上
因此,我被任命是创建基本的酒店管理系统。虽然我对工作总体上满意,但我已经意识到,在函数用户()输入超过2个数据之后,在start()之后选择break()将以某种方式调用update()函数,而应将其退出程序。我已经包含了整个代码,因为我没有确切的想法出现在哪里。请帮助
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <fstream>
#include<conio.h>
#include<stdio.h>
using namespace std;
void start();
void admin();
void user();
void update();
void display();
void input();
void data();
void header();
void slogan();
int x=15,y=15;
int num1,num2,num3,num4;
int p=x, q=y;
int f,h,k;
ofstream file;
string customer;
ifstream inputFile;
string inventory;
struct Info
{
string Name;
string idNum;
string contact;
Info*link;
}
*head, *tail;
int main()
{
header();
return 0;
}
void header()
{
cout<<"ntt ## ## ######## ## ####### ####### ### ### ######## ";
cout<<"ntt ## ## ## ## ## ## ## #### #### ## ";
cout<<"ntt ## ## ## ## ## ## ## ## ## ## ## ## ";
cout<<"ntt ## # ## ####### ## ## ## ## ## ## ## ## ####### ";
cout<<"ntt ## ### ## ## ## ## ## ## ## ### ## ## ";
cout<<"ntt #### #### ## ## ## ## ## ## ## ## ";
cout<<"ntt ## ## ######## ######## ####### ####### ## ## ######## n";
cout<<"ntt ######## ####### ## ## ###### ######## ######## ## ";
cout<<"ntt ## ## ## ## ## ## ## ## ## ## ";
cout<<"ntt ## ## ## ## ## ## ## ## ## ## ";
cout<<"ntt ## ## ## ######## ## ## ## ####### ## ";
cout<<"ntt ## ## ## ## ## ## ## ## ## ## ";
cout<<"ntt ## ## ## ## ## ## ## ## ## ## ";
cout<<"ntt ## ####### ## ## ###### ## ######## ########n";
cout<<"ntt ####### ###### ## ## ######## ###### ####### ### ## ## ###### ";
cout<<"ntt ## ## ## ## ## ## ## ## ## ## #### ## ## ## ##";
cout<<"ntt ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##";
cout<<"ntt ## ## ## ## ## ####### ## ## ####### ## ## ## ## ## ##";
cout<<"ntt ## ######## ## ## ## ## ## ## ## ## ## ## ## ########";
cout<<"ntt ## ## ## ## ## ## ## ## ## ## ## #### ## ## ##";
cout<<"ntt ####### ## ## ######## ## ## ###### ## ## ## ### ## ## ##nnn";
cout<<"ntt****************************************************************************************************nnnnn";
system("pause");
start();
}
void start()
{
int choose;
system("cls");
slogan();
cout<<"nntttWELCOME nnn";
cout<<"[1].ADMIN nn";
cout<<"[2].USER nn";
cout<<"[3].EXIT nn";
cout<<"SELECTION : ";
cin>>choose;
switch(choose)
{
case 1:
system("cls");
admin();
break;
case 2:
system("cls");
user();
break;
case 3://the problem lies here, where it should exit the program//
cout <<"THANK YOU FOR USING THE PROGRAM"<<endl;
slogan();
system("cls");
break
default:
system("cls");
start();
}
}
void slogan()
{
cout<<"nttttHOTEL CALIFORNIAn";
cout<<"ttt-------------------------------n";
cout<<"ttttHEAVEN ON EARTHnn";
void admin()
{
system("cls");
slogan();
cout<<"nnnt[1].ROOM AVAILABLEnn";
cout<<"t[2].ONLINE VIEWnn";
cout<<"t[3].WALK INnn";
cout<<"t[4].BACKnn";
cout<<"tSELECTION : ";
cin>>num2;
switch(num2)
{
case 1:
system("cls");
k=p+q;
if (k==0){
cout << "SORRY OUR ROOMS ARE FULL hRIGHT NOW"<< endl;
cout << "PLEASE COME BACK LATER"<< endl;
system("pause");
system("cls");
start();
}
cout << "Room available " << k << endl;
cout << "Small: " << p << endl;
cout << "Large: " << q << endl;
system("pause");
admin();
case 2:
system("cls");
display();
break;
case 3:
system("cls");
input();
break;
case 4:
system("cls");
start();
break;
default:
system("cls");
start();
}
}
void input()
{
cout<<"nnPLEASE ENTER YOUR NAME: ";
cin>>std::ws;
getline( cin, customer );
customer += ".txt";
file.open( customer.c_str() );
system("cls");
slogan();
cout<<"nnttttCHOOSE ROOM :nn";
cout<< "[1].LARGE(FOR MORE THAN 3 PEOPLE)********RM200 per night"<<endl;
cout <<"[2].SMALL(FOR LESS THAN 3 PEOPLE)********RM100 per night"<<endl;
cout <<"FOR 3 PEOPLE BEST TAKE LARGE"<<endl;
cout<<"nn";
cin>>num3;
system("cls");
if (num3==1){
q--;
data();
system("pause");
file.close();
start();
}else if (num3==2){
p--;
data();
system("pause");
file.close();
start();
} else if (num3!=1 && num3!=2){
cout << "WRONG INPUT GIVEN" <<endl;
system("pause");
system("cls");
input();
}
}
void data()
{ int date, month,store,year=2018;
struct Info*temp;
head = NULL;
tail = NULL;
cout << "HOW MANY NIGHTS WILL YOU BE STAYING?" << endl;
cin>>f;
if(f>30 || f<0){
cout << "NOT ALLOWED" <<endl;
system("pause");
system("cls");
start();
}
h=200 * f;
cout << "nnTotal: RM" << h << endl;
file<< "Total: RM " << h ;
system ("pause");
system("cls");
cout<<"nnxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxn";
cout<<"nttttFOR THE YEAR 2018n";
cout<<"ttt-------------------------------n";
cout<<"nttttONE MONTH=30 DAYSnn";
cout<<"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxn";
cout<<"tttENTER CHECK IN DATE(1-30)nn";
cin>>date;
if (date>30 || date<0){
cout <<"CANNOT COMPREHEND" << endl;
system("pause");
admin();
}
cout << "tttENTER CHECK IN MONTH(1-12)" <<endl;
cin>>month;
if (month>12 || month <0){
cout <<"CANNOT COMPREHEND" << endl;
system("pause");
admin();
}
file << "CHECK IN ON: " <<date<<"/"<<month<<"/"<<year<<endl;
store=date+f;
if(store>30){
store=store-30;
month=month+1;
if (month>12){
month=month-12;
year=year+1;
}
}
file <<"CHECH OUT ON: " << store<<"/"<<month<<"/"<<year<<endl;
Info *a=new Info;
cout<<"ENTER NAME(SAME AS PREV)"<<endl;
cin>>std::ws;
getline(cin, a->Name);
cout<<"n";
a->link=NULL;
if (head == NULL)
{
head = a;
tail = a;
}
else
{
tail->link =a;
tail= a;
}
Info *b=new Info;
cout<<"ENTER IC "<<endl;
cin>>std::ws;
getline(cin, b->idNum);
cout<<"n";
b->link=NULL;
if (head == NULL)
{
head = b;
tail = b;
}
else
{
tail->link =b;
tail= b;
}
Info *c=new Info;
cout<<"ENTER PHONE NUMBER "<<endl;
cin>>std::ws;
getline(cin, c->contact);
cout<<"nn";
c->link=NULL;
if (head == NULL)
{
head = c;
tail = c;
}
else
{
tail->link =c;
tail= c;
}
temp = head;
while(temp!=NULL)
{
file<<"n"<<temp->Name;
file<<"n"<<temp->idNum;
file<<"n"<<temp->contact<<" nn";
temp = temp->link;
}
cout<<"nDONEnn";
}
void user(){
system("cls");
slogan();
cout<<"nnnt[1].REGISTERnn";
cout<<"t[2].UPDATEnn";
cout<<"t[3].BACKnn";
cout<<"t[4].EXITnn";
cout<<"tSELECTION : ";
cin>>num4;
switch(num4)
{
case 1:
system("cls");
cout << "Room available " << p+q << endl;
cout << "Small: " << p << endl;
cout << "Large: " << q << endl;
system("pause");
system("cls");
input();
case 2:
system("cls");
update();
break;
case 3:
system("cls");
start();
break;
case 4:
system("cls");
break;
default:
system("cls");
start();
}
}
void display()
{
slogan();
cout<<"nnENTER YOUR NAME : ";
cin>>customer;
inputFile.open((customer+".txt").c_str());
if (inputFile)
{
getline(inputFile, customer);
while (inputFile)
{
cout << customer << endl;
getline(inputFile, customer);
}
inputFile.close();
system("pause");
admin();
}
else
{
cout << "NO DATAn";
system("pause");
admin();
}
}
void update()//instead it jumps toward here even after breaking//
{
slogan();
cout<<"nn[1] UPDATE BOOKINGn";
cout<<"nn[2] CANCEL BOOKINGn";
cout<<"nnCHOOSE: ";
cin>>num1;
system("cls");
switch(num1)
{
case 1:
cout<<"nnttt--- UPDATE ---nn";
cout<<"nntENTER YOUR NAME TO CHECK IF DATA EXIST : ";
cin>>std::ws;
//inputFile.open((customer+".txt").c_str());
getline( std::cin, customer );
if(inputFile){
system("cls");
input();
break;
} else
{
cout<< "nnt!NO DATA!" <<endl;
system("pause");
user();
}
case 2:
cout<<"nnttt--- CANCEL BOOKING ONLINE ---nn";
cout<<"nntENTER YOUR NAME : ";
cin>>customer;
inputFile.open((customer+".txt").c_str());
getline( inputFile, customer );
if(inputFile){
remove((customer + ".txt").c_str());
cout<<"nntBOOKING CANCEL";
cout<<"nntINFO DELETEDnn";
cout<<"nntBYE BYEnn";
system("pause");
start();
break;
} else
{
cout<< "nnt!NO DATA!" <<endl;
system("pause");
start();
}
default:
system("cls");
start();
}
}
我认为,唯一相关的功能是user()和update(),因为如果我删除了update()函数,则不会开始调用任何其他函数。
您忘了添加一个";"在第110行的中断代码