#include <iostream>#include <string>using namespace std;class Person { public: Person(char *nam,char s,int a) {strcpy(name,nam);sex=s;age=a;} protected: char name[20]; char sex; int age;}; __________________ { public: Teacher(char *nam,char s,int a,char *t):Person(nam,s,a) {strcpy(title,t); } protected: char title[10]; };class Student:__________________ { public: Student(char *nam,char s,int a,float sco): Person(nam,s,a),score(sco){} protected: float score; };class Graduate:public Teacher,public Student { public: Graduate(char *nam,char s,int a,char *t,float sco,float w): Person(nam,s,a),Teacher(nam,s,a,t),Student(nam,s,a,sco),wage(w){} __________________ { cout<<"name:"<<name<<endl; cout<<"age:"<<age<<endl; cout<<"sex:"<<sex<<endl; cout<<"score:"<<score<<endl; cout<<"title:"<<title<<endl; cout<<"wages:"<<wage<<endl; } private: float wage; };int main( ){ char name[20],title[10],sex;int age;float score,wage; while(cin>>name>>sex>>age>>title>>score>>wage) { Graduate grad1(name,sex,age,title,score,wage); grad1.show( ); } return 0;}输入输入有多组测试数据,每行为一组测试数据,且用空格隔开个数据。输出根据程序代码输出相应的信息。样例输入Wangli f 24 assistant 89.5 1234.5样例输出name:Wangliage:24sex:fscore:89.5title:assistantwages:1234.5
2 回答
慕课朵颐3509194
TA贡献3条经验 获得超0个赞
第一个空声明Teacher类,并声明其公有继承于Person类: class Teacher:public Person
第一个空声明Student类公有继承于Person类: public Person
第三个空声明Graduate类的成员函数show: void show()
说明一下:前两个空也可以声明为保护继承
- 2 回答
- 0 关注
- 1067 浏览
添加回答
举报
0/150
提交
取消