机房预订系统(水文)

//3.1 菜单实现

//    在主函数main中添加菜单提示,代码如下:

int main() {
   

	cout << "======================  欢迎来到机房预约系到统  =====================" 
         << endl;
	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 << "输入您的选择: ";

	system("pause");

	return 0;
}


//3.2 搭建接口

//    接受用户的选择,搭建接口
  //  在main中添加代码

int main() {
   

	int select = 0;

	while (true)
	{
   

		cout << "======================  欢迎来到传智播客机房预约系统  =====================" << endl;
		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:  //学生身份
			break;
		case 2:  //老师身份
			break;
		case 3:  //管理员身份
			break;
		case 0:  //退出系统
			break;
		default:
             cout << "输入有误,请重新选择!" << endl;
		    system("pause");
			system("cls");
			break;
		}

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



//4、 退出功能实现
//4.1 退出功能实现

在main函数分支 0 选项中,添加退出程序的代码:

	cout << "欢迎下一次使用"<<endl;
	system("pause");
	return 0;




//5、 创建身份类
//5.1 身份的基类

 //   在整个系统中,有三种身份,分别为:学生代表、老师以及管理员
//    三种身份有其共性也有其特性,因此我们可以将三种身份抽象出一个身份基类identity


#pragma once
#include<iostream>
using namespace std;

//身份抽象类
class Identity
{
   
public:

	//操作菜单
	virtual void operMenu() = 0;

	string m_Name; //用户名
	string m_Pwd;  //密码
};


/*5.2 学生类
5.2.1 功能分析

    学生类主要功能是可以通过类中成员函数,实现预约实验室操作

    学生类中主要功能有:
        显示学生操作的菜单界面
        申请预约
        查看自身预约
        查看所有预约
        取消预约*///5.2.2 类的创建

 

//student.h中添加如下代码:

#pragma once
#include<iostream>
using namespace std;
#include "identity.h"

//学生类
class Student :public Identity
{
   
public:
	//默认构造
	Student();

	//有参构造(学号、姓名、密码)
	Student(int id, string name, string pwd);

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

	//申请预约
	void applyOrder(); 

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

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

	//取消预约
	void cancelOrder();
	
	//学生学号
	int m_Id;

};

//student.cpp中添加如下代码:

#include "student.h"

//默认构造
Student::Student()
{
   
}

//有参构造(学号、姓名、密码)
Student::Student(int id, string name, string pwd)
{
   
}

//菜单界面
void Student::operMenu()
{
   
}

//申请预约
void Student::applyOrder()
{
   

}

//查看我的预约
void Student::showMyOrder()
{
   

}

//查看所有预约
void Student::showAllOrder()
{
   

}

//取消预约
void Student::cancelOrder()
{
   

}

/*5.3 老师类
5.3.1 功能分析

    教师类主要功能是查看学生的预约,并进行审核

    教师类中主要功能有:

        显示教师操作的菜单界面

        查看所有预约

        审核预约

        ​

5.3.2 类的创建

    在头文件以及源文件下创建 teacher.h 和 teacher.cpp文件

teacher.h中添加如下代码:*/

#pragma once
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
#include "identity.h"

class Teacher :public Identity
{
   
public:

	//默认构造
	Teacher();

	//有参构造 (职工编号,姓名,密码)
	Teacher(int empId, string name, string pwd);

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

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

	//审核预约
	void validOrder(); 

	int m_EmpId; //教师编号

};

    teacher.cpp中添加如下代码:

#include"teacher.h"

//默认构造
Teacher::Teacher()
{
   
}

//有参构造 (职工编号,姓名,密码)
Teacher::Teacher(int empId, string name, string pwd)
{
   
}

//菜单界面
void Teacher::operMenu()
{
   
}

//查看所有预约
void Teacher::showAllOrder()
{
   
}

//审核预约
void Teacher::validOrder()
{
   
}

/*5.4 管理员类
5.4.1 功能分析

    管理员类主要功能是对学生和老师账户进行管理,查看机房信息以及清空预约记录

    管理员类中主要功能有:

        显示管理员操作的菜单界面

        添加账号

        查看账号

        查看机房信息

        清空预约记录

        ​

5.4.2 类的创建

    在头文件以及源文件下创建 manager.h 和 manager.cpp文件

manager.h中添加如下代码:*/

#pragma once
#include<iostream>
using namespace std;
#include "identity.h"

class Manager :public Identity
{
   
public:

	//默认构造
	Manager();

	//有参构造  管理员姓名,密码
	Manager(string name, string pwd);

	//选择菜单
	virtual void operMenu();

	//添加账号  
	void addPerson();

	//查看账号
	void showPerson();

	//查看机房信息
	void showComputer();

	//清空预约记录
	void cleanFile();

};

    manager.cpp中添加如下代码:

#include "manager.h"

//默认构造
Manager::Manager()
{
   
}

//有参构造
Manager::Manager(string name, string pwd)
{
   
}

//选择菜单
void Manager::operMenu()
{
   
}

//添加账号  
void Manager::addPerson()
{
   
}

//查看账号
void Manager::showPerson()
{
   
}

//查看机房信息
void Manager::showComputer()
{
   
}

//清空预约记录
void Manager::cleanFile()
{
   
}

6、 登录模块
6.1 全局文件添加

功能描述:

    不同的身份可能会用到不同的文件操作,我们可以将所有的文件名定义到一个全局的文件中
    在头文件中添加 globalFile.h 文件
    并添加如下代码:

#pragma once 

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

并且在同级目录下,创建这几个文件

1548575650130
6.2 登录函数封装

功能描述:

    根据用户的选择,进入不同的身份登录

在预约系统的.cpp文件中添加全局函数 void LoginIn(string fileName, int type)

参数:

    fileName --- 操作的文件名
    type --- 登录的身份 (1代表学生、2代表老师、3代表管理员)

LoginIn中添加如下代码:

#include "globalFile.h"
#include "identity.h"
#include <fstream>
#include <string>


//登录功能
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)
	{
   
		//学生登录验证
	}
	else if (type == 2)
	{
   
		//教师登录验证
	}
	else if(type == 3)
	{
   
		//管理员登录验证
	}
	
	cout << "验证登录失败!" << endl;

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

    在main函数的不同分支中,填入不同的登录接口


6.3 学生登录实现





		//学生登录验证
		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);
				
				return;
			}
		}




在Login函数的教师分支中加入如下代码,验证教师身份

		//教师登录验证
		int fId;
		string fName;
		string fPwd;
		whil
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值