C++第五次上机实验

/*
* 文件名称: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;
}
运行结果:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值