/*烟台大学计算机学院学生
*All right reserved.
*文件名称:体验虚基类
*作者:杨飞
*完成日期:2014年5月2日
*版本号:v1.0
*对任务及求解方法的描述部分:体验虚基类
*我的程序:*/
#include <iostream>
#include <cstring>
using namespace std;
class Student
{
public:
Student(int,string ,float);
virtual void display();
protected:
int num;
string name;
float score;
};
Student::Student(int num1,string name1,float score1)
{
num=num1;
name=name1;
score=score1;
}
void Student::display()
{
cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
cout<<"score:"<<score<<endl;
}
class Graduate:public Student
{
public:
Graduate(int num1,string name1,float score1,float wage1):
Student(num1,name1,score1),wage(wage1){}
void display();
private:
float wage;
};
void Graduate::display()
{
cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
cout<<"score:"<<score<<endl;
cout<<"wage:"<<wage<<endl;
}
int main()
{
cout<<"学生信息"<<endl;
Student stu(1001,"huangren",89);
Graduate ren(1008,"acsjx",99,1200);
Student *pt=&stu;
pt->display();
cout<<"研究生信息:"<<endl;
pt=&ren;
pt->display();
return 0;
}
心得体会:呵呵!!!