注册 登录
编程论坛 C++教室

求教一下c++关于对象数组的问题

wang13131 发布于 2015-11-28 17:39, 621 次点击
在主函数中,先定义一个学生类对象数组,再通过for循环给对象数组赋上实际值,最后输出对象数组个元素的值   

class Score

{

protected:

    double Chinese,English,Mathematics;
  public:
  Score():Chinese(0),English(0),Mathematics(0){}
 
     Score(int Chinese, int English, int  Mathematics):Chinese(Chinese),English(English),Mathematics(Mathematics){}
    double sum();         //计算三门课总成绩

     void print();        //输出三门课成绩和总成绩

     void modify(int Chinese, int English, int Mathematics);      //修改三门课成绩
};
 
class Student

{

protected:

     string Num, Name;

     Score MyScore;//学生类中包含Score类的对象,体现了组合,让学生重点掌握

public:

     Student():Num(""),Name(""),MyScore(){}

     Student(string num, string name, Score  score):Num(num),Name(name),MyScore(score){}

     double sum();         //计算三门课总成绩

     void print();

     void modify(string num, string name, Score score);

};
 
  怎么从键盘上输入学号和成绩呢
1 回复
#2
yangfrancis2015-11-29 13:34
Student stu1;
double number;
string n;
cin>>number;
cin>>n;
Score s;
double cn,en,ma;
cin>>cn>>en>>ma;
s.modify(cn,en,ma);
stu1.modify(number,n,s);
1