您的位置:首页 > 编程语言 > C语言/C++

第五次C++上实验

2016-05-06 17:48 495 查看
/*
*文件名称: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;
}

#include<iostream>
#include<string>
using namespace std;
class Teacher
{
string title;
public:
void get(string name,int age,string sex,string title);//输入职称、名字、年龄、性别
void show_it();
string name;
int age;
string sex;
};
void Teacher::get(string name,int age,string sex,string title)
{
this->name=name;
this->age=age;
this->sex=sex;
this->title=title;
}
void Teacher::show_it()
{
cout<<"姓名:"<<name<<endl;
cout<<"年龄:"<<age<<endl;
cout<<"性别:"<<sex<<endl;
cout<<"职称:"<<title<<endl;
}
class Cadre:public Teacher
{
string post;
public:
void get1(string post);//输入职务
void showpost();
};
void Cadre::get1(string post)
{
this->post=post;
}
void Cadre::showpost()
{
Teacher::show_it();
cout<<"职务:"<<post<<endl;
}
class Teacher_Cadre:public Cadre
{
double wages;
public:
void get2(double wages);//输入工资
void show();//最终输出
};
void Teacher_Cadre::get2(double wages)
{
this->wages=wages;
}
void Teacher_Cadre::show()
{
Cadre::showpost();
cout<<"工资:"<<wages<<"元"<<endl;
}
int main()
{
Teacher_Cadre c;
c.get("曾辉",42,"男","副教授");
c.get1("主任");
c.get2(1534.5);
c.show();
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: