您的位置:首页 > 其它

第3题

2015-06-08 22:33 337 查看
#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: protected 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.get_value_1();
stud1.display1( );
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: