第12周实验报告2

实验目的:多重继承

* 程序头部注释开始
* 程序的版权和版本声明部分
* 烟台大学计算机学院学生
* 文件名称:        多重继承

* 作    者:          胡斌                
* 完成日期:  2012 年 5月8日
* 版本号:     v1.0    

#include <iostream>
#include<string>
using namespace std;

class Teacher
{
     public:
		 Teacher(string nam,int a ,char s,string ad, int te,string t)
		 {
			 name = nam;
			 age = a;
			 sex = s;
			 add = ad;
			 tel = te;
			 title = t;
		 }
		 
		 ~Teacher(){};

         void display();
     protected:
		 string name;
		 int age;
		 char sex;
		 string add;
		 int tel;
		 string title;
};

class Cadre
{
     public:
		 Cadre(string nam,int a ,char s,string ad, int te,string p)
		 {
			 name = nam;
			 age = a;
			 sex = s;
			 add = ad;
			 tel = te;
			 post = p;
		 }
		 
		 ~Cadre(){};
     protected:
		 string name;
		 int age;
		 char sex;
		 string add;
		 int tel;
		 string post;
};
class Teacher_Cadre:public Teacher,public Cadre
{
     public:
		 Teacher_Cadre(string nam,int a ,char s,string ad, int te,string t,string p,float w):Teacher(nam,a,s,ad,te,t),Cadre(nam,a,s,ad,te,p),wages(w){}

		 void show();
     private:
		 float wages;
};

int main()
{
	Teacher_Cadre T_C("hubin", 20, 'm', "yantaidaxue", 182531," tejijiaoshi"," gongwuyuan", 5000);
	 
    T_C.show();

	system("pause");
    return 0;
}

void Teacher::display()
{
	cout<<"mane:"<<Teacher::name<<endl;
	cout<<"age:"<<Teacher::age<<endl;
	cout<<"sex:"<<Teacher::sex<<endl;
	cout<<"add:"<<Teacher::add<<endl;
	cout<<"tel:"<<Teacher::tel<<endl;
	cout<<"title:"<<Teacher::title<<endl;
}

void Teacher_Cadre::show()
{
	Teacher::display();
	cout<<"post:";
	cout<<post<<endl;
	cout<<"wages:"<<wages<<endl;
}


截图:

mane:hubin
age:20
sex:m
add:yantaidaxue
tel:182531
title: tejijiaoshi
post: gongwuyuan
wages:5000
请按任意键继续. . .


继承多了,虽然有点不适应,但功能还是挺大的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值