类的继承2

//Cadre.h

#pragma once
class Cadre
{
public:
	Cadre(char*,int,int,char*,char*,char*);
	~Cadre();
	void display();
	void getpost();
private:
	
	int age;
	int sex;
	char add[50];
	char tel[20];
public:
	char name[20];
	char post[20];
};

//Teacher.h

#pragma once
class Teacher
{
public:
	Teacher(char*,int,int,char*,char*,char*);
	~Teacher();
	void display();
private:
	
	int age;
	int sex;
	char add[50];
	char tel[20];
public:
	char name[20];
	char title[20];
};

//Teacher-Cadre.h

#pragma once
#include "Teacher.h"
#include "Cadre.h"
#include<iostream>
class Teacher_Cadre :public Teacher,public Cadre
{public:
	Teacher_Cadre(char*Nam, int a, int s, char*add, char*tel, char*tit, char *pos, double wages);
	~Teacher_Cadre();
	void show();
private :
	double wages;
};

//Cadre.cpp

#define _CRT_SECURE_NO_WARNINGS
#include "Cadre.h"
#include<iostream>
using namespace std;

Cadre::Cadre(char *Nam, int a, int s, char *add, char *tel, char *pos)
{
	strcpy(name , Nam);
	age = a;
	sex = s;
	strcpy(this->add , add);
	strcpy(this->tel, tel);
	strcpy(post ,pos);

}


Cadre::~Cadre()
{
	cout << "Cadre析构函数" << endl;
}
void Cadre::display()
{
	cout << "name:" << name << "\n" << "age:" << age << "\n" << "address:" << add << "\n" << "telephoto:" << tel << "\n" << "post:" << post << "\n";

}
void  Cadre::getpost()
{
	cout<<post;
}

//Teacher.cpp

#define _CRT_SECURE_NO_WARNINGS
#include "Teacher.h"
#include<iostream>
using namespace std;

Teacher::Teacher(char*Nam, int a, int s, char*add, char*tel, char*tit)
{
	strcpy(name, Nam);
	age = a;
	sex = s;
	strcpy(this->add, add);
	strcpy(this->tel, tel);
	strcpy(title, tit);
}


Teacher::~Teacher()
{
	cout << "Teacher析构函数" << endl;
}
void Teacher::display()
{
	cout << "name:" << name << "\n"<< "age:" << age << "\n" << "address:" << add << "\n" << "telephoto:" << tel << "\n" << "title:" << title << "\n" ;

}

//Teacher-Cadre.cpp

#include "Teacher_Cadre.h"
#include "Teacher.h"
#include "Cadre.h"
#include<iostream>
using namespace std;

Teacher_Cadre::Teacher_Cadre(char*Nam, int a, int s, char*add, char*tel, char*tit, char *pos, double w) : Teacher(Nam,  a,  s, add, tel, tit), Cadre(Nam, a, s, add, tel,pos)
{
	wages = w;
}


Teacher_Cadre::~Teacher_Cadre()
{
	cout << "Teache_Cadre" << endl;
}
void Teacher_Cadre::show()
{
	Teacher::display();
	cout <<Cadre::name<<"\n"<< "post:" << post << "\n" << "wages:" << wages << endl;


}

//main.cpp

#include "Teacher.h"
#include "Cadre.h"
#include "Teacher_Cadre.h"
#include<iostream>
using namespace std;
int main()
{
	Teacher_Cadre a1("liming",20,0, "http//www,dddd","0556-123456789","professor","leader",10000);
	a1.show();
	system("pause");
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值