- * 程序的版权和版本声明部分
- * Copyright (c) 2011, 烟台大学计算机学院学生
- * All rights reserved.
- * 文件名称:
- * 作者:李君凯
- * 完成日期: 2012年 5月 8日
- * 版本号:
- *对任务及求解方法的描述部分
<span style="font-size:16px;">#include<iostream> #include<string> using namespace std; class Student //(1)修改student类中各数据成员和成员函数的访问限定符,并观察发生的现象 { public: Student(int n,string nam,char s) ; void show(); ~Student( ){ } protected: int num; string name; char sex ; }; class Student1: public Student //(2)修改此处的继承方式,并观察发生的现象 { public: Student1(int n,string nam,char s,int a,string ad); void show1( ); ~Student1( ){ } private: int age; string addr; }; Student::Student(int n,string nam,char s) { num=n; name=nam; sex=s; } void Student::show() { cout<<"num: "<<num<<endl; cout<<"name: "<<name<<endl; cout<<"sex: "<<sex<<endl<<endl; } Student1::Student1(int n,string nam,char s,int a,string ad):Student(n,nam,s) { age=a; addr=ad; } void Student1::show1( ) { cout<<"num: "<<num<<endl; cout<<"name: "<<name<<endl; cout<<"sex: "<<sex<<endl; cout<<"age: "<<age<<endl; cout<<"address: "<<addr<<endl<<endl; } int main( ) { Student1 stud1(10010,"Wang-li",'f',19,"115 Beijing Road,Shanghai"); Student1 stud2(10011,"Zhang-fun",'m',21,"213 Shanghai Road,Beijing"); Student stud3(20010,"He-xin",'m'); stud1.show1( ); stud2.show( ); stud3.show( ); system("PAUSE"); return 0; } </span>
![](https://img-my.csdn.net/uploads/201205/08/1336479672_9998.jpg)