1 //实验六任务2 2 #include <iostream> 3 #include <string> 4 using namespace std; 5 class People 6 { 7 public: 8 People(){} 9 ~People(){} 10 void setValue(int m,string str) 11 { 12 age = m; 13 name = str; 14 } 15 virtual void display() = 0; 16 protected: 17 int age; 18 string name; 19 }; 20 class Student :public People 21 { 22 public: 23 Student(){} 24 ~Student(){} 25 void setID(int m) 26 { 27 studentID = m; 28 } 29 void display() 30 { 31 cout<<"姓名:"<<name<<endl; 32 cout<<"年龄:"<<age<<endl; 33 cout<<"学号:"<<studentID<<endl; 34 } 35 private: 36 int studentID; 37 }; 38 class Teacher : public People 39 { 40 public: 41 Teacher(){} 42 ~Teacher(){} 43 void setID(int m) 44 { 45 teacherID = m; 46 } 47 void display() 48 { 49 cout<<"姓名:"<<name<<endl; 50 cout<<"年龄:"<<age<<endl; 51 cout<<"工号:"<<teacherID<<endl; 52 } 53 private: 54 int teacherID; 55 }; 56 int main() 57 { 58 Student s; 59 Teacher t; 60 s.setValue(18,"张三"); 61 t.setValue(28,"李四"); 62 s.setID(123); 63 t.setID(654); 64 s.display(); 65 t.display(); 66 return 0; 67 }
标签:27,People,int,void,Student,2023.4,public From: https://www.cnblogs.com/muzhaodi/p/17360194.html