level 11
第一片心意🍗
楼主
#include <IOSTREAM>
#include <STRING>
using namespace std;
class Birthday
{public:
Birthday(int y, int m, int d):year(y), month(m), day(d){}
void display()
{
cout <<year <<"/" <<month <<"/" <<day <<endl;
}
private:
int year;
int month;
int day;
};
class Teacher
{public:
Teacher(string nam, int a, string t)
{ name = nam;
age = a;
title = t;
}
void display()
{ cout <<"name:" <<name <<endl;
cout <<"age:" <<age <<endl;
cout <<"title:" <<title <<endl;
}
protected:
string name;
int age;
string title;
};
class Student
{public:
Student(string nam, char s, float sco)
{ name1 = nam;
sex = s;
score = sco;
}
void display1()
{ cout <<"name:" <<name1 <<endl;
cout <<"sex:" <<sex <<endl;
cout <<"score:" <<score <<endl;
}
protected:
string name1;
char sex;
float score;
};
class Graduate:public Teacher, public Student
{public:
Graduate(string nam, int a, char s, string t, float sco, float w, Birthday b):
Teacher(nam, a, t), Student(nam, s, sco), wage(w), bir(b){}
void show()
{ cout <<"name:" <<name <<endl;
cout <<"age:" <<age <<endl;
cout <<"sex:" <<sex <<endl;
cout <<"score:" <<score <<endl;
cout <<"title:" <<title <<endl;
cout <<"wage:" <<wage <<endl;
bir.display();
}
private:
float wage;
Birthday bir;
};
int main()
{
Graduate grad1("Wang-li", 24, 'f', "assistant", 89.5, 1234.5,
(1989, 12, 12));
grad1.show();
return 0;
}
在Graduate类中有类Birthday成员,在定义了Graduate类后怎么对其成员bir赋值?
2013年10月25日 13点10分
1
#include <STRING>
using namespace std;
class Birthday
{public:
Birthday(int y, int m, int d):year(y), month(m), day(d){}
void display()
{
cout <<year <<"/" <<month <<"/" <<day <<endl;
}
private:
int year;
int month;
int day;
};
class Teacher
{public:
Teacher(string nam, int a, string t)
{ name = nam;
age = a;
title = t;
}
void display()
{ cout <<"name:" <<name <<endl;
cout <<"age:" <<age <<endl;
cout <<"title:" <<title <<endl;
}
protected:
string name;
int age;
string title;
};
class Student
{public:
Student(string nam, char s, float sco)
{ name1 = nam;
sex = s;
score = sco;
}
void display1()
{ cout <<"name:" <<name1 <<endl;
cout <<"sex:" <<sex <<endl;
cout <<"score:" <<score <<endl;
}
protected:
string name1;
char sex;
float score;
};
class Graduate:public Teacher, public Student
{public:
Graduate(string nam, int a, char s, string t, float sco, float w, Birthday b):
Teacher(nam, a, t), Student(nam, s, sco), wage(w), bir(b){}
void show()
{ cout <<"name:" <<name <<endl;
cout <<"age:" <<age <<endl;
cout <<"sex:" <<sex <<endl;
cout <<"score:" <<score <<endl;
cout <<"title:" <<title <<endl;
cout <<"wage:" <<wage <<endl;
bir.display();
}
private:
float wage;
Birthday bir;
};
int main()
{
Graduate grad1("Wang-li", 24, 'f', "assistant", 89.5, 1234.5,
(1989, 12, 12));
grad1.show();
return 0;
}
在Graduate类中有类Birthday成员,在定义了Graduate类后怎么对其成员bir赋值?