C++ 第一次实验课

第一次 实验

题目

代码

#include <iostream>
#include <string>
#define Author JokerNoCry
#define Date 2020/4/13
using namespace std;

class Person
{
private:
	string Name, Sex, Age;
public:
	void SetDate()
	{
		cout << "Please input name:" << endl; cin >> Name;
		cout << "Please input sex:" << endl; cin >> Sex;
		cout << "Please input age:" << endl; cin >> Age;
	}
	void Display() const
	{
		cout << "The name is : " << Name << endl;
		cout << "The sex is : " << Sex << endl;
		cout << "The age is : " << Age << endl;
	}
};
class Teacher :public Person
{
private:
	string Number, Job, Dept;
public:
	void SetDate()
	{
		Person::SetDate();
		cout << "Please input number:" << endl; cin >> Number;
		cout << "Please input job:" << endl; cin >> Job;
		cout << "Please input dept:" << endl; cin >> Dept;
	}
	void Display() const
	{
		Person::Display();
		cout << "The number is : " << Number << endl;
		cout << "The job is : " << Job << endl;
		cout << "The dept is : " << Dept << endl;
	}
};
class Student :public Person
{
private:
	string Number, Classroom;
	int Math, Chinese, English;
public:
	void SetDate()
	{
		Person::SetDate();
		cout << "Please input number:" << endl; cin >> Number;
		cout << "Please input classroom:" << endl; cin >> Classroom;
		cout << "Please input math scores:" << endl; cin >> Math;
		cout << "Please input chinese scores:" << endl; cin >> Chinese;
		cout << "Please input english scores:" << endl; cin >> English;
	}
	void Display() const
	{
		Person::Display();
		cout << "The number is : " << Number << endl;
		cout << "The classroom is : " << Classroom << endl;
		cout << "The math scores is : " << Math << endl;
		cout << "The chinese scores is : " << Chinese << endl;
		cout << "The english scores is : " << English << endl;
	}
};
int main()
{
	Teacher tea[100];
	Student stu[100];
	int Identity;
	int t = 0, s = 0;
	cout << "Please choice identity :0.Exit 1.Teacher 2.Student" << endl;
	while (cin >> Identity)
	{
		if (Identity == 0)
		{
			cout << "GoodBye !" << endl;
		}
		else if (Identity == 1)
		{
			tea[t].SetDate();
			tea[t++].Display();
			cout << "Please choice identity :0.Exit 1.Teacher 2.Student" << endl;
		}
		else if (Identity == 2)
		{
			stu[s].SetDate();
			stu[s++].Display();
			cout << "Please choice identity :0.Exit 1.Teacher 2.Student" << endl;
		}
		else
		{
			cout << "Error !\nPlease input age!" << endl;
			cout << "Please choice identity :0.Exit 1.Teacher 2.Student" << endl;
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_30445397/article/details/105484797