C++第五次实验

/* 
*文件名称:Ex1-5.cpp   
*作者:吴培鸿   
*完成日期:2016年5月6日   
*对任务及求解方法的描述部分:   
*输入描述:无   
*问题描述:1.程序填空
		   2.类的编写
*程序输出:按要求写出程序
*问题分析:略   
*算法分析:略  
*/ 
//1.
#include <iostream>    
#include <string>    
using namespace std;    
class Person    
{    
    string name;  // 姓名    
    int age;      // 年龄    
public:    
  
    Person() {}    
    void setname(string na)    
    {    
        name=na;    
    }    
    void setage(int a)    
    {    
        age=a;    
    }    
    string getname()    
    {    
        return name;    
    }    
    int getage()    
    {    
        return age;    
    }    
};    
class Leader:virtual public Person    //继承Person的公有部分  
{    
    string job;     // 职务    
    string dep;     // 部门    
public:    
    Leader() { }    
    void setjob(string jb)    
    {    
        job=jb;    
    }    
    void setdep(char dp[])    
    {    
        dep=dp;          
    }    
    string getjob()    
    {    
        return job;    
    }    
    string getdep()    
    {    
        return dep;    
    }    
};    
class Engineer:virtual public Person     // 继承Leader的公有部分  
{    
    string major;     // 专业    
    string prof;      // 职称    
public:    
    Engineer () { }    
    void setmajor(string maj)    
    {    
        major=maj;    
    }    
    void setprof(string pf)    
    {    
        prof=pf;    
    }    
    string getmajor()    
    {    
        return major;    
    }    
    string getprof()    
    {    
        return prof;    
    }    
};    
class chairman:public Leader,public Engineer { } ;// 继承Engineer的公有部分  
int main()    
{    
    chairman c;    
    c.setname("张三");    
    c.setage(42);    
    c.setjob("处长");    
    c.setdep("技术处");    
    c.setmajor("轮机设计");    
    c.setprof("高级工程师");    
    cout <<c.getname() << "," <<c.getage()<<" 岁,担任" <<c.getdep() <<c.getjob() <<endl;    
    cout <<c.getprof() << ",从事" << c.getmajor()<< "专业" << "。 " << endl;    
    return 0;    
} 
//2.
#include<iostream>
#include<string>
using namespace std;
class Person
{
	string name;
	int age;
	string sex;
public:
	Person(){ }
	void get1(string name,int age,string sex);//输入名字、年龄、性别
	void showit();//一介输出
};
void Person::get1(string name,int age,string sex)
{
	this->name=name;
	this->age=age;
	this->sex=sex;
}
void Person::showit()
{
	cout<<"姓名:"<<name<<endl;
	cout<<"年龄:"<<age<<endl;
	cout<<"性别:"<<sex<<endl;
}
class Teacher:public Person
{
	string title;
public:
	void get2(string title);//输入职称
	void show_it();//二阶输出
};
void Teacher::get2(string title)
{
	this->title=title;
}
void Teacher::show_it()
{
	Person::showit();
	cout<<"职称:"<<title<<endl;
}
class Cadre:public Teacher
{
	string post;
public:
	Cadre(){}
	void get3(string post);//输入职务
	void show();//三阶输出
};
void Cadre::get3(string post)
{
	this->post=post;
}
void Cadre::show()
{
	Teacher::show_it();
	cout<<"职务:"<<post<<endl;
}
class Teacher_Cadre:public Cadre
{
	double wages;
public:
	Teacher_Cadre(){}
	void get4(double wages);//输入工资
	void onshow();//最终输出
};
void Teacher_Cadre::get4(double wages)
{
	this->wages=wages;
}
void Teacher_Cadre::onshow()
{
	Cadre::show();
	cout<<"工资:"<<wages<<endl;
}
int main()
{
	Teacher_Cadre t1;
	t1.get1("曾辉",42,"男");
	t1.get2("副教授");
	t1.get3("主任");
	t1.get4(1534.5);
	t1.onshow();
	return 0;
}

你可能感兴趣的:(C++第五次实验)