/*copyright(c)2016.烟台大学计算机学院
* All rights reserved,
* 文件名称:text.Cpp
* 作者:刘涛
* 完成日期:2016年5月9日
* 版本号:vc++6.0
*问题描述:输出春哥
07. */
#include <iostream>
#include <cstring>
using namespace std;
class Person{
public:
Person(char* s){
strcpy(name,s);
}
void display( ){
cout<<"Name: "<<name<<endl;
}
private:
char name [20];
};
class Student: public Person//(1)
{
public:
Student(char* s, int g):Person(s) // (2)
{grade=g;}
void display1( ) {
display(); // (3)
cout<<"Grade: "<<grade<<endl;
}
private:
int grade;
};
int main( )
{
Student s("春哥",19);
s.display1(); // (4)
return 0;
}
运行结果:
<img src="https://img-blog.csdn.net/20160510150027379?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />