#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
class student{
private:
int num;
int age;
float score;
public:
student(int ,int ,float);
void display();
};
//定義構造函數
student::student(int n,int a,float sc):num(n),age(a),score(sc){}
void student::display(){//定義成員函數
cout<<num<<endl;
cout<<age<<endl;
cout<<score<<endl;
}
class graduate:public student{
private:
float pay;
public:
graduate(int,int,float,float);
void display();
};
graduate::graduate(int n,int a,float sc,float p):student(n,a,sc),pay(p){}
void graduate::display(){
student::display();
cout<<pay<<endl;
}
int main(){
student st(12222,22,97.4);
graduate gr(353543,26,88.2,8000);
student *pt=&st;
pt->display();
pt=&gr;
pt->display();
return 0;
}
輸出結果:
12222
22
97.4
353543
26
88.2
Press any key to continue