ex216.cpp
资源名称:VC6.0.rar [点击查看]
上传用户:qdhmjx
上传日期:2022-07-11
资源大小:2226k
文件大小:1k
源码类别:
书籍源码
开发平台:
Visual C++
- #include <iostream.h>
- #include <string.h>
- class student
- {
- protected:
- int num;
- char name[10];
- char sex;
- public:
- student(int n,char*na,char s)
- { //基类增加了带参数的构造函数
- num=n;
- strcpy(name,na);
- sex=s;
- }
- void display()
- {cout<<num<<endl<<name<<endl<<sex<<endl;}
- };
- class stud:public student
- {
- private:
- int age;
- public:
- stud(int n,char*na,char s,int a):student(n,na,s)
- {
- age=a;
- }
- void display()
- {cout<<num<<endl<<name<<endl<<sex<<endl<<age<<endl;}
- };
- stud a(1001,"Teddy",'M',23);
- void main()
- {
- a.display();
- }