学生住宿管理系统(小系统C++)

功能

(1)学生信息包括:姓名、学号、年龄、性别、学院、年级等

(2)宿舍信息包括:宿舍编号、宿舍楼名、楼层号、宿舍类型(二人间、四人间、六 人间、八人间) 、收费标准等。

(3)住宿信息包括:学生、宿舍、入住时间、是否欠费等。

(4)完成以下的操作:学生信息和宿舍信息的添加、修改、浏览、删除和查询。 (5)完成以下的操作:学生入住、缴费;住宿信息浏览、学生住宿信息查询、宿舍住 宿信息浏览与查询。 2、提示: (1)增加必要的数据成员、成员函数或类; (2)对象指针(住宿信息类的对象指针成员可以指向相关的宿舍、对象指针数组成员可 以表示该宿舍的学生们)

代码:

#include 
#include 
using namespace std;

//定义学生和宿舍的最大数量
#define MAXSTU 50
#define MAXDOR 20

//定义学生类
class Student
{
private:
	int mXuehao;    //学号
	char* mName;    //名字
	int mAge;       //年龄
	char mSex;      //性别
	char* mPartment;//学院
	int mGrade;     //年级
public:
	Student(){mName = 0;mPartment = 0;}
	Student(int id,const char* name,int age,char sex,const char* par,int grade)
	{
		mXuehao = id;
		mName = new char[strlen(name)+1];
		memcpy(mName,name,strlen(name));
		mName[strlen(name)] = '\0';
		mAge = age;
		mSex = toupper(sex);
		mPartment = new char[strlen(par)+1];
		memcpy(mPartment,par,strlen(par));
		mPartment[strlen(par)] = '\0';
		mGrade = grade;
	}
	~Student()
	{
		if (mName)
		{
			delete[] mName;
			mName = 0;
		}
		if (mPartment)
		{
			delete[] mPartment;
			mPartment = 0;
		}
	}
	//设置类属性
	void setId(int id){mXuehao = id;}
	void setName(const char* name)
	{
		if (mName != 0)
		{
			delete[] mName;
			mName = 0;
		}
		mName = new char[strlen(name)+1];
		memcpy(mName,name,strlen(name));
		mName[strlen(name)] = '\0';
	}
	void setSex(char sex){mSex = toupper(sex);}
	void setAge(int age){mAge = age;}
	void setPartment(const char* par)
	{
		if(mPartment)
			delete []mPartment;
		mPartment = new char[strlen(par)+1];
		memcpy(mPartment,par,strlen(par));
		mPartment[strlen(par)] = '\0';
	}
	void setGrade(int g){mGrade = g;}
	//获取类属性
	int getId(){return mXuehao;}
	char* getName(){return mName;}
	char getSex(){return mSex;}
	int getAge(){return mAge;}
	char* getPartment(){return mPartment;}
	int getGrade(){return mGrade;}
	void display()
	{
		cout.setf(ios::left);//设置左对齐
		cout << mXuehao << " " ;
		cout.fill(' ');  //设置不足位填充方式
		cout.width(10);  //设置宽度,只对下一条有作用
		cout << mName ;
		cout << " " << mSex << " ";
		cout << mAge << " " ;
		cout.fill(' ');
		cout.width(20);
		cout<< mPartment ;
		cout<< " " << mGrade << endl;
		cout.unsetf(ios::left); //取消左对齐
	}
};

//定义宿舍类型
enum EDomType
{
	e_dorm_two=1,
	e_dorm_four,
	e_dorm_six,
	e_dorm_eight
};

//定义宿舍类
class Dormatory
{
private:
	int mSusheId;   //宿舍号
	char* mDorName; //宿舍楼名
	int mLayer;     //楼层号
	EDomType mEtype;//类型
	int mPrice;     //价格
public:
	Dormatory(){mDorName = 0;}
	Dormatory(int id,const char* name,int layer,EDomType e,int price)
	{
		mSusheId = id;
		mDorName = new char[strlen(name)+1];
		memcpy(mDorName,name,strlen(name));
		mDorName[strlen(name)] = '\0';
		mLayer = layer;
		mEtype = e;
		mPrice = price;
	}

	~Dormatory()
	{
		if(mDorName)
		{
			delete[] mDorName;
			mDorName = 0;
		}
	}
	//设置类属性
	void setId(int id){mSusheId = id;}
	void setName(const char* name)
	{
		if(mDorName) delete[] mDorName;
		mDorName = new char[strlen(name)+1];
		memcpy(mDorName,name,strlen(name));
		mDorName[strlen(name)] = '\0';
	}
	void setLayer(int layer){mLayer = layer;}
	void setDormType(EDomType e){mEtype = e;}
	void setPrice(int p){mPrice = p;}
	
	//获取类属性
	int getId(){return mSusheId;}
	char* getName(){return mDorName;}
	int getLayer(){return mLayer;}
	EDomType getType(){return mEtype;}
	int getPrice(){return mPrice;}
	void display()
	{
		cout.setf(ios::left);
		cout<< mSusheId << " ";
		cout.fill(' ');
		cout.width(10);  //名字最多5个汉子或者10个英文字符
		cout << mDorName;
		cout << " " << mLayer << " ";
		if(e_dorm_two == mEtype)
			cout << "二人间" ;
		else if(e_dorm_four == mEtype)
			cout << "四人间" ;
		else if(e_dorm_six == mEtype)
			cout << "六人间" ;
		else
			cout << "八人间" ;
		cout << " " << mPrice << endl;
		cout.unsetf(ios::left);
	}
};
//定义时间类
struct Date 
{
	int year;
	int month;
	int day;
};
//住宿信息
class HomeInfo
{
private:
	Dormatory* mDormatory;   //宿舍对象指针
	Student* mStu[8];        //学生指针数组
	bool mbqf[8];            //是否欠费,true欠费,否则不欠费
	Date mHomeDate[8];       //入住时间

	int mCurrentNmb;//当前已入住人数
	char mDormSex;  //当前宿舍的性别
public:
	HomeInfo()
	{
		for (int i =0;i< 8;i++)
		{
			mStu[i] = 0;
			mbqf[i] = true;
		}
		mDormatory = 0;
		mCurrentNmb = 0;
		mDormSex = 'n';  //表示该宿舍尚未分配
	}
	
	void setDormatory(Dormatory* p){mDormatory = p;}
	void setSex(char sex){mDormSex = sex;}
	Dormatory* getDormatory(){return mDormatory;}
	char getSex(){return mDormSex;}
	int getCurrentNmb(){return mCurrentNmb;}
	//查看某个学生是否在该房间
	bool isIn(Student* stu)
	{
		for (int i=0;igetType() && mCurrentNmb == 8)
			return true;
		else if(e_dorm_six == mDormatory->getType() && mCurrentNmb == 6)
			return true;
		else if(e_dorm_four == mDormatory->getType() && mCurrentNmb == 4)
			return true;
		else if(e_dorm_two == mDormatory->getType() && mCurrentNmb == 2)
			return true;
		return false;
	}
	//办理入住
	bool Home(Student *stu,Date d)
	{
		if(isFull())
		{
			cout << "宿舍已满,请重新选择宿舍!!!"<< endl;
			return false;
		}
		if(mDormSex == 'n')
			mDormSex = stu->getSex();
		mStu[mCurrentNmb] = stu;
		mHomeDate[mCurrentNmb] = d;
		mCurrentNmb++;
		cout << "入住成功!宿舍:" << mDormatory->getName() << " " << mDormatory->getLayer() << " " << mDormatory->getId() << endl;
		return true;
	}
	//付费
	void pay(Student *stu)
	{
		for (int i=0;idisplay();
		for (int i =0;i>";
			mStu[i]->display();
		}
	}
};

//转换类型
EDomType getDormType(int type)
{
	if(1== type)
		return e_dorm_two;
	else if(2 == type)
		return e_dorm_four;
	else if(3== type)
		return e_dorm_six;
	else 
		return e_dorm_eight;
}



//1添加学生
void AddStudent(Student* allStudents[],int &nRealStu)
{
	bool bgo = true;
	int id;
	char name[20]={0};
	char sex;
	int age;
	char par[30]={0};
	int grade;
	char ch;
	while(bgo)
	{
		system("cls");
		cout << "请输入学生学号:";
		
		while(1)
		{
			id = 0;
			cin >> id;
			if(id <= 0)
			{
				cout << "输入不合法,请重新输入";
				if (cin.fail())
				{
					cin.clear();
					cin.sync();
				}
			}
			else
				break;
		}
		
		
		cout << "请输入学生姓名:" ;
		memset(name,0,20);
		cin >> name;
		cout << "请输入学生性别:";
		cin >> sex;
		cout << "请输入学生年龄:";
		while(1)
		{
			age = 0;
			cin >> age;
			if (age <= 0)
			{
				cout << "输入不合法,请重新输入";
				if (cin.fail())
				{
					cin.clear();
					cin.sync();
				}
			}else
				break;
		}
		
		cout << "请输入学院:";
		memset(par,0,30);
		cin >> par;
		cout << "请输入年级:";
		while(1)
		{
			grade = 0;
			cin >> grade;
			if (grade <= 0)
			{
				cout << "输入不合法,请重新输入";
				if (cin.fail())
				{
					cin.clear();
					cin.sync();
				}
			}else
				break;
		}
		
		Student* stu = new Student(id,name,age,sex,par,grade);
		allStudents[nRealStu] = stu;
		nRealStu++;
		cout << "学生添加成功!" << endl;
		cout << "是否继续添加(Y/N)?" ;
		while(true)
		{
			if (cin.fail())
			{
				cin.clear();
				cin.sync();
			}
			cin >> ch;
			
			if (ch == 'N' || ch == 'n')
			{
				bgo = false;
				break;
			}else if(ch == 'Y' || ch == 'y')
			{
				break;
			}
		}
	}
	
	system("pause");
}

//2修改学生信息
void ModStudent(Student* allStudents[],int nRealStu)
{
	int id;
	char name[20]={0};
	char sex;
	int age;
	char par[30]={0};
	int grade;
	Student* stu = 0;
	system("cls");
	cout << "请输入需要修改信息的学生学号:";
	while(1)
	{
		id = 0;
		cin >> id;
		if(id > 0)
			break;
		if (cin.fail())
		{
			cin.clear();
			cin.sync();
		}
		cout << "输入不合法,请重新输入" << endl;
	}
	

	for (int i =0;i< nRealStu;i++)
	{
		if(allStudents[i]->getId() == id)
		{
			stu = allStudents[i];
			cout << "找到学生信息如下:" << endl;
			cout << "姓名:" << stu->getName() << endl;;
			cout << "性别:" << stu->getSex() << endl;
			cout << "年龄:" << stu->getAge() << endl;;
			cout << "学院:" << stu->getPartment() << endl;
			cout << "年级:"<< stu->getGrade() << endl;

			cout << "请输入需要修改的信息:" << endl;

			cout << "请输入学生姓名:";
			cin >> name;
			cout << "请输入学生性别:";
			cin >> sex;
			cout << "请输入学生年龄:";
			cin >> age;
			cout << "请输入学院:";
			cin >> par;
			cout << "请输入年级:";
			cin >> grade;

			allStudents[i]->setName(name);
			allStudents[i]->setSex(sex);
			allStudents[i]->setAge(age);
			allStudents[i]->setPartment(par);
			allStudents[i]->setGrade(grade);

			cout << "学生信息修改成功!" << endl;
			break;
		}
	}
	if(stu==0)
		cout << "未找到该学生信息!" << endl;
	
	system("pause");
}

//3删除学生信息
void DeleteStudent(Student* allStudents[],int &nRealStu,HomeInfo allInfo[],int nRealDorm)
{
	int id;
	Student* stu = 0;
	system("cls");
	cout << "请输入需要删除信息的学生学号:";
	while(1)
	{
		id = 0;
		cin >> id;
		if(id > 0)
			break;
		if (cin.fail())
		{
			cin.clear();
			cin.sync();
		}
		cout << "输入不合法,请重新输入" << endl;
	}

	for (int i =0;i< nRealStu;i++)
	{
		if(allStudents[i]->getId() == id)
		{
			stu = allStudents[i];
			//删除学生
			nRealStu -=1;
			//数组元素前移
			for (int j = i;j< nRealStu;j++)
			{
				allStudents[j] = allStudents[j+1];
			}
			cout << "删除成功!!" << endl;
			break;
		}
	}
	if (stu == 0)
	{
		cout << "未找到该学生信息" << endl;
	}else
	{
		//从住宿信息中删除该学生信息
		for (int i=0;i< nRealDorm;i++)
		{
			allInfo[i].Leave(stu);
		}
		delete stu;
		stu = 0;
	}
	system("pause");
}

//4.浏览所有学生信息
void ShowAllStudents(Student* allStudents[],int nRealStu)
{
	system("cls");
	cout << "学生信息如下:" << endl;
	for (int i =0;i< nRealStu;i++)
	{
		allStudents[i]->display();
	}
	system("pause");
}
//5.查询学生信息
void FindStudents(Student* allStudents[],int nRealStu)
{
	int i,opt;
	int id;
	char tmp[40] = {0};
	bool bgo = true;
	bool isfind = false;
	char ch;
	while(bgo)
	{

		system("cls");
		cout << "1.按学号查询" << endl;
		cout << "2.按姓名查询" << endl;
		cin >> opt;
		switch(opt)
		{
		case 1:
			cout << "请输入需要查询的学号:" << endl;
			while(1)
			{
				cin >> id;
				if(id > 0)break;
				else
				{
					if (cin.fail())
					{
						cin.clear();
						cin.sync();
					}
					cout << "输入不合法,请重新输入" << endl;
				}
			}
			
			for (i=0;igetId() == id)
				{
					allStudents[i]->display();
					break;
				}
			}
			if (i == nRealStu)
			{
				cout << "未找到学号为"<< id <<"的学生信息..." << endl;
			}
			
			break;
		case 2:
			cout << "请输入需要查询的姓名:" << endl;
			memset(tmp,0,40);
			cin >> tmp;
			isfind = false;
			for (i=0;igetName(),tmp) == 0)
				{
					isfind = true;
					allStudents[i]->display();
				}
			}
			if (!isfind)
			{
				cout << "未找到姓名为"<< tmp <<"的学生信息..." << endl;
			}
			break;
		}

		cout << "是否继续查询(Y/N)?";
		while(true)
		{
			if (cin.fail())
			{
				cin.clear();
				cin.sync();
			}
			cin >> ch;
			if (ch == 'n' || ch == 'N')
			{
				bgo = false;
				break;
			}else if(ch == 'y'||ch =='Y')
			{
				break;
			}
		}
	}
	system("pause");
}

//6.添加宿舍
void AddDormatory(Dormatory* allDormatory[],int &nRealDorm,HomeInfo allInfo[])
{
	int id;
	char name[20]={0};
	int layer;
	int type;
	int price;
	char ch;
	bool bgo = true;
	while(bgo)
	{
		system("cls");
		cout << "请输入宿舍编号:";
		while(1)
		{
			id = 0;
			cin >> id;
			if(id > 0) break;
			else
			{
				if (cin.fail())
				{
					cin.clear();
					cin.sync();
				}
				cout << "输入不合法,请重新输入" << endl;
			}
		}
	
		cout << "请输入宿舍名称:";
		cin >> name;
		cout << "请输入楼层号:";
		cin >> layer;
		cout << "请输入宿舍类型(1.二人间 2.四人间 3.六人间 4.八人间)";
		cin >> type;
		cout << "请输入价格:";
		cin >> price;
		Dormatory* st = new Dormatory(id,name,layer,getDormType(type),price);
		allDormatory[nRealDorm] = st;

		//添加入住信息
		allInfo[nRealDorm].setDormatory(st);

		nRealDorm += 1;
		cout << "宿舍添加成功!!" << endl;
		cout << "是否继续添加(Y/N)?";
		while(true)
		{
			cin >> ch;
			if(ch == 'y' || ch == 'Y')
				break;
			else if(ch == 'N' || ch == 'n')
			{
				bgo = false;
				break;
			}
		}
	}
	system("pause");
}
//7.修改宿舍信息
void ModDormatory(Dormatory* allDormatory[],int nRealDorm)
{
	int id;
	int i;
	char name[20]={0};
	int layer;
	int type;
	int price;
	system("cls");
	cout << "请输入要修改信息的宿舍编号:";
	while(1)
	{
		id = 0;
		cin >> id;
		if (id > 0)break;
		else
		{
			if (cin.fail())
			{
				cin.clear();
				cin.sync();
			}
			cout << "输入不合法,请重新输入" << endl;
		}
	}

	for (i=0;igetId() == id)
		{
			cout << "该宿舍当前信息如下:" << endl;
			allDormatory[i]->display();
			cout << "-------------------------" << endl;
			cout << "请输入宿舍名称:";
			cin >> name;
			cout << "请输入楼层号:";
			cin >> layer;
			cout << "请输入宿舍类型(1.二人间 2.四人间 3.六人间 4.八人间)";
			cin >> type;
			cout << "请输入价格:";
			cin >> price;
			allDormatory[i]->setName(name);
			allDormatory[i]->setLayer(layer);
			allDormatory[i]->setDormType(getDormType(type));
			allDormatory[i]->setPrice(price);
			cout << "宿舍信息修改成功!!"<< endl;
			break;
		}
	}
	system("pause");
}
//8.删除宿舍信息
void DeleteDormatory(Dormatory* allDormatory[],int &nRealDorm,HomeInfo allInfo[])
{
	int i,j,id;
	bool isfind = false;
	Dormatory* dor = 0;
	system("cls");
	cout << "请输入需要删除的宿舍号:";
	while(1)
	{
		id = 0;
		cin >> id;
		if (id > 0)break;
		else
		{
			if (cin.fail())
			{
				cin.clear();
				cin.sync();
			}
			cout << "输入不合法,请重新输入" << endl;
		}
	}
	for (i=0;igetId() == id)
		{
			dor = allDormatory[i];
			//数组前移
			for (j = i;jdisplay();
	}
	system("pause");
}
//10.查询宿舍信息
void FindDormatory(Dormatory* allDormatory[],int nRealDorm)
{
	int id,i;
	char tmp[30]={0};
	char ch;
	int opt;
	bool isfind = false;
	bool bgo = true;
	while(bgo)
	{
		system("cls");
		cout << "1.根据宿舍编号查询" << endl;
		cout << "2.根据宿舍名查询" << endl;
		cout << "3.根据楼层号查询" << endl;
		cout << "4.根据宿舍类型查询" << endl;
		cin >> opt;
		switch(opt)
		{
		case 1:
			cout << "请输入宿舍编号:";
			cin >> id;
			for (i=0;igetId() == id)
				{
					allDormatory[i]->display();
					break;
				}
			}
			if (i == nRealDorm)
			{
				cout << "未找到是宿舍编号为" << id << "的宿舍信息" << endl;
			}
			break;
		case 2:
			cout << "请输入宿舍名:";
			cin >> tmp;
			isfind = false;
			for (i=0;igetName(),tmp) == 0)
				{
					allDormatory[i]->display();
					isfind = true;
				}
			}
			if (!isfind)
			{
				cout << "未找到是宿舍名为" << tmp << "的宿舍信息" << endl;
			}
			break;
		case 3:
			cout << "请输入楼层号:";
			cin >> id;
			isfind = false;
			for (i=0;igetLayer() == id)
				{
					allDormatory[i]->display();
					isfind = true;
				}
			}
			if (!isfind)
			{
				cout << "未找到是楼层号为" << id << "的宿舍信息" << endl;
			}
			break;
		case 4:
			cout << "请输入宿舍类型(1.二人间 2.四人间 3.六人间 4.八人间):";
			cin >> id;
			isfind = false;
			for (i=0;igetType() == getDormType(id))
				{
					allDormatory[i]->display();
					isfind = true;
				}
			}
			if (!isfind)
			{
				if(1 == id)
					cout << "未找到是房间类型为二人间的宿舍信息" << endl;
				else if(2 == id)
					cout << "未找到是房间类型为四人间的宿舍信息" << endl;
				else if(3 == id)
					cout << "未找到是房间类型为六人间的宿舍信息" << endl;
				else 
					cout << "未找到是房间类型为八人间的宿舍信息" << endl;
			}
			break;
		}
	
		cout << "是否继续查询(Y/N)?" << endl;
		while(true)
		{
			cin >> ch;
			if(ch == 'y' || ch =='Y')
				break;
			else if(ch == 'n' || ch == 'N')
			{
				bgo = false;
				break;
			}

		}
	}
	system("pause");
}

//获取可用的宿舍-功能11调用
int GetDormatory(Student* stu,HomeInfo allinfo[],int nRealNmb)
{
	int i = 0;
	//先找是否有未住满的同性别宿舍
	for (i=0;igetSex()) && (!allinfo[i].isFull()) )
		{
			return i;
		}
	}
	//没有已分配的宿舍,则从未分配性别的宿舍中找一个
	for (i=0;i> id;
		//查找学生信息
		stu = 0;
		for (int i = 0;igetId()==id)
			{
				stu = allStudents[i];
				break;
			}
		}
		if (stu == 0)
		{
			cout << "未找到该学号的学生"<< endl;
		}else
		{
			//判断学生是否已经入住
			bool isIn = false;
			for (int i=0;idisplay();
					break;
				}
			}
			//如果没有入住,则办理入住
			if (!isIn)
			{
				int index = GetDormatory(stu,allInfo,nRealDorm);
				if(index == -1)
				{
					cout << "没有宿舍可供分配" << endl;
				}else
				{
					cout << "请输入入住年、月、日:";
					Date dd;
					cin >> dd.year >> dd.month >> dd.day;
					allInfo[index].Home(stu,dd);
				}
			}
		}

		cout << "是否继续办理入住(Y/N)?";
		while(1)
		{
			cin >> ch;
			if(ch == 'y' || ch == 'Y')
				break;
			else if(ch =='n' || ch == 'N')
			{
				bgo = false;
				break;
			}
		}
	}//while end
	system("pause");
}

//12学生缴费
void StudentPay(Student* allStudents[],int nRealStu,HomeInfo allInfo[],int nRealDorm)
{
	int id;
	bool bgo = true;
	Student* stu = 0;
	char ch;
	while(bgo)
	{
		system("cls");
		cout << "请输入要缴费的学生学号:";
		cin >> id;
		//查找学生信息
		stu = 0;
		for (int i = 0;igetId()==id)
			{
				stu = allStudents[i];
				break;
			}
		}
		if (stu == 0)
		{
			cout << "未找到该学号的学生"<< endl;
		}else
		{
			//查找该学生的入住信息
			int i = 0;
			for (i=0;i< nRealDorm;i++)
			{
				if (allInfo[i].isIn(stu))
				{
					if(allInfo[i].isPayed(stu))
					{
						cout << "该学生已经付费" << endl;
						break;
					}else
					{
						allInfo[i].pay(stu);
						break;
					}
				}
			}
			if (i == nRealDorm)
			{
				cout << "该学生尚未办理入住,请先办理入住" << endl;
			}
		}

		cout << "是否继续办理缴费(Y/N)?";
		while(1)
		{
			cin >> ch;
			if(ch == 'y' || ch == 'Y')
				break;
			else if(ch =='n' || ch == 'N')
			{
				bgo = false;
				break;
			}
		}
	}
	system("pause");
}
//13住宿信息浏览
void ShowHomeInfo(HomeInfo allInfo[],int nRealDorm)
{
	int i;
	system("cls");
	cout << "入住信息如下:" <> opt;
		int id;
		char tmp[30]={0};
		switch(opt)
		{
		case 1:
			cout << "请输入学号:";
			cin >> id;
			for (i=0;igetId() == id)
				{
					stu = allStudents[i];
					break;
				}
			}
			if(stu == 0)
				cout << "未找到该学号的学生" << endl;
			else
			{
				for (i=0;idisplay();
						break;
					}
				}
			}
			break;
		case 2:
			cout << "请输入姓名:";
			cin >> tmp;
			for (i=0;igetName(),tmp) == 0)
				{
					stu = allStudents[i];
					
					for (j=0;jdisplay();
							break;
						}
					}
					//可能存在重名的学生,所以此处不退出循环
				}
			}
			if(stu == 0)
				cout << "未找到该学号的学生" << endl;
			
			break;
		}
		cout << "是否继续查询(Y/N)?";
		while(1)
		{
			cin >> ch;
			if(ch == 'y' || ch == 'Y')
				break;
			else if(ch =='n' || ch == 'N')
			{
				bgo = false;
				break;
			}
		}
	}
	system("pause");
}
//15宿舍入住信息查询
void FindDormInfo(HomeInfo allInfo[],int nRealDorm)
{
	int i;
	bool bgo = true;
	int id;
	char ch;
	while(bgo)
	{
		system("cls");
		cout << "请输入需要查询的宿舍编号:"<< endl;
		cin >> id;
		for (i=0;i< nRealDorm;i++)
		{
			if (allInfo[i].getDormatory()->getId() == id)
			{
				allInfo[i].display();
			}
		}

		cout << "是否继续查询(Y/N)?";
		while(1)
		{
			cin >> ch;
			if(ch == 'y' || ch == 'Y')
				break;
			else if(ch =='n' || ch == 'N')
			{
				bgo = false;
				break;
			}
		}
	}
	system("pause");
}

int main()
{
	Student* allStudents[MAXSTU];   //存储所有学生信息
	int nRealStu = 0;               //当前实际学生数量
	Dormatory* allDormatory[MAXDOR];//保存所有宿舍信息
	int nRealDorm = 0;              //当前实际宿舍数量
	HomeInfo allInfo[MAXDOR];       //保存所有入住信息

	int opt;
	bool bgo = true;
	while(bgo)
	{
		system("cls");
		cout << "--------------学生住宿信息管理系统---------------"<< endl;
		cout << "|    1.添加学生                                 |"<< endl;
		cout << "|    2.修改学生信息                             |"<< endl;
		cout << "|    3.删除学生                                 |"<< endl;
		cout << "|    4.浏览所有学生信息                         |"<< endl;
		cout << "|    5.查询学生信息                             |"<< endl;
		cout << "|    6.添加宿舍                                 |"<< endl;
		cout << "|    7.修改宿舍信息                             |"<< endl;
		cout << "|    8.删除宿舍                                 |"<< endl;
		cout << "|    9.浏览所有宿舍信息                         |"<< endl;
		cout << "|    10.查询宿舍信息                            |"<< endl;
		cout << "|    11.学生入住                                |"<< endl;
		cout << "|    12.学生缴费                                |"<< endl;
		cout << "|    13.住宿信息浏览                            |"<< endl;
		cout << "|    14.学生入住信息查询                        |"<< endl;
		cout << "|    15.宿舍入住信息查询                        |"<< endl;
		cout << "|    0.退出系统                                 |"<< endl;
		cout << "-------------------------------------------------"<< endl;
		cin >> opt;
		switch(opt)
		{
		case 0:
			bgo = false;
			break;
		case 1:
			//添加学生
			AddStudent(allStudents,nRealStu);
			break;
		case 2:
			//修改学生信息
			ModStudent(allStudents,nRealStu);
			break;
		case 3:
			//删除学生
			DeleteStudent(allStudents,nRealStu,allInfo,nRealDorm);
			break;
		case 4:
			//浏览所有学生信息
			ShowAllStudents(allStudents,nRealStu);
			break;
		case 5:
			//查询学生信息
			FindStudents(allStudents,nRealStu);
			break;
		case 6:
			//添加宿舍信息
			AddDormatory(allDormatory,nRealDorm,allInfo);
			break;
		case 7:
			//修改宿舍信息
			ModDormatory(allDormatory,nRealDorm);
			break;
		case 8:
			//删除宿舍信息
			DeleteDormatory(allDormatory,nRealDorm,allInfo);
			break;
		case 9:
			//浏览所有宿舍信息
			ShowAllDormatory(allDormatory,nRealDorm);
			break;
		case 10:
			//查询宿舍信息
			FindDormatory(allDormatory,nRealDorm);
			break;
		case 11:
			//学生入住
			StudentIn(allStudents,nRealStu,allDormatory,nRealDorm,allInfo);
			break;
		case 12:
			//学生缴费
			StudentPay(allStudents,nRealStu,allInfo,nRealDorm);
			break;
		case 13:
			//住宿信息浏览
			ShowHomeInfo(allInfo,nRealDorm);
			break;
		case 14:
			//学生入住信息查询
			FindStudent(allStudents,nRealStu,allInfo,nRealDorm);
			break;
		case 15:
			//宿舍入住信息查询
			FindDormInfo(allInfo,nRealDorm);
			break;
		}
	}
	return 0;
}

你可能感兴趣的:(C++,小系统,c++)