當前位置:編程學習大全網 - 源碼下載 - c++:封裝壹個CStudent類,用來描述學生的屬性和行為。具體要求如下。 1.學生有姓名,籍貫

c++:封裝壹個CStudent類,用來描述學生的屬性和行為。具體要求如下。 1.學生有姓名,籍貫

/*c++:封裝壹個CStudent類,用來描述學生的屬性和行為。具體要求如下。

1.學生有姓名,籍貫,學號,年齡,成績五個成員數據,編寫構造函數,,

拷貝構造函數,同時編寫Display(),成員函數顯示學生的信息。

2.編寫“+”運算符重載函數,使CStudent類的

兩個對象相加返回兩個對象總成績相加的和。

3.編寫主函數,定義兩個CStudent類對象,分別調用成員函數Display(),

顯示兩個對象的學生信息,同時顯示兩個對象相加的結果。

*/

#include?<iostream>

#include?<String>

using?namespace?std;

class?CStudent

{

private:

int?number;

string?name;

string?hometown;

int?age;

double?score;

public:

CStudent(int?n=1,string?nm="",string?hm="",int?ag=0,double?sc=0)

{

cout<<"structor......\n";

number=n;

name=nm;

hometown=hm;

age=ag;

score=sc;

}

CStudent(CStudent?&s)

{

cout<<"copy?constructor....\n";

number=s.number;

name=s.name;

hometown=s.hometown;

age=s.age;

score=s.score;

}

void?Display()

{

cout<<"number\tname\thometown\tage\tscore\n";

cout<<number<<"\t"<<name<<"\t"<<hometown<<"\t"<<age<<"\t"<<score<<endl;

}

double?operator+(CStudent?&s)

{

return?score+s.score;

}?

};

int?main()

{

CStudent?s1(1,"張三","北京",23,87.5);

CStudent?s2(2,"李四","上海",22,91);

s1.Display();

s2.Display();

cout<<"成績和為"<<s1+s2<<endl;

return?0;

}

  • 上一篇:ITSM績效考核之惑
  • 下一篇:績效考核
  • copyright 2024編程學習大全網