码迷,mamicode.com
首页 > 编程语言 > 详细

C++第五次实验

时间:2016-05-07 10:22:02      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

/* 
*文件名称: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: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:public Leader     // 继承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 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++第五次实验

标签:

原文地址:http://blog.csdn.net/w1574489152/article/details/51330240

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!