/*
* 文件名称:Ex1-2.cpp
* 作 者:莫洋
* 完成日期:2016 年 5 月 8 日
* 版 本 号:v1.0
* 对任务及求解方法的描述部分:
* 输入描述:无
* 问题描述:
* 程序输出:略
* 问题分析:略
* 算法设计:略
*/
#include <iostream>
#include <string>
using namespace std;
class Person
{
string name;
int age;
string sex;
public:
Person() {}
void setname(string na)
{
name=na;
}
void setage(int a)
{
age=a;
}
void setsex(string s)
{
sex=s;
}
string getname()
{
return name;
}
int getage()
{
return age;
}
string getsex()
{
return sex;
}
};
class Teacher:virtual public Person
{
string title;
string post;
public:
Teacher() { }
void settitle(string te)
{
title=te;
}
string gettitle()
{
return title;
}
void display()
{
cout<<"姓名:"<<getname()<<endl;
cout<<"年龄:"<<getage()<<endl;
cout<<"性别:"<<getsex()<<endl;
}
};
class Cadre: virtual public Person
{
string post;
public:
Cddre() { }
void setpost(char pt[])
{
post=pt;
}
string getpost()
{
return post;
}
};
class Teacher_Cadre: public Teacher,public Cadre
{
double wages;
public:
Teacher_Cadre() {}
void setwages(double w)
{
wages=w;
}
double getwages()
{
return wages;
}
void show()
{
display();
}
};
void main()
{
Teacher_Cadre c;
c.setname("曾辉");
c.setage(42);
c.setsex("男");
c.settitle("副教授");
c.setpost("主任");
c.setwages(1534.5);
c.show();
cout <<"职称:"<<c.gettitle()<<endl;
cout <<"职务:"<<c.getpost()<<endl;
cout <<"工资:"<<c.getwages()<<endl;
}
运行结果:
C++第五次上机实验
最新推荐文章于 2021-04-08 10:07:21 发布