[Submit][Status][Web Board]
Description
Student类含有私有数据成员:num,name,sex,公有成员函数: 输入函数get_value()和输出函数display()。采用公用继承方式实现类Student1,增加数据成员:age,addr,成员函数:get_value_1()和display_1()。在程序运行时输入num,name,sex,age,addr的值,调用输出函数输出以上5个数据的值。
Input
输入num,name,sex,age,addr的值
Output
输出num,name,sex,age,addr的值
Sample Input
1001 zhang m 21 shanghai
Sample Output
num: 1001name: zhangsex: mage: 21address: shanghai
#include <iostream> using namespace std; class Student { public: void get_value() { cin>>num>>name>>sex; } void display( ) { cout<<"num: "<<num<<endl; cout<<"name: "<<name<<endl; cout<<"sex: "<<sex<<endl; } private : int num; char name[10]; char sex; }; class Student1:public Student {public: void get_value_1() {//get_value(); cin>>age>>addr; } void display_1() {cout<<"age: "<<age<<endl; cout<<"address: "<<addr<<endl;} private: int age; char addr[30]; }; int main() { Student1 stud1; stud1.get_value(); stud1.get_value_1(); stud1.display(); stud1.display_1(); return 0; }