鱼C论坛

 找回密码
 立即注册
查看: 2373|回复: 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;
}
       
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

建议好好学习类的基础

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

using namespace std;

class Cclass
{
public:
        Cclass(string, int, int, int, int);

        void show();

private:
        string name;
        int id;
        int CC;
        int eng;
        int math;
        
};

Cclass::Cclass(string n, int Id, int ccount, int english, int m)
{
        name = n;
        id = Id;
        CC = ccount;
        eng = english;
        math = m;
}
void Cclass::show()
{
        cout<<name<<" "<< id<<" "<<CC<<" "<<eng<<" "<<math<<endl;
}

int main()
{
        Cclass student("小红",123456,12,23,45);
        student.show();
        getchar();
        return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-10-19 16:57:21 From FishC Mobile | 显示全部楼层
谢谢大佬,最近才学,第一次作业就是这个!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-30 21:26

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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