/**** 这个类完成的是共有继承,但我不知道该怎么写 把它和这个类的类函数写到主函数的文件中编译可以通过,请问在这里我该如何写呢?******/
#include"Student.h" // 以我的愚见 我认为以下四行很有可能出错
#include"Teacher.h"
class Teachers;
class Students;
class Graduate :public Teachers,public Students
{
public :
Graduate(string nam1,int ag,float s,string na,int a,string t,float w):
Students(nam1,ag,s),Teachers(na,a,t),wages(w){}
void show();
private:
int wages;
};
/**************************************************************/
/************************ 以下下部分为main.cpp *************************/
#include<iostream>
#include"Student.h"
#include"Teacher.h"
#include"Graduate.h"
int main(void)
{
Graduate g1("胡成",21,87,"胡成",21,"教授",6800);
g1.show();
return 0;
}
/*********************************************************/
/************************ Teacher.h*******************/
#include<string>
using namespace std;
class Teachers{
public:
Teachers(string na,int a,string t):name(na),age(a),title(t){}
void dispaly1();
protected:
string name;
int age;
string title;
};
/******************* Student.h*************************/
#include<string>
using namespace std;
class Students
{
public :
Students(string nam1,int a,float s): name1(nam1),age(a),score(s){}
void display();
protected:
string name1;
int age;
float score;
};
/********************************************************************************/
所有的类。cpp,都是差不多的,只是输出的作用
/*********************** Teacher.cpp ,另外一个差不多一模一样***********************/
#include<iostream>
#include"Teacher.h"
void Teachers::dispaly1()
{
cout<<"姓名:"<<name<<endl;
cout<<"年龄:"<<age<<endl;
cout<<"职称:"<<title<<endl;
}
#include"Student.h" // 以我的愚见 我认为以下四行很有可能出错
#include"Teacher.h"
class Teachers;
class Students;
class Graduate :public Teachers,public Students
{
public :
Graduate(string nam1,int ag,float s,string na,int a,string t,float w):
Students(nam1,ag,s),Teachers(na,a,t),wages(w){}
void show();
private:
int wages;
};
/**************************************************************/
/************************ 以下下部分为main.cpp *************************/
#include<iostream>
#include"Student.h"
#include"Teacher.h"
#include"Graduate.h"
int main(void)
{
Graduate g1("胡成",21,87,"胡成",21,"教授",6800);
g1.show();
return 0;
}
/*********************************************************/
/************************ Teacher.h*******************/
#include<string>
using namespace std;
class Teachers{
public:
Teachers(string na,int a,string t):name(na),age(a),title(t){}
void dispaly1();
protected:
string name;
int age;
string title;
};
/******************* Student.h*************************/
#include<string>
using namespace std;
class Students
{
public :
Students(string nam1,int a,float s): name1(nam1),age(a),score(s){}
void display();
protected:
string name1;
int age;
float score;
};
/********************************************************************************/
所有的类。cpp,都是差不多的,只是输出的作用
/*********************** Teacher.cpp ,另外一个差不多一模一样***********************/
#include<iostream>
#include"Teacher.h"
void Teachers::dispaly1()
{
cout<<"姓名:"<<name<<endl;
cout<<"年龄:"<<age<<endl;
cout<<"职称:"<<title<<endl;
}