C++程序设计小实验④(实验报告)

实验题

实验:编写一个人员信息管理系统。这个系统的功能是:交互式地实现校园人员信息的录入与显示。

分析:
学校里,主要有四类人员:大学本科学生、教师、研究生和助教。
大学本科生每周有固定的学时数。教师除了固定的学时数外,还有每周的教学时数。研究生除了固定的学时数外,每周还可以自由做一定的研究。助教除了上课外,还要做研究和一定的教学工作。
人员的基本信息包括姓名、编号、性别、身份证号、总学时数、以及每周固定学时数。各个人员之间的关系:people类派生出student类和teacher类,student类派生出graduate类,graduate类和teacher类派生出TA类。

以下给出部分程序:

#include
using namespace std;

class people
{
public:
//添加程序
private:
};

class student: virtual public people
{
public:
//添加程序
private:
};

class teacher: virtual public people
{
public:
//添加程序
private:
};

class graduate: virtual public student
{
public:
//添加程序
private:
};

class TA: public graduate, public teacher
{
public:
//添加程序
private:
};

void main()
{
//添加程序
}

#include <iostream>
using namespace std;

class people
{
    
    
 public:
	char name[6];
	char sex[6];
	char id[6];
};

class student : virtual public people
{
    
    
public:
	double learn_time;
	student(double);   
	friend istream& operator >>(istream& in, student& x);
	void print1();

};
// student 构造函数
student::student(double time):learn_time(time){
    
    }

//student >>运算符重载
istream& operator >>(istream& in, student& x)
{
    
    
	cout << "请输入学生姓名:";
	in >> x.name;
	cout << "请输入学生的性别:(man or woman)";
	in >> x.sex;
	cout << "请输入学生的ID: ";
	in >> x.id;
	return in;

}
//student类输出
void student::print1()
{
    
    
	cout << "学生: " << endl;
	cout << "姓名" << "\t" << "性别" << "\t" << "ID" << "\t" << "学时"<<endl;
	cout << name << "\t" << sex << "\t" << id << "\t" << learn_time << endl;;

}
//

class teacher : virtual public people
{
    
    
public:
	double TElearning_time;
	double teach_time;
	teacher(double TElearning, double teach);
	friend istream& operator >>(istream& in, student& x);
	void printTE();

};
//teacher 构造函数
teacher::teacher(double TElearning,double teach):	TElearning_time(TElearning),
teach_time(teach)
{
    
    }
//teacher类输出
void teacher::printTE()
{
    
    
	cout << "教师: " << endl;
	cout << "姓名" << "\t" << "性别" << "\t" << "ID" << "\t" << "教师学时" <<"\t"<<"教学时间"<<endl;
	cout << name << "\t" << sex << "\t" << id << "\t" << TElearning_time << "\t" "\t" << teach_time << endl ;
}

//teacher >>类型符重载
istream& operator >>(istream& in, teacher& x)
{
    
    
	cout << "请输入老师姓名:";
	in >> x.name;
	cout << "请输入老师的性别:(man or woman)";
	in >> x.sex;
	cout << "请输入老师的ID: ";
	in >> x.id;
	return in;

}
//

class graduate : virtual public student
{
    
    
public:
	double research;
	graduate(double learning, double researching);
	friend istream& operator >>(istream& in, graduate& x);
	void printGA();

};
//graduate 构造函数
graduate::graduate(double learning, double reserching):student(learning),research(reserching)
{
    
    }
//graduate >>重载
istream& operator >>(istream& in, graduate& x)
{
    
    
	cout << "请输入研究生姓名:";
	in >> x.name;
	cout << "请输入研究生的性别:(man or woman)";
	in >> x.sex;
	cout << "请输入研究生的ID: ";
	in >> x.id;
	return in;

}
//graduate  输出
void graduate::printGA()
{
    
    
	cout << "研究生: " << endl;
	cout << "姓名" << "\t" << "性别" << "\t" << "ID" << "\t" << "学时" << "\t" << "研究时间" << endl;
	cout << name << "\t" << sex << "\t" << id << "\t" << learn_time << "\t" << research << endl;;

}

class TA : public graduate, public teacher
{
    
    
public:
	
	TA(double learning,double reserching,double teaching_time );
	friend istream& operator >>(istream& in, TA& x);
	void printTA();
};

//TA 构造函数
TA::TA(double learning, double reserching, double teaching_time) :
	graduate(learning, reserching), teacher(0, teaching_time),student(0)
{
    
    };
//TA >>重载
istream& operator >>(istream& in, TA& x)
{
    
    
	cout << "请输入助教姓名:";
	in >> x.name;
	cout << "请输入助教的性别:(man or woman)";
	in >> x.sex;
	cout << "请输入助教的ID: ";
	in >> x.id;
	return in;

}
//TA 输出
void TA::printTA()
{
    
    
	cout << "助教: "<<endl;
	cout << "姓名" << "\t" << "性别" << "\t" << "ID" << "\t" << "助教上课" << "\t" << "助教研究时间" <<"\t" <<"助教教学时间"<<endl;
	cout << name << "\t" << sex << "\t" << id << "\t" << learn_time <<  "\t" "\t" <<research<<"\t" "\t" "\t" << teach_time<<endl;

}


int main()
{
    
       
    student a(24);
	cin >> a;
	a.print1();

	teacher b(20,20);
	cin >> b;
	b.printTE();
	
	graduate c(33, 30);
	cin >> c;
	c.printGA();
	
	TA d(10,10,10);
	cin >> d;
	d.printTA();

	return 0;
}
    

Guess you like

Origin blog.csdn.net/qq_46167911/article/details/105642792