菜鸟的博客

纵有疾风起,人生不言弃。

导航

2023.4.28

 1 //实验六任务5
 2 #include <iostream>
 3 #include <string>
 4 using namespace std;
 5 class Student
 6 {
 7 public:
 8     Student(int ID,string name);
 9     void setnameid()
10     {
11         cout<<"请输入姓名:"<<endl;
12         cin>>name;
13         cout<<"请输入学号:"<<endl;
14         cin>>ID;
15     }
16     void displaynameid()
17     {
18         cout<<"姓名:"<<name<<endl;
19         cout<<"学号:"<<ID<<endl;
20     }
21     virtual void setmajor() = 0;
22     virtual string getmajor() = 0;
23     virtual void setadvisor() = 0;
24     virtual string getadvisor() = 0;
25 protected:
26     string name;
27     int ID;
28 };
29 class Understud:public Student
30 {
31 public:
32     Understud(string name,int ID,string major);
33     void setmajor()
34     {
35         cout<<"请输入学号:"<<endl;
36         cin>>major;
37     }
38     string getmajor()
39     {
40         cout<<"专业:"<<major<<endl;
41         return major;
42     }
43 protected:
44     string major;
45 };
46 class Poststud:public Understud
47 {
48 public:
49     Poststud(string name = "***",int ID = -1,string major = "###",string advisor = "&&&");
50     void setadvisor()
51     {
52         cout<<"请输入导师姓名:"<<endl;
53         cin>>advisor;
54     }
55     string getadvisor()
56     {
57         cout<<"导师姓名:"<<advisor<<endl;
58         return advisor;
59     }
60 private:
61     string advisor;
62 };
63 int main()
64 {
65     Poststud p;
66     int num;
67     cout<<"请输入选项(0或1):";
68     cin>>num;
69     if(num == 0)
70     {
71         p.displaynameid();
72         p.getmajor();
73         p.getadvisor();
74     }
75     else if(num == 1)
76     {
77         p.setnameid();
78         p.setmajor();
79         p.setadvisor();
80         p.displaynameid();
81         p.getmajor();
82         p.getadvisor();
83     }
84     return 0;
85 }

 

posted on 2023-04-29 00:47  hhmzd233  阅读(15)  评论(0编辑  收藏  举报