C++入门项目(四)——机房预约系统

引言

这个小项目是基于C++的综合知识,主要涵盖了C++的综合知识,有面向对象思想,泛型编程思想,STL的使用,文件的读写等。是为了深入掌握C++而做的一个入门级综合小项目。主要参考了黑马程序员的C++教程,下面是黑马程序员的C++教学视频链接。
黑马程序员C++教程

系统介绍

身份简介

本系统分别有三种身份使用该程序:
1.学生代表:申请使用机房
2.教师:审核学生的预约申请
3.管理员:给学生、教师创建账号

机房简介

机房共有3间
1号机房:最大容量20人
2号机房:最大容量50人
3号机房:最大容量100人

申请简介

申请的订单每周由管理员负责清空
学生可以预约未来一周内的机房使用,预约的日期为周一到周五,预约时需要选择预约时段(上午,下午)
教师来审核预约,依据实际情况审核预约通过或不通过

使用介绍

首先进入登录界面,可选的功能有:
1.学生代表
2.老师
3.管理员
4.退出
每个身份都需要进行验证后,才能进入子菜单。
学生需要输入:学号,姓名,登录密码
老师需要输入:职工号,姓名,登录密码
管理员需要输入:管理员姓名,登录密码

学生具体功能

1.申请预约
2.查看自身预约
3.查看所有预约
4.取消预约
5.注销登录

教师具体功能

1.查看所有预约
2.审核预约
3.注销登陆

管理员具体功能

1.添加账号
2.查看账号
3.查看机房
4.清空预约
5.注销登录

系统需要的类

程序中用到的文件名宏定义如下:

//管理员文件
#define ADMIN_FILE "admin.txt"
//学生文件
#define STUDENT_FILE "student.txt"
//教师文件
#define TEACHER_FILE "teacher.txt"
//机房信息文件
#define COMPUTER_FILE "computer.txt"
//订单文件
#define ORDER_FILE "order.txt"

机房类

#pragma once
#include <iostream>
using namespace std;
class Computer
{
public:
	int num_;	//机房号
	int size_;	//容量
};


预约类

#pragma once
#include <string>
#include <fstream>
#include <map>
#include <iostream>
#include "global.h"
using namespace std;
class Order
{
public:
	Order();
	//更新预约记录
	void updateOrder();
	//截取键值对
	void PutMap(string str,map<string,string>&m);
	//记录预约条数
	int size_;
	//记录预约信息,key记录条数,value记录键值对信息
	map<int, map<string, string>> orderdata_;
};

其源文件如下:

#include "order.h"

Order::Order()
{
	this->orderdata_.clear();
	ifstream ifs;
	ifs.open(ORDER_FILE, ios::in);
	string date;		//日期
	string interval;	//时间段
	string stuid;		//学号
	string stuname;		//姓名
	string roomid;		//机房号
	string status;		//预约状态
	this->size_ = 0;	//初始化记录条数
	while (ifs >> date && ifs >> interval && ifs >> stuid
		&& ifs >> stuname && ifs >> roomid && ifs >> status) {
		map<string, string> m;
		m.clear();
		this->PutMap(date, m);
		this->PutMap(interval, m);
		this->PutMap(stuid, m);
		this->PutMap(stuname, m);
		this->PutMap(roomid, m);
		this->PutMap(status, m);
		this->size_++;
		this->orderdata_.insert(make_pair(this->size_, m));
	}
	ifs.close();
}
//更新预约记录
void Order::updateOrder()
{
	if (this->size_ == 0) {
		return;
	 }
	ofstream ofs(ORDER_FILE, ios::out | ios::trunc);
	for (int i = 1; i <= this->size_; i++) {
		ofs << "date:" << this->orderdata_[i]["date"] << " ";
		ofs << "interval:" << this->orderdata_[i]["interval"] << " ";
		ofs << "stuid:" << this->orderdata_[i]["stuid"] << " ";
		ofs << "stuname:" << this->orderdata_[i]["stuname"] << " ";
		ofs << "roomid:" << this->orderdata_[i]["roomid"] << " ";
		ofs << "status:" << this->orderdata_[i]["status"] << endl;
	}
	ofs.close();
}
//截取键值对
void Order::PutMap(string str,map<string, string>& m)
{
	string key;
	string value;
	int pos = str.find(":"); 
	if (pos != -1) {
		key = str.substr(0, pos);
		value = str.substr(pos + 1, str.size() - pos - 1);
		m.insert(make_pair(key, value));
	}
}

身份抽象基类

#pragma once
#include <iostream>
#include <string>
using namespace std;
//身份抽象基类
class Identity
{
public:
	virtual void OperMenu() = 0;	//操作菜单
	string name_;					//用户名
	string password_;				//密码
};


管理员类

#pragma once
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include "identity.h"
#include "global.h"
#include "student.h"
#include "teacher.h"
#include "computer.h"
using namespace std;

class Admin : public Identity
{
public:
	Admin();
	Admin(string name, string password);
	~Admin();
	//选择菜单
	virtual void OperMenu();
	//添加账号
	void AddPerson();
	//查看账号
	void ShowPerson();
	//查看机房信息
	void ShowComputer();
	//清空预约记录
	void ClearFile();
	//初始化容器
	void InitVector();
	//检测是否有重复账号
	bool checkRepeat(int id,int type);
	vector<Student> stu_;
	vector<Teacher> tea_;
	vector<Computer> com_;
};

其源文件如下:

#include "admin.h"

Admin::Admin()
{

}
Admin::Admin(string name, string password)
{
	this->name_ = name;
	this->password_ = password;
	this->InitVector();
	ifstream ifs;
	ifs.open(COMPUTER_FILE, ios::in);
	Computer com;
	while (ifs >> com.num_ && ifs >> com.size_) {
		this->com_.push_back(com);
	}
	ifs.close();
}
Admin::~Admin()
{

}
//选择菜单
void Admin::OperMenu()
{
	cout <<  "欢迎管理员" << this->name_ << "登录!" << endl;
	cout << "\t\t-----------------------------------------\n";
	cout << "\t\t|                                        |\n";
	cout << "\t\t|               1.添加账号               |\n";
	cout << "\t\t|                                        |\n";
	cout << "\t\t|               2.查看账号               |\n";
	cout << "\t\t|                                        |\n";
	cout << "\t\t|               3.查看机房               |\n";
	cout << "\t\t|                                        |\n";
	cout << "\t\t|               4.清空预约               |\n";
	cout << "\t\t|                                        |\n";
	cout << "\t\t|               0.注销登录               |\n";
	cout << "\t\t|                                        |\n";
	cout << "\t\t-----------------------------------------\n";
	cout << "请选择您的操作:" << endl;
}
//添加账号
void Admin::AddPerson()
{
	string filename;	//操作的文件名
	string tip;			//提示信息
	string error;
	ofstream ofs;		
	int select = 0;
	cout << "请输入添加账号的类型:1.学生\t2.老师" << endl;
	while (true) {
		cin >> select;
		if (select == 1) {
			//学生类型
			tip = "请输入学号:";
			error = "学号重复,请重新输入!";
			filename = STUDENT_FILE;
			break;
		}
		else if (select == 2) {
			//老师类型
			tip = "请输入工号:";
			error = "工号重复,请重新输入!";
			filename = TEACHER_FILE;
			break;
		}
		else {
			cout << "输入错误,请重新输入!" << endl;
		}
	}
	ofs.open(filename, ios::out | ios::app);
	int fid;
	string fname;
	string fpassword;
	cout << tip;
	while (true) {
		cin >> fid;
		bool ret = this->checkRepeat(fid, select);
		if (ret) {
			cout << error << endl;
		}
		else {
			break;
		}
	}
	cout << "请输入用户名:";
	cin >> fname;
	cout << "请输入密码:";
	cin >> fpassword;
	ofs << fid << " " << fname << " " << fpassword << " " << endl;
	cout << "添加成功!" << endl;
	system("pause");
	system("cls");
	ofs.close();
	this->InitVector();
}
void PrintStu(Student& s)
{
	cout << "学号:" << s.id_ << "\t"
		<< "姓名:" << s.name_ << "\t"
		<< "密码:" << s.password_ << endl;
}
void PrintTea(Teacher& t)
{
	cout << "工号:" << t.id_ << "\t"
		<< "姓名:" << t.name_ << "\t"
		<< "密码:" << t.password_ << endl;
}
//查看账号
void Admin::ShowPerson()
{
	cout << "请选择要查看的内容:1.学生\t2.老师" << endl;
	int select = 0;
	while (true) {
		cin >> select;
		if (select == 1) {
			for_each(this->stu_.begin(), this->stu_.end(), PrintStu);
			break;
		}
		else if (select == 2) {
			for_each(this->tea_.begin(), this->tea_.end(), PrintTea);
			break;
		}
		else {
			cout << "输入错误,请重新输入!" << endl;
		}
	}
	system("pause");
	system("cls");
}
//查看机房信息
void Admin::ShowComputer()
{
	cout << "机房信息如下:" << endl;
	for (vector<Computer>::iterator it = this->com_.begin(); it != this->com_.end(); ++it) {
		cout << "机房号:" << it->num_ << "\t" << "机房最大容量:" << it->size_ << endl;
	}
	system("pause");
	system("cls");
}
//清空预约记录
void Admin::ClearFile()
{
	ofstream ofs(ORDER_FILE,ios::trunc);//如果文件存在则删除重建
	ofs.close();
	cout << "清空成功!" << endl;
	system("pause");
	system("cls");
}
//初始化容器
void Admin::InitVector()
{
	//确保容器为清空状态
	stu_.clear();
	tea_.clear();
	ifstream ifs;
	ifs.open(STUDENT_FILE, ios::in);
	if (!ifs.is_open()) {
		cout << "读取文件失败!" << endl;
		return;
	}
	Student s;
	while (ifs >> s.id_ && ifs >> s.name_ && ifs >> s.password_) {
		stu_.push_back(s);
	}
	ifs.close();

	ifs.open(TEACHER_FILE, ios::in);
	if (!ifs.is_open()) {
		cout << "读取文件失败!" << endl;
		return;
	}
	Teacher t;
	while (ifs >> t.id_ && ifs >> t.name_ && ifs >> t.password_) {
		tea_.push_back(t);
	}
	ifs.close();
}
//检测是否有重复账号
bool Admin::checkRepeat(int id, int type)
{
	if (type == 1) {
		//检测学生
		for (vector<Student>::iterator it = this->stu_.begin(); it != this->stu_.end(); ++it) {
			if (id == it->id_)	return true;
		}
	}
	else {
		//检测老师
		for (vector<Teacher>::iterator it = this->tea_.begin(); it != this->tea_.end(); ++it) {
			if (id == it->id_)	return true;
		}
	}
	return false;
}

学生类

#pragma once
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include "identity.h"
#include "global.h"
#include "computer.h"
using namespace std;

class Student : public Identity
{
public:
	Student();
	Student(int id,string name,string password);
	~Student();

	//菜单界面
	virtual void OperMenu();

	//申请预约
	void ApplyOrder();

	//查看我的预约
	void ShowMyOrder();

	//查看所有预约
	void ShowAllOrder();

	//取消预约
	void CancelOrder();

	int id_ = 0;	//学号
	vector<Computer> com_;
};

其源文件如下:

#include "student.h"
#include "order.h"
Student::Student()
{

}
Student::Student(int id, string name, string password)
{
	this->id_ = id;
	this->name_ = name;
	this->password_ = password;
	ifstream ifs;
	ifs.open(COMPUTER_FILE, ios::in);
	Computer c;
	while (ifs >> c.num_ && ifs >> c.size_) {
		this->com_.push_back(c);
	}
	ifs.close();
}

Student::~Student()
{
	
}

//菜单界面
void Student::OperMenu()
{
	cout << "欢迎学生" << this->name_ << "登录!" << endl;
	cout << "\t\t-----------------------------------------\n";
	cout << "\t\t|                                        |\n";
	cout << "\t\t|               1.申请预约               |\n";
	cout << "\t\t|                                        |\n";
	cout << "\t\t|               2.查看我的预约           |\n";
	cout << "\t\t|                                        |\n";
	cout << "\t\t|               3.查看所有预约           |\n";
	cout << "\t\t|                                        |\n";
	cout << "\t\t|               4.取消预约               |\n";
	cout << "\t\t|                                        |\n";
	cout << "\t\t|               0.注销登录               |\n";
	cout << "\t\t|                                        |\n";
	cout << "\t\t-----------------------------------------\n";
	cout << "请选择您的操作:" << endl;
}

//申请预约
void Student::ApplyOrder()
{
	cout << "机房开放时间为周一至周五,请选择预约时间:" << endl;
	cout << "1.周一\t" << "2.周二\t" << "3.周三\t" << "4.周四\t" << "5.周五" << endl;
	int date = 0;		//周几
	int interval = 0;	//上午下午
	int num = 0;		//几号机房
	while (true) {
		cin >> date;
		if (date >= 1 && date <= 5) {
			break;
		}
		else {
			cout << "输入错误,请重新输入!" << endl;
		}
	}
	cout << "请选择预约时间段:1.上午\t2.下午" << endl;
	while (true) {
		cin >> interval;
		if (interval >= 1 && interval <= 2) {
			break;
		}
		else {
			cout << "输入错误,请重新输入!" << endl;
		}
	}
	cout << "请选择预约的机房:" << endl;
	for (vector<Computer>::iterator it = this->com_.begin(); it != this->com_.end(); ++it) {
		cout << it->num_ << "号机房,容量为:" << it->size_ << endl;
	}
	while (true) {
		cin >> num;
		if (num >= 1 && num <= 3) {
			break;
		}
		else {
			cout << "输入错误,请重新输入!" << endl;
		}
	}
	cout << "预约成功,审核中!" << endl;
	ofstream ofs;
	ofs.open(ORDER_FILE, ios::app);
	ofs << "date:" << date << " ";
	ofs << "interval:" << interval << " ";
	ofs << "stuid:" << this->id_ << " ";
	ofs << "stuname:" << this->name_ << " ";
	ofs << "roomid:" << num << " ";
	ofs << "status:" << 1 << endl;
	ofs.close();
	system("pause");
	system("cls");
}

//查看我的预约
void Student::ShowMyOrder()
{
	Order of;
	if (of.size_ == 0) {
		cout << "无预约记录" << endl;
		system("pause");
		system("cls");
		return;
	}
	for (int i = 0; i <= of.size_; i++) {
		//c_str() 转 const char*
		// atoi (const char*) 转 int
		if (this->id_ == atoi(of.orderdata_[i]["stuid"].c_str())) {
			cout << "预约日期:周" << of.orderdata_[i]["date"] << "\t";
			cout << "时间段:" << (of.orderdata_[i]["interval"] == "1"?"上午":"下午") << "\t";
			cout << "学号:" << of.orderdata_[i]["stuid"] << "\t";
			cout << "姓名:" << of.orderdata_[i]["stuname"] << "\t";
			cout << "机房号:" << of.orderdata_[i]["roomid"] << "\t";
			string status;
			if (of.orderdata_[i]["status"] == "1") {
				status += "审核中";
			}
			if (of.orderdata_[i]["status"] == "2") {
				status += "预约成功";
			}
			if (of.orderdata_[i]["status"] == "-1") {
				status += "预约失败,审核未通过";
			}
			else {
				status += "预约已取消!";
			}
			cout << "预约状态:" << status << endl;;
		}
	}
	system("pause");
	system("cls");
}

//查看所有预约
void Student::ShowAllOrder()
{
	Order of;
	if (of.size_ == 0) {
		cout << "无预约记录" << endl;
		system("pause");
		system("cls");
		return;
	}
	for (int i = 1; i <= of.size_; i++) {
		cout << i << "、";
		cout << "预约日期:周" << of.orderdata_[i]["date"] << "\t";
		cout << "时间段:" << (of.orderdata_[i]["interval"] == "1" ? "上午" : "下午") << "\t";
		cout << "学号:" << of.orderdata_[i]["stuid"] << "\t";
		cout << "姓名:" << of.orderdata_[i]["stuname"] << "\t";
		cout << "机房号:" << of.orderdata_[i]["roomid"] << "\t";
		string status = "状态:";
		if (of.orderdata_[i]["status"] == "1") {
			status += "审核中";
		}
		else if (of.orderdata_[i]["status"] == "2") {
			status += "预约成功";
		}
		else if (of.orderdata_[i]["status"] == "-1") {
			status += "预约失败,审核未通过";
		}
		else {
			status += "预约已取消!";
		}
		cout << "预约状态:" << status << endl;
	}
	system("pause");
	system("cls");
}

//取消预约
void Student::CancelOrder()
{
	Order of;
	if (of.size_ == 0) {
		cout << "无预约记录" << endl;
		system("pause");
		system("cls");
		return;
	}
	cout << "审核中或预约成功的记录可以取消,请输入取消的记录" << endl;
	int index = 1;	//第几条记录
	vector<int> v;	//存放在最大容器中的下标编号
	for (int i = 0; i <= of.size_; i++) {
		if (this->id_ == atoi(of.orderdata_[i]["stuid"].c_str())) {
			if (of.orderdata_[i]["status"] == "1" || of.orderdata_[i]["status"] == "2") {
				v.push_back(i);
				cout << index++ << "、";
				cout << "预约日期:周" << of.orderdata_[i]["date"] << "\t";
				cout << "时间段:" << (of.orderdata_[i]["interval"] == "1" ? "上午" : "下午") << "\t";
				cout << "机房号:" << of.orderdata_[i]["roomid"] << "\t";
				string status = "状态:";
				if (of.orderdata_[i]["status"] == "1") {
					status += "审核中!";
				}
				else if (of.orderdata_[i]["status"] == "2") {
					status += "预约成功!";
				}
				cout << status << endl;
			}
		}
	}
	cout << "请输入要取消的记录,0代表返回" << endl;
	int select = 0;
	while (true) {
		cin >> select;
		if (select >= 0 && select <= v.size()) {
			if (select == 0) {
				break;
			}
			else {
				of.orderdata_[v[select - 1]]["status"] = "0";
				of.updateOrder();
				break;
			}
		}
		cout << "输入错误,请重新输入!" << endl;
	}
	system("pause");
	system("cls");
}

教师类

#pragma once
#include <iostream>
#include <string>
#include <vector>
#include "identity.h"
#include "order.h"
#define _CRT_SECURE_NO_WARINGS
using namespace std;

class Teacher : public Identity
{
public:
	Teacher();
	Teacher(int id,string name,string password);
	~Teacher();
	//菜单界面
	virtual void OperMenu();
	//查看所有预约
	void ShowAllOrder();
	//审核预约
	void ExamineOrder();

	int id_ = 0;				//教师编号
};

其源文件如下:

#include "teacher.h"

Teacher::Teacher()
{

}
Teacher::Teacher(int id, string name, string password)
{
	this->id_ = id;
	this->name_ = name;
	this->password_ = password;
}
Teacher::~Teacher()
{

}
//菜单界面
void Teacher::OperMenu()
{
	cout << "欢迎老师" << this->name_ << "登录!" << endl;
	cout << "\t\t-----------------------------------------\n";
	cout << "\t\t|                                        |\n";
	cout << "\t\t|             1.查看所有预约             |\n";
	cout << "\t\t|                                        |\n";
	cout << "\t\t|             2.审核预约                 |\n";
	cout << "\t\t|                                        |\n";
	cout << "\t\t|             0.注销登录                 |\n";
	cout << "\t\t|                                        |\n";
	cout << "\t\t-----------------------------------------\n";
	cout << "请选择您的操作:" << endl;
}
//查看所有预约
void Teacher::ShowAllOrder()
{
	Order of;
	if (of.size_ == 0) {
		cout << "无预约记录" << endl;
		system("pause");
		system("cls");
		return;
	}
	for (int i = 1; i <= of.size_; i++) {
		cout << i << "、";
		cout << "预约日期:周" << of.orderdata_[i]["date"] << "\t";
		cout << "时间段:" << (of.orderdata_[i]["interval"] == "1" ? "上午" : "下午") << "\t";
		cout << "学号:" << of.orderdata_[i]["stuid"] << "\t";
		cout << "姓名:" << of.orderdata_[i]["stuname"] << "\t";
		cout << "机房号:" << of.orderdata_[i]["roomid"] << "\t";
		string status = "状态:";
		if (of.orderdata_[i]["status"] == "1") {
			status += "审核中";
		}
		else if (of.orderdata_[i]["status"] == "2") {
			status += "预约成功";
		}
		else if (of.orderdata_[i]["status"] == "-1") {
			status += "预约失败,审核未通过";
		}
		else {
			status += "预约已取消!";
		}
		cout << "预约状态:" << status << endl;
	}
	system("pause");
	system("cls");
}
//审核预约
void Teacher::ExamineOrder()
{
	Order of;
	if (of.size_ == 0) {
		cout << "无预约记录" << endl;
		system("pause");
		system("cls");
		return;
	}
	vector<int> v;
	int index = 0;
	cout << "待审核的预约记录如下:" << endl;
	for (int i = 1; i <= of.size_; i++) {
		if (of.orderdata_[i]["status"] == "1") {
			v.push_back(i);
			cout << ++index << "、";
			cout << "预约日期:周" << of.orderdata_[i]["date"] << "\t";
			cout << "时间段:" << (of.orderdata_[i]["interval"] == "1" ? "上午" : "下午") << "\t";
			cout << "学号:" << of.orderdata_[i]["stuid"] << "\t";
			cout << "姓名:" << of.orderdata_[i]["stuname"] << "\t";
			cout << "机房号:" << of.orderdata_[i]["roomid"] << "\t";
			string status = "状态:审核中";
			cout << status << endl;
		}
	}
	cout << "请输入审核的预约记录,0代表返回" << endl;
	int select = 0;	//接收用户选择的预约记录
	int ret = 0;	//接收预约结果记录
	while (true) {
		cin >> select;
		if (select >= 0 && select <= v.size()) {
			if (select == 0) {
				break;
			}
			else {
				cout << "请输入审核结果:1.通过\t2.不通过" << endl;
				cin >> ret;
				if (ret == 1) {
					of.orderdata_[v[select - 1]]["status"] = "2";
				}
				else {
					of.orderdata_[v[select - 1]]["status"] = "-1";
				}
				of.updateOrder();	//更新预约记录
				cout << "审核完毕!" << endl;
				break;
			}
		}
		cout << "输入有误,请重新输入!" << endl;
	}
	system("pause");
	system("cls");
}

主函数

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

//管理员菜单
void AdminMenu(Identity* &identity)
{
	int select = 0;
	while (true) {
		//显示管理员菜单
		identity->OperMenu();
		Admin* admin = (Admin*)identity;
		cin >> select;
		switch (select) {
		case 1:			//添加账号
			admin->AddPerson();
			break;
		case 2:			//查看账号
			admin->ShowPerson();
			break;
		case 3:			//查看机房
			admin->ShowComputer();
			break;	
		case 4:			//清空预约
			admin->ClearFile();
			break;
		default:		//注销登录
			delete admin;
			cout << "注销成功!" << endl;
			system("pause");
			system("cls");
			return;
		}
	}
}
//学生菜单
void StudentMenu(Identity* &identity)
{
	int select = 0;
	while (true) {
		//显示学生菜单
		identity->OperMenu();
		Student* student = (Student*)identity;
		cin >> select;
		switch (select) {
		case 1:			//申请预约
			student->ApplyOrder();
			break;
		case 2:			//查看我的预约
			student->ShowMyOrder();
			break;
		case 3:			//查看所有预约
			student->ShowAllOrder();
			break;
		case 4:			//取消预约
			student->CancelOrder();
			break;
		default:		//注销登录
			delete student;
			cout << "注销成功!" << endl;
			system("pause");
			system("cls");
			return;
		}
	}
}
//教师菜单
void TeacherMenu(Identity* &identity)
{
	int select = 0;
	while (true) {
		//显示管理员菜单
		identity->OperMenu();
		Teacher* teacher = (Teacher*)identity;
		cin >> select;
		switch (select) {
		case 1:			//查看所有预约
			teacher->ShowAllOrder();
			break;
		case 2:			//审核预约
			teacher->ExamineOrder();
			break;
		default:		//注销登录
			delete teacher;
			cout << "注销成功!" << endl;
			system("pause");
			system("cls");
			return;
		}
	}
}

//登录函数,参数1为文件名,参数2为登录类型
void LoginIn(string filename, int type)
{
	Identity *identity = NULL;
	ifstream ifs;
	ifs.open(filename, ios::in);
	if (!ifs.is_open()) {
		cout << "文件不存在!" << endl;
		ifs.close();
		return;
	}
	int id = 0;
	string name;
	string password;
	if (type == 1) {
		//学生登录
		cout << "请输入学号:";
		cin >> id;
	}
	else if (type == 2) {
		//教师登录
		cout << "请输入工号:";
		cin >> id;
	}
	cout << "请输入用户名:";
	cin >> name;
	cout << "请输入密码:";
	cin >> password;
	if (type == 1) {
		//学生登录验证
		int fid;
		string fname;
		string fpassword;
		//从文件中读取信息
		while (ifs >> fid && ifs >> fname && ifs >> fpassword) {
			if (fid == id && fname == name && fpassword == password) {
				cout << "验证成功!" << endl;
				system("pause");
				system("cls");
				identity = new Student(id, name, password);
				StudentMenu(identity);		//进入学生子菜单
				return;
			}
		}
	}
	else if (type == 2) {
		//教师登录验证
		int fid;
		string fname;
		string fpassword;
		//从文件中读取信息
		while (ifs >> fid && ifs >> fname && ifs >> fpassword) {
			if (fid == id && fname == name && fpassword == password) {
				cout << "验证成功!" << endl;
				system("pause");
				system("cls");
				identity = new Teacher(id, name, password);
				TeacherMenu(identity);		//进入教师子菜单
				return;
			}
		}
	}
	else if (type == 3) {
		//管理员登录验证
		string fname;
		string fpassword;
		//从文件中读取信息
		while (ifs >> fname && ifs >> fpassword) {
			if (fname == name && fpassword == password) {
				cout << "验证成功!" << endl;
				system("pause");
				system("cls");
				identity = new Admin(name, password);
				AdminMenu(identity);		//进入管理员子菜单
				return;
			}
		}
	}
	cout << "验证登录失败!" << endl;
	system("pause");
	system("cls");
	return;
}


int main()
{
	int select = 0;
	cout << "================  欢迎来到机房预约系统!  ================" << endl;
	while (true) {
		cout << endl << "请输入您的身份:" << endl;
		cout << "\t\t-----------------------------------------\n";
		cout << "\t\t|                                        |\n";
		cout << "\t\t|               1.学生代表               |\n";
		cout << "\t\t|                                        |\n";
		cout << "\t\t|               2.老    师               |\n";
		cout << "\t\t|                                        |\n";
		cout << "\t\t|               3.管 理 员               |\n";
		cout << "\t\t|                                        |\n";
		cout << "\t\t|               0.退    出               |\n";
		cout << "\t\t|                                        |\n";
		cout << "\t\t-----------------------------------------\n";
		cout << "请输入您的选择:";
		cin >> select;
		switch (select) {
		case 1:			//学生
			LoginIn(STUDENT_FILE, 1);
			break;
		case 2:			//老师
			LoginIn(TEACHER_FILE, 2);
			break;
		case 3:			//管理员
			LoginIn(ADMIN_FILE, 3);
			break;
		case 0:			//退出
			cout << "欢迎下次使用!" << endl;
			system("pause");
			system("cls");
			return 0;
		default:
			cout << "输入错误,请重新输入!" << endl;
			system("pause");
			system("cls");
			break;
		}
	}
	system("pause");
	return 0;
}

结尾

需要源码的小伙伴可以联系我!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 黑马机房预约系统是一款用于管理和预约机房资源的系统。该系统可以方便高效地帮助用户进行机房的预约和管理。 首先,该系统提供了一个用户界面,用户可以通过该界面浏览机房的可用时间和预约情况。用户可以根据自己的需要选择合适的时间段进行预约。 其次,系统还提供了预约管理功能。管理员可以登录系统进行机房资源的管理和调度。管理员可以查看所有预约情况,对预约进行审核和处理。如果有冲突或者其他问题,管理员可以通过系统与用户进行沟通和协商。 此外,该系统还提供了提醒功能。系统会在预约时间将近时给用户发送短信或者邮件提醒,确保用户不会忘记约定的使用时间。 黑马机房预约系统的好处是多方面的。首先,它提高了机房资源的利用率,避免了资源的浪费。通过合理的调度和管理,可以确保尽可能多的用户能够享受到机房的使用权。其次,该系统提供了便利的预约和管理功能,方便了用户和管理员的操作,节省了时间和精力。最后,该系统的提醒功能可以避免预约的遗忘,提高了效率和准确性。 总之,黑马机房预约系统是一款方便实用的系统,可以有效管理和预约机房资源,提高资源利用率和用户满意度。 ### 回答2: 黑马机房预约系统是一个方便学生预约机房使用的系统。这个系统主要有以下几个功能: 1. 预约机房:学生可以通过系统预约机房的使用时间。他们可以选择日期和时间段,并在系统中查看机房的实时可用情况。这有助于有效安排机房的使用,避免冲突和浪费。 2. 查看预约记录:学生可以通过系统查看他们的预约记录。这包括他们预约的日期,时间段以及预约成功与否的状态。这一功能方便他们随时了解自己的预约情况以及进行相应的调整。 3. 取消预约:对于一些情况下无法按计划使用机房的学生,他们可以通过系统取消预约。这样可以及时释放机房资源,方便其他学生进行预约。 4. 管理员权限:系统设有管理员权限,负责管理机房资源和学生预约情况。管理员可以查看机房使用情况,审核和确认学生的预约申请。他们还可以处理预约冲突和问题,确保机房资源的最有效利用。 5. 通知功能:系统可以通过短信、邮件等方式通知学生预约情况的变化,以及管理员的审核结果等。这样,学生能及时了解自己的预约状态,管理员也能更方便地与学生进行沟通。 总之,黑马机房预约系统通过有效的预约管理和信息传递,方便了学生对机房的使用,提升了机房资源的利用率。它是一个便捷、高效的工具,为学生和管理员带来了更好的使用体验。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值