1 #include<iostream>
2 #include<string>
3 using namespace std;
4 class people{
5 protected:
6 int age;string name;
7 public:
8 people(){};
9 people(int a,string b)
10 {
11 age=a;
12 name=b;
13 }
14 ~people(){};
15 void setValue(int m,string str)
16 {
17 age=m;
18 name=str;
19 }
20 void display()
21 {
22 cout<<"age:"<<age<<endl<<"name:"<<name<<endl;
23 }
24
25
26 };
27 class student:public people{
28 private:int ID;
29 public:
30 student(){};
31 student(int a,string b,int c):people(a,b),ID(c){}
32 ~student(){};
33 void setID(int m)
34 {
35 ID=m;
36 }
37 void displayID()
38 {
39 cout<<"ID:"<<ID<<endl;
40 }
41 };
42 int main()
43 {
44 student s(18,"jia",1111);
45 s.display();
46 s.displayID();
47 int a,c;
48 string b;
49 cout<<"请依次输入年龄 姓名 学号:";
50 cin>>a>>b>>c;
51 s.setValue(a,b);
52 s.setID(c);
53 s.display();
54 s.displayID();
55 }
1 #include<iostream>
2 #include<string>
3 using namespace std;
4 class Student
5 {
6 private:
7 string name;
8 int banji;
9 int xuehao;
10 public:
11 Student(string a, int b, int c)
12 {
13 name = a;
14 banji = b;
15 xuehao = c;
16 }
17 void sdiaplay()
18 {
19 cout << "name:" << name << endl << "banji" << banji << endl << "xuehao" << xuehao << endl;
20 }
21 void sshow()
22 {
23 cout << "shangke....." << endl;
24 }
25 };
26 class Teacher
27 {
28 private:
29 int gonghao;
30 int gongzi;
31 public:
32 Teacher(int a, int b)
33 {
34 gonghao = a;
35 gongzi = b;
36 }
37 void tdiaplay()
38 {
39 cout << "gonghao:" << gonghao << endl << "gongzi" << gongzi << endl;
40 }
41 void tshow()
42 {
43 cout << "shouke....." << endl;
44 }
45 };
46 class Zhujiao :public Student, public Teacher
47 {
48 public:
49 Zhujiao(string a, int b, int c, int d, int e) :Student(a, b, c), Teacher(d, e) {}
50 void zdisplay()
51 {
52 Student::sdiaplay();
53 Teacher::tdiaplay();
54 Student::sshow();
55 Teacher::tshow();
56 }
57 };
58 int main()
59 {
60 Zhujiao a("1111", 2, 3, 4, 5);
61 a.zdisplay();
62 }