/*
*烟台大学计算机学院
*文件名称:main.cpp
*作 者:王者健
*完成日期:2016年6月15日
*版 本 号:codeblocks 16.01
*问题描述:
*输入描述:
*程序输出:
*/
#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
{
public:
Student(char* s,int g):Person(s)
{
grade=g;
}
void display1()
{
display();
cout<<"Grade: "<<grade<<endl;
}
private:
int grade;
};
int main()
{
Student s("春哥",19);
s.display1();
return 0;
}
简单的继承和派生
最新推荐文章于 2020-02-22 18:11:17 发布