《C++面向对象程序设计答案》-第五章--谭浩强-.doc

上传人:灯火****19 文档编号:136792391 上传时间:2020-07-02 格式:DOC 页数:13 大小:45.50KB
返回 下载 相关 举报
《C++面向对象程序设计答案》-第五章--谭浩强-.doc_第1页
第1页 / 共13页
《C++面向对象程序设计答案》-第五章--谭浩强-.doc_第2页
第2页 / 共13页
《C++面向对象程序设计答案》-第五章--谭浩强-.doc_第3页
第3页 / 共13页
《C++面向对象程序设计答案》-第五章--谭浩强-.doc_第4页
第4页 / 共13页
《C++面向对象程序设计答案》-第五章--谭浩强-.doc_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《《C++面向对象程序设计答案》-第五章--谭浩强-.doc》由会员分享,可在线阅读,更多相关《《C++面向对象程序设计答案》-第五章--谭浩强-.doc(13页珍藏版)》请在金锄头文库上搜索。

1、1:#include using namespace std;class Studentpublic: void get_value() cinnumnamesex; void display( ) coutnum: numendl; coutname: nameendl; coutsex: sexageaddr; void display_1() coutage: ageendl; /引用派生类的私有成员,正确。 coutaddress: addrendl; /引用派生类的私有成员,正确。 private: int age; char addr30; ; int main() Student

2、1 stud1; stud1.get_value_1(); stud1.display(); stud1.display_1(); return 0;2:#include using namespace std;class Studentpublic: void get_value() cinnumnamesex; void display( ) coutnum: numendl; coutname: nameendl; coutsex: sexageaddr; void display_1() display(); coutage: ageendl; /引用派生类的私有成员,正确。 cout

3、address: addrendl; /引用派生类的私有成员,正确。 private: int age; char addr30; ; int main() Student1 stud1; stud1.get_value_1(); stud1.display_1(); return 0;3:#include using namespace std;class Student /声明基类public: /基类公用成员 void get_value(); void display( ); protected : /基类保护成员 int num; char name10; char sex;void

4、 Student:get_value() cinnumnamesex;void Student:display( ) coutnum: numendl; coutname: nameendl; coutsex: sexageaddr; void Student1:display1( ) coutnum: numendl; /引用基类的保护成员 coutname: nameendl; /引用基类的保护成员 coutsex: sexendl; /引用基类的保护成员 coutage: ageendl; /引用派生类的私有成员 coutaddress: addrendl; /引用派生类的私有成员 in

5、t main( ) Student1 stud1; /stud1是派生类student1类的对象 stud1.get_value_1(); /调用派生类对象stud1的公用成员函数 stud1.display1( ); /调用派生类对象stud1的公用成员函数 return 0; 4: 解法一#include using namespace std;class Student /声明基类public: /基类公用成员 void get_value(); void display( ); protected : /基类保护成员 int num; char name10; char sex;voi

6、d Student:get_value() cinnumnamesex;void Student:display( ) coutnum: numendl; coutname: nameendl; coutsex: sexageaddr; void Student1:display1( ) coutnum: numendl; /引用基类的保护成员,合法 coutname: nameendl; /引用基类的保护成员,合法 coutsex: sexendl; /引用基类的保护成员,合法 coutage: ageendl; /引用派生类的私有成员,合法 coutaddress: addrendl; /

7、引用派生类的私有成员,合法 int main( ) Student1 stud1; /stud1是派生类student1类的对象 stud1.get_value_1(); /调用派生类对象stud1的公用成员函数get_value_1 stud1.display1( ); /调用派生类对象stud1的公用成员函数display1 return 0; 解法二#include using namespace std;class Student /声明基类public: /基类公用成员 void get_value(); void display( ); protected : /基类保护成员 in

8、t num; char name10; char sex;void Student:get_value() cinnumnamesex;void Student:display( ) coutnum: numendl; coutname:nameendl; coutsex:sexageaddr; void Student1:display1( ) coutage:ageendl; coutaddress:addrendl; int main( ) Student1 stud1; /stud1是派生类student1类的对象 stud1.get_value(); stud1.get_value_1(); stud1.display( ); stud1.display1(); /合法。display1是派生类中的公用成员函数 retur

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号