#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
class person{//聲明基類
protected:
int age;
char sex;
string name;
public:
person(int a,char s,string nam){
age=a;
sex=s;
name=nam;
}
};
class teacher:virtual public person
{
protected:
string title;
public:
teacher(int a,char s,string nam,string t):person(a,s,nam){
title=t;
}
};
class student:virtual public person
{
protected:
float score;
public:
student(int a,char s,string nam,float sc):person(a,s,nam){
score=sc;
}
};
class graduate:public teacher,public student
{
protected:
float wdge;
public:
graduate(int a,char s,string nam,string t,float sc,float wd):person(a,s,nam),teacher(a,s,nam,t),student(a,s,nam,sc){
wdge=wd;
}
void show(){
cout<<name<<endl;
cout<<age<<endl;
cout<<sex<<endl;
cout<<title<<endl;
cout<<score<<endl;
cout<<wdge<<endl;
}
};
int main(){
graduate gr(22,f,"k;asdjf;daf","klsdaf",89.5,79.5);
gr.show();
return 0;
}
輸出結果:
k;asdjf;daf
22
f
klsdaf
89.5
79.5
Press any key to continue