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

📄 9_79.cpp

📁 上传经典的适合C++初学者的一百个C++例子代码
💻 CPP
字号:
#include<iostream.h>
#include<string.h>
class Person
{
public:
	Person(const char*n,const char*t,const char*a)
	{
		name=new char[strlen(n)+1];
		strcpy(name,n);
		tel=new char[strlen(t)+1];
		strcpy(tel,t);
		add=new char[strlen(a)+1];
		strcpy(add,a);
	}
	void Print() const
	{ 
		cout<<name<<endl;
		cout<<" TEL:"<<tel;
		cout<<" Address:"<<add;
	}
	~Person()
	{
		delete[] name;
		delete[] tel;
		delete[] add;
//		cout<<"Destructed class Person!"<<endl;
	}
protected:
	char*name;
	char*tel;
	char*add;
};
class Student:virtual public Person
{
public:
	Student(const char*n,const char*t,const char*a,const char*m):Person(n,t,a)
	{
		major=new char[strlen(m)+1];
		strcpy(major,m);
	}
	void Print() const
	{	
		Person::Print();
		cout<<" Major:"<<major<<endl;
	}
protected:
	char*major;
};
class Staff:virtual public Person
{
public:
	Staff(const char*n,const char*t,const char*a,const char*d,int sal):Person(n,t,a)
	{
		dept=new char[strlen(d)+1];
		strcpy(dept,d);
		salary=sal;
	}
	void Print() const
	{
		Person::Print();
		cout<<" Department:"<<dept;
		cout<<" Salary:"<<salary<<endl;
	}
protected:
	char*dept;
	int salary;
};
class Teacher: public Staff
{
public:
	Teacher(const char*n,const char*d,const char*t,const char*a,const char*l,int sal)
		:Person(n,t,a),Staff(n,t,a,d,sal)
	{
		lesson=new char[strlen(l)+1];
		strcpy(lesson,l);
	}
	void Print() const
	{
		Staff::Print();
		cout<<" Lesson: "<<lesson<<endl;
	}
protected:
	char*lesson;
};
class StudentTeacher:public Student,public Teacher
{
public:
	StudentTeacher(const char*n,const char *m,const char*d,const char*t,\
		const char*a,const char*l,int sal)\
		:Person(n,t,a),Student(n,t,a,m),Teacher(n,d,t,a,l,sal){}
	void Print() const
	{
		Student::Print();
		cout<<" Department: "<<dept;
		cout<<" Lesson: "<<lesson;
		cout<<" Salary: "<<salary;
	}
};
void main()
{
	Student stu("Richard","01012345678","EAST_16_1","Software Engineering");
	Staff sta("Volatire","01012345679","WEST_16_2","Management",2000);
	Teacher te("Churchill","Computer","01012345677","EAST_16_5","C++",2500);
	StudentTeacher st("Emerson","Computer Application","Computer","01012345676",\
		"EAST_16_7","C++",2200);
    cout<<"Student:";
	stu.Print();
	cout<<"Stsff:";
	sta.Print();
	cout<<"Teacher:";
	te.Print();
	cout<<"Teacher in studying:";
	st.Print();
	cout<<endl;
}

⌨️ 快捷键说明

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