⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 roommanage.cpp

📁 命令行模式下的简单宾馆管理系统..各种基本功能齐全..属于新人练习作品..hotel manager..
💻 CPP
字号:
/*
 * File: roommanage.cpp
 * --------------
 * This file implements the roommanage.h interface. 
 */


#include "roommanage.h"

/* Implementation */

RoomManage::RoomManage() //read the data file to initialize the Hotel // not used 
{
	numOfRooms=0;
	allRoomList=new (struct AllRoomList);
	if (allRoomList == NULL) Error("");
	else {
		allRoomList->curRoom=NULL;
		allRoomList->next=NULL;
	}
}
void RoomManage::SetNumOfRooms( int num )
{
	numOfRooms=num;
}
void RoomManage::SetNumOfAccounts( int num )
{
	numOfAccounts=num;
}
int RoomManage::GetNumOfRooms()
{
	return numOfRooms;
}
int RoomManage::GetNumOfAccounts()
{
	return numOfAccounts;
}
/*
void RoomManage::SetAllRoomList()	//add
{}
void RoomManage::SetGuestInHotel()	//add
{}
*/
void RoomManage::AddRoom( Room *p )
{
	struct AllRoomList *temp,*newp;
	temp=allRoomList;
	newp=new (struct AllRoomList);
	if (newp == NULL) {Error("");return;}
	while (temp->next != NULL)temp=temp->next;
	temp->next=newp;
	newp->curRoom=p;
	newp->next=NULL;
	numOfRooms++;
}
bool RoomManage::DeleteRoom( Room *room )
{
	struct AllRoomList *p,*temp;
	p=allRoomList->next;
	temp=allRoomList;
	while (p != NULL && p->curRoom != room) {temp=p;p=p->next;}
	if (p == NULL) {Error("Not Found this Account~");return false;}
	temp->next=p->next;
	delete p;
	numOfRooms--;
	return true;
}
/*
void RoomManage::AddGuest( Account *p )
{
	struct AccountList *newp,*temp;
	temp=guestInHotel;
	newp=new (struct AccountList);
	if (newp == NULL) {Error("");return;}
	while (temp->next != NULL) temp=temp->next;
	temp->next=newp;
	newp->curAccount=p;
	newp->next=NULL;
	numOfAccounts++;
}
void RoomManage::DeleteGuest( Account *p )
{
	struct AccountList *temp,*pp;
	temp=guestInHotel->next;
	pp=guestInHotel;
	while (temp != NULL && temp->curAccount != p) {pp=temp;temp=temp->next;}
	if (temp == NULL ){Error("Not Found this Account~");return;}
	pp->next=temp->next;
	delete temp;
	numOfAccounts--;
}
*/
Room *RoomManage::GetRoom( int num )
{
	struct AllRoomList *p;
	p=allRoomList->next;
	while (p != NULL && p->curRoom->GetRoomNum() != num ) p=p->next;
	if (p == NULL) return NULL;
	return p->curRoom;
}
/*
Account *RoomManage::GetGuest( Account *p )
{
	struct AccountList *temp;
	temp=guestInHotel->next;
	while (temp != NULL && temp->curAccount != p) temp=temp->next;
	if (temp == NULL) return NULL;
	return temp->curAccount;
}
	//struct AllRoomList *GetAllRoomList();
	//struct AccountList *GetGuestInHotel();
	//void DisplayAvailableRoomBrief();	//only display the available rooms' num ,type,price in a list..to choose..
	//void DisplayOneRoomInfo();	//display the room's all detail..
	//void AddFee( Account *, int );
	//void CheckIn( Room *, Account *);
	//void CheckOut( Room *, Account *);

void RoomManage::ChangeRoomState( Room *p, RoomState state )
{
	p->SetRoomState(state);
}
*/
void RoomManage::PrintRoomList()
{
	struct AllRoomList *p=allRoomList->next;
	while (p != NULL){
		p->curRoom->PrintInfoBrief();
		p=p->next;
	}
}
void RoomManage::PrintRoomStateList( RoomState state )	//add
{
	struct AllRoomList *p=allRoomList->next;
	while (p != NULL){
		if (p->curRoom->GetRoomState() == state) p->curRoom->PrintInfoBrief();
		p=p->next;
	}
}
void RoomManage::PrintRoomInfo( Room *p )
{
	p->PrintInfo();
}
void RoomManage::WriteToFile(ofstream *fout)///
{
	*fout << "<ROOMMANAGE>" << endl << numOfRooms << endl;
	struct AllRoomList *tempList = allRoomList->next;
	while (tempList != NULL)
	{
		tempList->curRoom->WriteToFile(fout);
		tempList = tempList->next;
	}
}
void RoomManage::ReadFromFile(ifstream *fin)///
{
	string temp_s;
	int num;
	*fin >> temp_s;
	*fin >> num;
	//allRoomList = NULL;
	for (int i = 0; i < num; i++)
	{
		Room *q = new Room;
		if (q == NULL) {Error("");return ;}
		q->ReadFromFile(fin);
		AddRoom(q);
	}
}
void RoomManage::CleanAllRoom()
{
	struct AllRoomList *p,*temp;
	p=allRoomList->next;
	temp=allRoomList;
	while (p != NULL){
		temp=p->next;
		DeleteRoom(p->curRoom);
		p=temp;
	}
	numOfRooms=0;
}
RoomManage::~RoomManage()
{
	CleanAllRoom();
	struct AllRoomList *p=allRoomList;
	while (p->next != NULL){
		allRoomList=allRoomList->next;
		delete p;
		p=allRoomList;
	}
	delete p;
}

/*
 * Function: NewRoom()
 * Usage: *Room=*Room();
 * ---------------------------
 * This function allow the user to create a new room
 * by entering all the room info,
 * and returns the pointer of the new room.
 */

Room *NewRoom()
{
	string t;
	int tt;
	Room *curRoom=new Room;
	if (curRoom == NULL) {Error("");return NULL;}
	while (1){
		cout<<"Please input RoomNum :";
		curRoom->SetRoomNum(GetInt());
		cout<<"Please input RoomType(1-Single 2-Double 3-Triple 4-Suite):";
		tt=GetInt();
		while(tt < 1 || tt > 4) {cout<<"Input must be '1' or '2' or '3' or '4' ";tt=GetInt();}
		curRoom->SetRoomType(RoomType(tt-1));
		cout<<"Please input Room Price:";
		curRoom->SetRoomPrice(GetInt());
		cout<<"Please inpput Room Charging Hours(h) :";
		curRoom->SetChargingHours(GetInt());
		cout<<"=======The New Room Info====="<<endl;
		curRoom->PrintInfo();
		cout<<"Is it Correct?(y/n):";
		char com=GetYesNo();
		if (com == 'y') {
			cout<<"Add Room Success~"<<endl;
			cout<<"Num:"<<curRoom->GetRoomNum()<<endl;
			return curRoom;
		}
		cout<<"Please Input the Room Info Again..:"<<endl;
	}	
	return curRoom;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -