- #include "iostream"
- #include "string"
- using std::cin;
- using std::cout;
- using std::endl;
- using std::string;
- class Student
- {
- protected:
- int num;
- string name;
- char sex;
- public:
- void prit();
- void display();
- };
- void Student::prit()
- {
- cin >> num >> name >> sex;
- }
- void Student::display()
- {
- cout << num << " " << name << " " << sex;
- }
- class Studet1 : public Student
- {
- protected:
- int age;
- string addr;
- public:
- void prit();
- void display();
- };
- void Studet1::prit()
- {
- Student::prit();
- cin >> age >> addr;
- }
- void Studet1::display()
- {
- Student::display();
- cout << " ";
- cout << age << " " << addr;
- }
- int main(int argc, char const *argv[])
- {
- Studet1 A;
- A.prit();
- A.display();
- cout << endl;
- return 0;
- }
第二题
- #include "iostream"
- #include "string"
- using std::cin;
- using std::cout;
- using std::endl;
- using std::string;
- class Student
- {
- protected:
- int num;
- string name;
- char sex;
- public:
- void prit();
- void display();
- };
- void Student::prit()
- {
- cin >> num >> name >> sex;
- }
- void Student::display()
- {
- cout << num << " " << name << " " << sex;
- }
- class Studet1 : private Student
- {
- protected:
- int age;
- string addr;
- public:
- void prit();
- void display();
- };
- void Studet1::prit()
- {
- cin >> num >> name >> sex;
- cin >> age >> addr;
- }
- void Studet1::display()
- {
- cout << num << " " << name << " " << sex;
- cout << " ";
- cout << age << " " << addr;
- }
- int main(int argc, char const *argv[])
- {
- Studet1 A;
- A.prit();
- A.display();
- cout << endl;
- return 0;
- }
第三题
- #include "iostream"
- #include "string"
- using std::cin;
- using std::cout;
- using std::endl;
- using std::string;
- class Student
- {
- protected:
- int num;
- string name;
- char sex;
- public:
- void prit();
- void display();
- };
- void Student::prit()
- {
- cin >> num >> name >> sex;
- }
- void Student::display()
- {
- cout << num << " " << name << " " << sex;
- }
- class Studet1 : protected Student
- {
- protected:
- int age;
- string addr;
- public:
- void prit();
- void display();
- };
- void Studet1::prit()
- {
- cin >> num >> name >> sex;
- cin >> age >> addr;
- }
- void Studet1::display()
- {
- cout << num << " " << name << " " << sex;
- cout << " ";
- cout << age << " " << addr;
- }
- int main(int argc, char const *argv[])
- {
- Studet1 A;
- A.prit();
- A.display();
- cout << endl;
- return 0;
- }
第9题
- #include "iostream"
- #include "string"
- using std::cin;
- using std::cout;
- using std::endl;
- using std::string;
- class Teacher
- {
- protected:
- string name;
- int age;
- char sex;
- string addr;
- int tel;
- string title;
- public:
- Teacher(string, int, char, string, int, string);
- void display();
- };
- Teacher::Teacher(string na, int ag, char se, string ad, int te, string ti)
- :name(na), age(ag), sex(se), addr(ad), tel(te), title(ti)
- {}
- void Teacher::display()
- {
- cout << name << " " << age << " " << sex << " " << addr << " " << tel << " " << title;
- }
- class Cadre
- {
- protected:
- string name;
- int age;
- char sex;
- string addr;
- int tel;
- public:
- string post;
- Cadre(string na, int ag, char se, string ad, int te,string po);
- };
- Cadre::Cadre(string na, int ag, char se, string ad, int te, string po)
- :name(na), age(ag), sex(se), addr(ad), tel(te), post(po)
- {}
- class Teacher_Cadre : public Teacher, public Cadre
- {
- protected:
- public:
- int wages;
- Teacher_Cadre(string na, int ag, char se, string ad, int te, string ti, string po, int wa);
- };
- Teacher_Cadre::Teacher_Cadre(string na, int ag, char se, string ad, int te, string ti, string po, int wa)
- :Teacher(na, ag, se, ad, te, ti), Cadre(na, ag, se, ad, te, po), wages(wa)
- {}
- int main(int argc, char const *argv[])
- {
- Teacher_Cadre T("nihao", 18, 'M', "江西财经大学", 12345, "zhicheng", "zhiwu", 123456);
- T.display();
- cout << " ";
- cout << T.post << " " << T.wages << endl;
- return 0;
- }
第10题
- #include "iostream"
- #include "string"
- using std::cin;
- using std::cout;
- using std::endl;
- using std::string;
- class Teacher
- {
- protected:
- int num;
- string name;
- char sex;
- public:
- Teacher(int, string, char);
- void display();
- };
- Teacher::Teacher(int n, string na, char s)
- :num(n), name(na), sex(s)
- {}
- void Teacher::display()
- {
- cout << num << " " << name << " " << sex;
- }
- class BirthDate
- {
- protected:
- int year;
- int month;
- int day;
- public:
- BirthDate(int, int, int);
- void change();
- void display();
- };
- BirthDate::BirthDate(int y, int m, int d)
- :year(y), month(m), day(d)
- {}
- void BirthDate::display()
- {
- cout << year << " " << month << " " << day;
- }
- void BirthDate::change()
- {
- cin >> year >> month >> day;
- }
- class Professor : public Teacher
- {
- protected:
- BirthDate birthday;
- public:
- void change();
- Professor(int, string, char,int, int, int);
- void display();
- };
- void Professor::change()
- {
- birthday.change();
- }
- Professor::Professor(int n, string na, char s, int y, int m, int d)
- :Teacher(n, na, s), birthday(y, m, d)
- {
- }
- void Professor::display()
- {
- Teacher::display();
- cout << " ";
- birthday.display();
- cout << endl;
- }
- int main(int argc, char const *argv[])
- {
- Professor profl(123, "nihao", 'M', 1995, 11, 12);
- profl.display();
- profl.change();
- profl.display();
- return 0;
- }