最近做的一道c++作业题

今天突然想到,接触这玩意快一年了,结果还是弱鸡一只。一直跟自己说慢慢来,但是觉得,还是不能慢慢来,虽然想好好学习,但一直只是想。有时候想什么高数什么大物都不写,但是囿于现实,没办法。。没地方说事情就在这里巴拉巴拉一大堆先。看题吧

实验内容

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

分析:

学校里,主要有四类人员:大学本科学生、教师、研究生和助教。

大学本科生每周有固定的学时数。教师除了固定的学时数外,还有每周的教学时数。研究生除了固定的学时数外,每周还可以自由做一定的研究。助教生除了上课外,还要做研究和一定的教学工作。

人员的基本信息包括姓名、编号、性别、身份证号、总学时数以及每周固定学时数。各个人员之间的关系: people类派生出student 类和teacher类,student 类派生出graduate类, graduate类和teacher类派生出TA类。

我写出的渣渣代码如下:
 //work.h
#include < iostream >
#include<cstring>
#include<string>
#include<stdio.h>
#include <inttypes.h>
using namespace std;
static int k = 0;
static int k1 = 0;
static int k2 = 0;
static int k3 = 0;
 #define N 100
class people
{

public:
	people(){}
	virtual void Base_information()=0;
	virtual void printf()= 0;
	virtual void show() = 0;
	int a[N];
	int b[N];
	int c[N];
	int d[N];
};
class student : virtual public people
{
public:
	student(){}
	string name[N];
	int num[N];
	string sex[N];
	string idnum[N];
	int s_time[N];
	int all_time[N];
	void Base_information()
	{
		cout << "请输入姓名:";
		cin >> name[k];
		cout << "请输入学号:";
		cin >> num[k];
		cout << "请输入性别:";
		cin >> sex[k];
		cout << "请输入身份证号码:";
		cin >> idnum[k];
		cout << "请输入固定学时数:";
		cin >> s_time[k];	
	}
	int ALL_TIME(int,int );
	void printf()
	{
		a[k] = ALL_TIME(s_time[k], all_time[k]);
		cout << "一周的总学时为:" << a[k] << endl;
	//	cout << k << endl;
		k++;
	}
	void show()
	{
		for (int i = 0; i < k; i++)
		{
			cout << i + 1 << "、" << "姓名:" << name[i] << '\t' << "学号:" << num[i] << '\t' <<
				"性别:" << sex[i] << '\t' << "身份证:" << idnum[i] << '\t' << "周学时:" << a[i] << endl;
		}
	}
};
class teacher :virtual public people
{
public:
;
	teacher(){}
	string name1[N];
	int num1[N];
	string sex1[N];
	string idnum1[N];
	int s_time1[N];
	int all_time1[N];
	void Base_information()
	{
		cout << "请输入姓名:";
		cin >> name1[k1];
		cout << "请输入学号:";
		cin >> num1[k1];
		cout << "请输入性别:";
		cin >> sex1[k1];
		cout << "请输入身份证号码:";
		cin >> idnum1[k1];
		cout << "请输入固定学时数:";
		cin >> s_time1[k1];
		cout << "请输入教学学时:";
		cin >> c_time1[k1];
	}

	int ALL_TIME(int , int , int );
	void printf()
	{
		b[k1] = ALL_TIME(s_time1[k1], c_time1[k1], all_time1[k1]);
		cout << "一周的总学时为:" << b[k1] << endl;
		k1++;
	}
	void show()
	{
		for (int j = 0; j < k1; j++)
		{
			cout << j + 1 << "、" << "姓名:" << name1[j] << '\t' << "学号:" << num1[j] << '\t' <<
				"性别:" << sex1[j] << '\t' << "身份证:" << idnum1[j] << '\t' << "周学时:" << b[j] << endl;
		}
	}
private:
	int c_time1[N];

};
class graduate : virtual public student
{
public:
	graduate(){}
	string name2[N];
	int num2[N];
	string sex2[N];
	string idnum2[N];
	int s_time2[N];
	int all_time2[N];
	void Base_information()
	{
		cout << "请输入姓名:";
		cin >> name2[k2];
		cout << "请输入学号:";
		cin >> num2[k2];
		cout << "请输入性别:";
		cin >> sex2[k2];
		cout << "请输入身份证号码:";
		cin >> idnum2[k2];
		cout << "请输入固定学时数:";
		cin >> s_time2[k2];
		cout << "请输入每周的研究时数:";
		cin >> dis_time2[k2];
	}
	int ALL_TIME(int , int , int );
	void printf()
	{
		c[k2] = ALL_TIME(s_time2[k2], dis_time2[k2], all_time2[k2]);
		cout << "一周的总学时为:" << c[k2] << endl;
	//	cout << k2 << endl;
		k2++;
	}
	void show()
	{
		for (int p = 0; p < k2; p++)
		{
			cout << p + 1 << "、" << "姓名:" << name2[p] << '\t' << "学号:" << num2[p] << '\t' <<
				"性别:" << sex2[p] << '\t' << "身份证:" << idnum2[p] << '\t' << "周学时:" << c[p] << endl;
		}
	}
protected:
	int dis_time2[N];
};
class TA : public graduate, public teacher
{
public:

	TA(){}
	string name3[N];
	int num3[N];
	string sex3[N];
	string idnum3[N];
	int s_time3[N];
	int all_time3[N];
	void Base_information()
	{
		cout << "请输入姓名:";
		cin >> name3[k3];
		cout << "请输入学号:";
		cin >> num3[k3];
		cout << "请输入性别:";
		cin >> sex3[k3];
		cout << "请输入身份证号码:";
		cin >> idnum3[k3];
		cout << "请输入固定学时数:";
		cin >> s_time3[k3];
		cout << "请输入每周的研究时数:";
		cin >> dis_time3[k3];
		cout << "请输入助学时数:";
		cin >> hel_time3[k3];
	}
	int ALL_TIME(int , int , int , int );
	void printf()
	{
		d[k3]=ALL_TIME(s_time3[k3], dis_time3[k3], hel_time3[k3],all_time3[k3]);
		cout <<"一周的总学时为:"<< d[k3] << endl;
		k3++;
	}
	void show()
	{
		for (int q = 0; q < k3; q++)
		{
			cout << q + 1 << "、" << "姓名:" << name3[q] << '\t' << "学号:" << num3[q] << '\t' <<
				"性别:" << sex3[q] << '\t' << "身份证:" << idnum3[q] << '\t' << "周学时:" << d[q] << endl;
		}
	}
private:
	int hel_time3[N];
	int dis_time3[N];
};

//Work_d.cpp
#include"work.h"
int student:: ALL_TIME(int, int)
	{	
		k++;
		all_time[k-1] = s_time[k-1];;
		return all_time[k-1];
	}
int teacher::ALL_TIME(int , int , int )
	{
		k1++;
		all_time1[k1-1] = s_time1[k1-1] + c_time1[k1-1];
//		cout << k1<< endl;
		return all_time1[k1-1];
	}
int graduate::ALL_TIME(int , int , int )
	{
		k2++;
		all_time2[k2-1] = s_time2[k2-1] + dis_time2[k2-1];
	//	cout << k2 << endl;
		return all_time2[k2-1];
	}
int TA::ALL_TIME(int , int , int , int )
	{
		k3++;
		all_time3[k3-1] = s_time3[k3-1] + dis_time3[k3-1] + hel_time3[k3-1];
//		cout << k3 << endl;
		return all_time3[k3-1];
	}

//work_d.cpp
#include"work.h"
int main()
{
	cout << '\t' << '\t' << "欢迎来到我校人员管理系统:" << endl;
	people *p;
	teacher q;
	graduate e;
	student s;
	TA r;
		cout << '\t' << '\t' << " 录入本科生信息,请按1。" << endl;
		cout << '\t' << '\t' << " 录入教师信息,请按2。" << endl;
		cout << '\t' << '\t' << " 录入研究生信息,请按3。" << endl;
		cout << '\t' << '\t' << " 录入助教信息,请按4。" << endl;
		cout << '\t' << '\t' << " 查看本科生信息,请按5。" << endl;
		cout << '\t' << '\t' << " 查看教师信息,请按6。" << endl;
		cout << '\t' << '\t' << " 查看研究生信息,请按7。" << endl;
		cout << '\t' << '\t' << " 查看助教信息,请按8。" << endl;
		cout << '\t' << '\t' << " 退出请按9。" << endl;
		cout << "请输入您的指令:__" << "\b\b";
		int ch;
		while (cin>>ch)
		{ 
			switch (ch)
			{
			case 1:p = &s; p->Base_information(); p->printf(); break;
			case 2:p = &q; p->Base_information(); p->printf(); break;
			case 3:p = &e; p->Base_information(); p->printf(); break;
			case 4:p = &r; p->Base_information(); p->printf(); break;
			case 5:p = &s; p->show(); break;
			case 6:p = &q; p->show(); break;
			case 7:p = &e; p->show(); break;
			case 8:p = &r; p->show(); break;
			case 9:break;
			}
		}
		return 0;
	}






这个代码还不是很完善,例如,按9退出并不是跳出整个循环,还有感觉数据的处理还是不太好,占用内存太大,但目前的知识只能这样做了。

还有就是感觉可以加上信息的删除啊之类的,但是作业要交了,而且没有要求。。留着以后做吧,以后学多了继续优化添加。

经过这些时间的学习,总觉得越来越贴近生活了,对各种事情充满好奇心,但是。。连书都还不会好好看的弱鸡。。。还需要很多努力才能追上别人,毕竟是转专业来的。。
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值