第4题
来源:互联网 发布:民国图书数据库 编辑:程序博客网 时间:2024/06/14 13:07
#include <iostream>
using namespace std;
class Student//声明基类
{public: //基类公用成员
void get_value();
void display( );
protected : //基类保护成员
int num;
char name[10];
char sex;
};
void Student::get_value()
{cin>>num>>name>>sex;}
void Student::display( )
{cout<<"num: "<<num<<endl;
cout<<"name: "<<name<<endl;
cout<<"sex: "<<sex<<endl;
}
class Student1: public Student //声明一个公用派生类
{public:
void get_value_1();
void display1( );
private:
int age;
char addr[30];
};
void Student1::get_value_1()
{get_value();
cin>>age>>addr;
}
void Student1::display1( )
{cout<<"num: "<<num<<endl; //引用基类的保护成员,合法
cout<<"name: "<<name<<endl; //引用基类的保护成员,合法
cout<<"sex: "<<sex<<endl; //引用基类的保护成员,合法
cout<<"age: "<<age<<endl; //引用派生类的私有成员,合法
cout<<"address: "<<addr<<endl; //引用派生类的私有成员,合法
}
int main( )
{Student1 stud1; //stud1是派生类student1类的对象
stud1.get_value_1(); //调用派生类对象stud1的公用成员函数get_value_1
stud1.display1( ); //调用派生类对象stud1的公用成员函数display1
return 0;
}
- 第4章 第4题
- 第2章第4题
- 第2章 第4题
- 第3章 第4题
- 第4章 第1题
- 第4章 第2题
- 第4章 第3题
- 第4章 第5题
- 第4章 第6题
- 第4章 第7题
- 第5章第4题
- 第7章第4题
- 第7章 第4题
- 第10章第4题
- p27第4题
- 第一章第4题
- 第4题作业
- P51 第4题
- C++基数排序(清楚明了完美详细的实现)
- 3 微信开放平台---管理中心
- 代码中的特殊注释
- [翻译]Swift编程语言——继承
- RocksDB写入数据过程DBImpl::Write()源代码分析
- 第4题
- cocos2d-x3.3获取时间
- oracle max()函数和min()函数
- 构建Deployment系统
- [翻译]Swift编程语言——初始化
- 简单的正则
- [翻译]Swift编程语言——析构
- 资源查找收集整理
- 解决WinForm应用中引用“mshtml”出现“强名称签名对程序集 Microsoft.mshtml.dll 无效”