C++机房预约系统构建(二)

机房预约系统搭建

此次系统主要使用的语言为c++语言,使用了部分STL的容器来储存,适合学过一段时间的c++,用来练手。使用的编程软件为vs2019。本文承接上文内容。

建立机房系统的欢迎页面

在vs中搭建机房预约系统.cpp文件,建立开始页面,使得进入系统人员可以在管理人员,教师和学生之间选择进入方式。

机房预约系统.cpp

此部分作为文件的各个部分的连接段,比较重要,主程序主要使用了while循环和switch选择来完成,在switch中完成选择部分

#include<iostream>
#include<string>
using namespace std;
#include"globalFile.h"
#include<fstream>
#include"identity.h"
#include"student.h"
#include"teacher.h"
#include"manger.h"

int main()
{
	int select = 0;

	while (true)
	{
		cout << "==============欢迎进入机房预约系统==============" << endl;
		cout << "请输入你的身份" << endl;
		cout << "\t\t--------------------------------" << endl;
		cout << "\t\t|                               |" << endl;
		cout << "\t\t|       1.学生登录              |" << endl;
		cout << "\t\t|                               |" << endl;
		cout << "\t\t|       2.教师登录              |" << endl;
		cout << "\t\t|                               |" << endl;
		cout << "\t\t|       3.管理员登录            |" << endl;
		cout << "\t\t|                               |" << endl;
		cout << "\t\t|       0.退出系统              |" << endl;
		cout << "\t\t|                               |" << endl;
		cout << "\t\t---------------------------------" << endl;
		cout << "\t\t请输入你的选择" << endl;
		cin >> select;
		switch (select)
		{
		case 1:
			LoginIn(STUDNENT_FILE, 1);
			break;
		case 2:
			LoginIn(TEACHER_FILE, 2);
			break;
		case 3:
			LoginIn(ADMIN_FILE, 3);
			break;
		case 0:
			cout << "欢迎下次使用" << endl;
			system("pause");
			return 0;
			break;
		default:
			cout << "输入有误,请重新输入" << endl;
			system("pause");
			system("cls");
			break;
		}
	}
	return 0;
}

LoginIn函数

此函数主要用来对存在的文件进行判断和在主函数中所输入进入的数字进行分类,在分别调用不同的函数进行怕判断。主要使用的ifstream读取文件,进行判断,在简单的调用else和if文件分别对不同type的数字进行不同的选项,最后完成转向和对用户密码和账号和文件中存在的密码和账号进行判断。

void LoginIn(string filename, int type)
{
	Identity* person = NULL;

	ifstream ifs;
	ifs.open(filename, ios::in);
	
	if (!ifs.is_open())
	{
		cout << "不存在文件" << endl;
		ifs.close();
		return;
	}

	int id = 0;
	string name;
	string pwd;

	if (type == 1)
	{
		cout << "请输入你的学号" << endl;
		cin >> id;
	}
	else if (type == 2)
	{
		cout << "请输入你的职工号" << endl;
		cin >> id;
	}

	cout << "请输入你的账号" << endl;
	cin >> name;
	cout << "请输入你的密码" << endl;
	cin >> pwd;
	
	if (type == 1)
	{
		int fid;
		string fname;
		string fpwd;
		while (ifs >> fid && ifs >> fname && ifs >> fpwd)
		{	
			if (id == fid && name == fname && pwd == fpwd)
			{
				cout << "学生登录成功" << endl;
				system("pause");
				system("cls");
				person = new Student(id, name, pwd);
				studentMenu(person);
				return;
			}
		}

	}
	else if(type == 2)
	{
		int fid;
		string fname;
		string fpwd;
		while (ifs >> fid && ifs >> fname && ifs >> fpwd)
		{
			if (id == fid && name == fname && pwd == fpwd)
			{
				cout << "教师端登录成功" << endl;
				system("pause");
				system("cls");
				person = new Teacher(id, name, pwd);
				teacherMenu(person);
				return;
			}
		}
	}
	else if(type == 3)
	{
		string fname;
		string fpwd;
		while ( ifs >> fname && ifs >> fpwd)
		{
			if ( name == fname && pwd == fpwd)
			{
				cout << "管理端登录成功" << endl;
				system("pause");
				system("cls");
				person = new Manger(name, pwd);
				mangerMenu(person);
				return;
			}
		}
	}

	cout << "验证失败" << endl;

	system("pause");
	system("cls");
	return;
}

不同类型的menu函数

共有三个函数分别teacherMenu,studentMenu,mangerMenu对应了不同类型的分主菜单,现在可以通过头文件引用对不同类型的菜单进行编辑,来显示不同的内容。下方主要展现teacherMenu函数,其余函数与之类似。

void teacherMenu(Identity*& teacher)
{
	while (true)
	{
		teacher->openmenu();
		Teacher* tea = (Teacher*)teacher;

		int select = 0;
		cin >> select;

		if (select == 1)
		{
			cout << "查看所有预约" << endl;
			tea->showAllorder();
		}
		else if (select == 2)
		{
			cout << "审核预约" << endl;
			tea->validOrder();
		}
		else
		{
			delete teacher;
			cout << "注销成功" << endl;
			system("pause");
			system("cls");
			return;
		}
	}


}

本文结束,下文将分别对不同类型的.h文件进行编辑来完成不同的功能。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值