c/c++语言开发共享派生类Student的构造函数和析构函数 代码参考

1 #include <iostream> 2 #include <cstring> 3 4 using namespace std; 5 6 class Person 7 { 8 private: 9 char Name[10]; 10 int Age; 11 public: 12 Person( …

 1 #include <iostream>  2 #include <cstring>  3   4 using namespace std;  5   6 class person  7 {  8     private:  9         char name[10]; 10         int age; 11     public: 12         person(char *name, int age) 13         { 14             strcpy(name,name); 15             age=age; 16             cout<<"constructor of person "<<name<<endl; 17         } 18         ~person(){cout<<"deconstructor of person "<<name<<endl;} 19 }; 20  21 class student:public person 22 { 23     private: 24         char classname[10]; 25         person monitor; 26     public: 27         student(char *name, int age, char *classname, char *name1, int age1); 28         ~student(); 29 }; 30  31 student::student(char *name, int age, char *classname, char *name1, int age1):person(name,age),monitor(name1,age1) 32 { 33     strcpy(classname,classname); 34     cout<<"constructor of student"<<endl; 35 } 36  37 student::~student() 38 { 39     cout<<"deconstructor of student"<<endl; 40 } 41  42 int main() 43 { 44     char name1[10],name2[10],classname[20]; 45     int age1,age2; 46     cin>>name1>>age1>>classname>>name2>>age2; 47     student one(name1,age1,classname,name2,age2); 48     return 0; 49 }

 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/c-cdevelopment/599736.html

(0)
上一篇 2021年5月9日
下一篇 2021年5月9日

精彩推荐