64,639
社区成员
发帖
与我相关
我的任务
分享
#include <iostream.h>
class Score {
float computer;
float english;
float mathematics;
public:
Score(float x1,float y1,float z1);
Score();
void print();
void modify(float x2,float y2,float z2);
};
Score::Score(float x1,float y1,float z1)
{
computer = x1;english = y1;mathematics = z1;
}
Score::Score()
{
computer = 0;english = 0;mathematics=0;
}
void Score::modify(float x2,float y2,float z2)
{
computer = x2 ;english = y2 ; mathematics = z2;
}
void Score::print()
{
cout<<"\nscore of computer:"<<computer;
cout<<"\nscore of english:"<<english;
cout<<"\nscore of mathematics:"<<mathematics;
}
#include <iostream.h>
#include <string.h>
#include "score.cpp"
class Student{
private:
int number;
char* name;
Score aScore; //Score 成员对象
public:
Student(int number1,char* name,float score1,float score2,float scroe3);
~Student();
//把MODIFY 也扩充为整个对象的修改
void modify(int number2,char* name2,float score21,float score22,float score23);
void print();
}
Student::Student(int number1,char* name1,float score1,float score2,float score3)
:aScore(score1,score2,score3)//对象成员aScore初始化
{
number = number1;
name = new char[strlen(name1)+1];
strcpy(name,name1);
}
Student::~Student(){delete name;}
void Student::modify(int number2,char* name2,float score21,float score22,float score23)
{
number = number2;
name = name2;
aScore.modify(score21,score22,score,23);//修改对象成员
}
void Student::print()
{
cout<<"\number:"<<number<<"\nname:"<<name;aScore.print();//输出对象成员ascore
}
int main()
{
int numberi;
char* namei = new char[15];
float score1,score2,score3;
cout<<"\nnumber:";
cin >> numberi;
cout<<"name:";
cin>>namei;
cout<<"score of computer:";
cin>>score1;
cout<<"score of english:";
cin>>score2;
cout<<"score of mathematics:";
cin>>score3;
Student aStudent(numberi,namei,score1+1,score2+1,score3+1);
aStudent.print();
aStudent.modify(numberi,namei,score1+1,score2+1,score3+1);
aStudent.print();
delete namei;
return 0;
}
class Student{
private:
int number;
char* name;
Score aScore; //Score 成员对象
public:
Student(int number1,char* name,float score1,float score2,float scroe3);
~Student();
//把MODIFY 也扩充为整个对象的修改
void modify(int number2,char* name2,float score21,float score22,float score23);
void print();
};//这里漏了分号
#include <iostream.h>
#include <string.h>
#include "score.cpp"
class Student{
private:
int number;
char* name;
Score aScore;
public:
Student(int number1,char* name,float score1,float score2,float scroe3);
~Student();
void modify(int number2,char* name2,float score21,float score22,float score23);
void print();
}//这里少了;