根据所给的基类Student和Teacher,定义Graduate类
类定义:
#include <iostream>
#include <string>
using namespace std;
class Teacher
{public:
Teacher(string nam,int a,string t)
{name=nam;
age=a;
title=t;}
void display()
{cout<<"name:"<<name<<endl;
cout<<"age"<<age<<endl;
cout<<"title:"<<title<<endl;
}
protected:
string name;
int age;
string title;
};
class Student
{public:
Student(string nam,char s,float sco)
{name1=nam;
sex=s;
score=sco;}
void display1()
{cout<<"name:"<<name1<<endl;
cout<<"sex:"<<sex<<endl;
cout<<"score:"<<score<<endl;
}
protected:
string name1;
char sex;
float score;
};
/* 请在这里填写答案 */
裁判测试程序样例:
int main( )
{Graduate grad1("Wang-li",24,'f',"assistant",89.5,1234.5);
grad1.show( );
return 0;
}
输出样例:
name:Wang-li
age:24
sex:f
score:89.5
title:assistant
wages:1234.5
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
class Graduate:public Teacher,public Student{
float wages;
public:
Graduate (string nam,int a,char s,string t,float sco,float w):
Teacher(nam,a,t),Student(nam,s,sco),wages(w){}
void show(){
cout <<"name:"<<name<<endl;
cout<<"age:"<<age<<endl;
cout<<"sex:"<<sex<<endl;
cout<<"score:"<<score<<endl;
cout<<"title:"<<title<<endl;
cout<<"wages:"<<wages<<endl;
}
};
初始化列表时要注意顺序(错误的)
注意输出顺序是
所以就应该是:(正确的)