问题及代码:
在下面的程序横线处填空,以使程序内容完整,并使程序的输出为:
Name:春哥
Grade:19
/*
* Copyright (c) 2015, 烟台大学计算机学院
* All rights reserved.
*文件名称:test.cpp
* 作 者:曾建强
* 完成日期:2015年5月20日
* 版 本 号:v1.0
*
* 问题描述:如上述
* 输入描述:
* 程序输出:
*/
#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;
}
运行结果: