#include <iostream>
#include <string>
using namespace std;
class Data
{
public:
Data();
Data(int ye, int mon, int da);
Data(Data &da);
void inf();
private:
int year;
int month;
int day;
};
class Student {
public:
Student(int num, string na, int ma, int en, int cs, Data tp);
Student(Student &stu);
~Student();
int sum();
int ave();
void show();
private:
Data birthday;
int number;
string name;
int math;
int eng;
int com;
};
Data::Data()
{
year = 1998;
month = 8;
day = 3;
}
Data::Data(int ye = 0, int mon = 0, int da = 0)
{
year = ye;
month = mon;
day = da;
}
Data::Data(Data &da)
{
cout << endl << "Warnning:This Copy constructors.!!!" << endl;
year = da.year;
month = da.month;
day = da.day;
}
void Data::inf()
{
cout << "Birthday:" << year << "/" << month << "/" << day << endl;
}
Student::Student(int num, string na, int ma, int en, int cs, Data tp) :birthday(tp) {
number = num;
name = na;
math = ma;
eng = en;
com = cs;
}
Student::~Student()
{
}
Student::Student(Student &stu) :birthday(stu.birthday) {
cout << endl << "Warnning:This Copy constructors.!!!" << endl;
number = stu.number;
name = stu.name;
math = stu.math;
eng = stu.eng;
com = stu.com;
}
int Student::sum() {
return math + eng + com;
}
int Student::ave() {
return (math + eng + com) / 3;
}
void Student::show() {
cout << "Number:" << number << endl;
cout << "Name:" << name << endl;
birthday.inf();
cout << "Math score:" << math << endl;
cout << "English score:" << eng << endl;
cout << "Computer score:" << com << endl;
cout << "Sum score:" << sum() << endl;
cout << "Average score:" << ave() << endl;
}
int main() {
Data tmp(2012, 12, 02);
Student noob(001, "!#%$#^$%^", 90, 89, 88, tmp);
noob.show();
Student newbie(noob);
newbie.show();
return 0;
}
- 测试结果