1 #include <iostream>
 2 #include <string.h>
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 using namespace std;
 5 class Student
 6 {
 7     public:
 8         void display();
 9     protected:
10         int num;
11         string name;
12         char sex;
13 };
14 
15 void Student::display()
16 {
17     cout<<"num:"<<num<<endl;
18     cout<<"name:"<<name<<endl;
19     cout<<"sex:"<<sex<<endl;
20 }
21 
22 class Student1:protected Student
23 {
24     public:
25         void display1();
26     private:
27         int age;
28         string addr;
29 };
30 
31 void Student1::display1()
32 {
33     cout<<"num:"<<num<<endl;
34     cout<<"name:"<<name<<endl;
35     cout<<"sex:"<<sex<<endl;
36     cout<<"age:"<<age<<endl;
37     cout<<"address:"<<addr<<endl;
38 }
39 
40 int main(int argc, char** argv) {
41     Student1 stud1;
42     stud1.display1();
43     return 0;
44 }

 

相关文章:

  • 2022-01-19
  • 2022-12-23
  • 2021-09-02
  • 2021-09-16
  • 2022-01-29
  • 2021-12-19
  • 2022-02-21
  • 2021-06-01
猜你喜欢
  • 2021-11-16
  • 2021-10-13
  • 2021-11-08
  • 2022-12-23
  • 2021-07-23
相关资源
相似解决方案