⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 empmult.cpp

📁 高永强 全C编程源码 清华大学出版社 2002年六月第一版
💻 CPP
字号:
//这个程序在本书所带软盘中。文件名为EMPMULT.CPP
//这个程序演示在程序中怎样进行多重继承以及多级继承。

#include <iostream.h>

const int LEN = 80;				//名字的最大长度

class student {                 //教育程度
	private:
		char school[LEN];		//学校名
		char degree[LEN];		//学位
	public:
		void getedu(void);
		void output(void);
};

void student::getedu(void)
{
	cout << "   输入学校名: ";
	cin >> school;
	cout << "   输入获得学位 \n";
	cout << "   (高中, 学士,硕士, 博士): ";
	cin >> degree;
}

void student::output(void)
{
	cout << "\n   学校: " << school;
	cout << "\n   学位: " << degree;
}

class employee {
	private:
		char name[LEN];         //雇员名
		int ID; 				//雇员编号
	public:
		void getdata(void);
		void display(void);
};

void employee::getdata(void)
{
	cout << "\n   输入姓: "; cin >> name;
	cout << "   输入雇员编号: ";      cin >> ID;
}

void employee::display(void)
{
	cout << "\n   雇员姓: " << name;
	cout << "\n   雇员编号: " << ID;
}

class worker : public employee  //从基类employee中导出worker
{
};

class scientist : private employee, private student
								//从基类employee和studnet导出scientist
{
	private:
		int pubs;				//出版数
	public:
		void getdata(void);
		void display(void);
};

void scientist::getdata(void)
{
	employee::getdata();
	cout << "   输入出版书数: "; cin >> pubs;
	student::getedu();
}

void scientist::display(void)
{
	employee::display();
	cout << "\n   出版书数为: " << pubs;
	student::output();
}

class supervisor : private employee, private student
								//从基类employee和student导出supervisor
{
	private:
		char department[LEN];
		int office;				//办公室
	public:
		void getdata(void);
		void display(void);
};

void supervisor::getdata(void)
{
	employee::getdata();
	cout << "   输入部门: ";          cin >> department;
	cout << "   输入办公室: "; cin >> office;
	student::getedu();
}

void supervisor::display(void)
{
	employee::display();
	cout << "\n   部门: " << department;
	cout << "\n   办公室: " << office;
	student::output();
}

class manager : public supervisor	//从基类supervisor导出manager
{
	private:
		char title[LEN];
		char club[LEN];			//例如高尔夫俱乐部
		public:
		void getdata(void);
		void display(void);
};

void manager::getdata(void)
{
	supervisor::getdata();
	cout << "   输入职务名称: "; cin >> title;
	cout << "   输入俱乐部名: "; cin >> club;
}

void manager::display(void)
{
	supervisor::display();
	cout << "\n   职务名称: " << title << endl;
	cout << "    俱乐部: " << club << endl;
}

void main()
{
	worker John;
	scientist Lee;
	supervisor Marry;
	manager boss;

	cout << endl;
	cout << "\n输入工人数据";
	John.getdata();
	cout << "\n输入科学家数据";
	Lee.getdata();
	cout << "\n输入监工数据";
	Marry.getdata();
	cout << "\n输入经理数据";
	boss.getdata();

	cout << "\n显示工人数据";
	John.display();
	cout << "\n显示科学家数据";
	Lee.display();
	cout << "\n显示监工数据";
	Marry.display();
	cout << "\n显示经理数据";
	boss.display();
}

/*下面是这个程序运行后的一个典型输出结果:

输入工人数据
	输入姓: 王
	输入雇员编号: 1203

输入科学家数据
	输入姓: 李
	输入雇员编号: 8900
	输入出版书数: 35
	输入学校名: 北大
	输入获得学位
	(高中, 学士,硕士, 博士): 博士

输入监工数据
	输入姓: 刘
	输入雇员编号: 8899
	输入部门: 销售
	输入办公室: 102
	输入学校名: 清华
	输入获得学位
	(高中, 学士,硕士, 博士): 学士

输入经理数据
	输入姓: 张
	输入雇员编号: 5122
	输入部门: 财务
	输入办公室: 204
	输入学校名: 财贸学院
	输入获得学位
	(高中, 学士,硕士, 博士): 硕士
	输入职务名称: 副经理
	输入俱乐部名: 高尔夫

显示工人数据
	雇员姓: 王
	雇员编号: 1203
显示科学家数据
	雇员姓: 李
	雇员编号: 8900
	出版书数为: 35
	学校: 北大
	学位: 博士
显示监工数据
	雇员姓: 刘
	雇员编号: 8899
	部门: 销售
	办公室: 102
	学校: 清华
	学位: 学士
显示经理数据
	雇员姓: 张
	雇员编号: 5122
	部门: 财务
	办公室: 204
	学校: 财贸学院
	学位: 硕士
	职务名称: 副经理
	 俱乐部: 高尔夫
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -