鱼C论坛

 找回密码
 立即注册
查看: 2729|回复: 2

新手求助

[复制链接]
发表于 2017-10-18 23:07:56 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
定义一个描述学生基本信息的类,数据类型包括姓名,学号,英语,语文,数学成绩,成员函数包括输出数据,姓名,学号,三门课成绩,要用构造函数。不知道哪儿错了,求大神指教。
#include<iostream.h>
class Cclass
{
        public:
        char name[20];
        int id;
        int CC;
        int eng;
        int math;
        int  cr str[20])
        {
                str[20]=name[20];
                cout<<str[20]<<" "<< id<<" "<<CC<<" "<<eng<<" "<<math<<endl;
        }
};
int main()
{
        Cclass student[1]={"小红",123456,12,23,45};
         print("小红");
         return 0;
}
       
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2017-10-19 09:13:25 | 显示全部楼层
你需要一个构造函数 对成员进行初始化
而且里面的打印函数写的也不对
main函数中的对象定义也有问题

建议好好学习类的基础

写个简单的上述可行版本如下:
  1. #include <iostream>
  2. #include <string>

  3. using namespace std;

  4. class Cclass
  5. {
  6. public:
  7.         Cclass(string, int, int, int, int);

  8.         void show();

  9. private:
  10.         string name;
  11.         int id;
  12.         int CC;
  13.         int eng;
  14.         int math;
  15.        
  16. };

  17. Cclass::Cclass(string n, int Id, int ccount, int english, int m)
  18. {
  19.         name = n;
  20.         id = Id;
  21.         CC = ccount;
  22.         eng = english;
  23.         math = m;
  24. }
  25. void Cclass::show()
  26. {
  27.         cout<<name<<" "<< id<<" "<<CC<<" "<<eng<<" "<<math<<endl;
  28. }

  29. int main()
  30. {
  31.         Cclass student("小红",123456,12,23,45);
  32.         student.show();
  33.         getchar();
  34.         return 0;
  35. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-10-19 16:57:21 From FishC Mobile | 显示全部楼层
谢谢大佬,最近才学,第一次作业就是这个!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-19 01:47

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表