第三题

来源:互联网 发布:java递归算法40例 编辑:程序博客网 时间:2024/05/25 08:14
#include using namespace std;class Student {public: void get_value(); void display( ); protected : int num; char name[10]; char sex;};void Student::get_value() {cout<<"num:";cin>>num;cout<<"name:";cin>>name;cout<<"sex:";cin>>sex;}void Student::display( ) {cout<<"num: "<<num<<endl; cout<<"name: "<<name<<endl; cout<<"sex: "<<sex<<endl; }class Student1: protected Student {public: void get_value_1(); void display1( );private: int age; char addr[30];};void Student1::get_value_1() {get_value(); cout<<"age:";cin>>age; cout<<"addr:";cin>>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.get_value_1(); stud1.display1( ); return 0; }
0 0
原创粉丝点击