休息后显示功能

问题描述 投票:-5回答:1

所以我的任务是创建一个基本的酒店管理系统。虽然我对我的工作总体感到满意,但我意识到在函数user()输入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<<"\n\t\t    ##               ##   ########   ##         #######    #######    ###       ###   ########    ";
cout<<"\n\t\t     ##             ##    ##         ##        ##         ##     ##   ####     ####   ##          ";
cout<<"\n\t\t      ##           ##     ##         ##        ##         ##     ##   ## ##   ## ##   ##          ";
cout<<"\n\t\t       ##    #    ##      #######    ##        ##         ##     ##   ##  ## ##  ##   #######     ";
cout<<"\n\t\t        ##  ###  ##       ##         ##        ##         ##     ##   ##   ###   ##   ##          ";
cout<<"\n\t\t         #### ####        ##         ##        ##         ##     ##   ##         ##   ##          ";
cout<<"\n\t\t          ##   ##         ########   ########   #######    #######    ##         ##   ########    \n";


cout<<"\n\t\t            ########    #######       ##    ##    ######    ########   ########   ##      ";
cout<<"\n\t\t               ##      ##     ##      ##    ##   ##    ##      ##      ##         ##      ";
cout<<"\n\t\t               ##      ##     ##      ##    ##   ##    ##      ##      ##         ##      ";
cout<<"\n\t\t               ##      ##     ##      ########   ##    ##      ##      #######    ##      ";
cout<<"\n\t\t               ##      ##     ##      ##    ##   ##    ##      ##      ##         ##      ";
cout<<"\n\t\t               ##      ##     ##      ##    ##   ##    ##      ##      ##         ##      ";
cout<<"\n\t\t               ##       #######       ##    ##    ######       ##      ########   ########\n";

cout<<"\n\t\t  #######    ######    ##         ##   ########    ######    #######     ###     ##   ##    ###### ";
cout<<"\n\t\t ##         ##    ##   ##         ##   ##         ##    ##   ##    ##    ####    ##   ##   ##    ##";
cout<<"\n\t\t ##         ##    ##   ##         ##   ##         ##    ##   ##    ##    ## ##   ##   ##   ##    ##";
cout<<"\n\t\t ##         ##    ##   ##         ##   #######    ##    ##   #######     ##  ##  ##   ##   ##    ##";
cout<<"\n\t\t ##         ########   ##         ##   ##         ##    ##   ##   ##     ##   ## ##   ##   ########";
cout<<"\n\t\t ##         ##    ##   ##         ##   ##         ##    ##   ##    ##    ##    ####   ##   ##    ##";
cout<<"\n\t\t  #######   ##    ##   ########   ##   ##          ######    ##     ##   ##     ###   ##   ##    ##\n\n\n";
cout<<"\n\t\t****************************************************************************************************\n\n\n\n\n";


system("pause");
start();

     }

  void start()
       {
 int choose;
system("cls");
slogan();
cout<<"\n\n\t\t\tWELCOME \n\n\n";
cout<<"[1].ADMIN \n\n";
cout<<"[2].USER \n\n";
cout<<"[3].EXIT \n\n";
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<<"\n\t\t\t\tHOTEL CALIFORNIA\n";
cout<<"\t\t\t-------------------------------\n";
cout<<"\t\t\t\tHEAVEN ON EARTH\n\n";


   void admin()
      {
  system("cls");
  slogan();
  cout<<"\n\n\n\t[1].ROOM AVAILABLE\n\n";
  cout<<"\t[2].ONLINE VIEW\n\n";
  cout<<"\t[3].WALK IN\n\n";
  cout<<"\t[4].BACK\n\n";
  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<<"\n\nPLEASE ENTER YOUR NAME: ";
  cin>>std::ws;
  getline( cin, customer );
  customer += ".txt";
  file.open( customer.c_str() );

 system("cls");
      slogan();
   cout<<"\n\n\t\t\t\tCHOOSE ROOM :\n\n";

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<<"\n\n";
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 << "\n\nTotal: RM" << h << endl;
    file<< "Total: RM " << h ;
    system ("pause");
    system("cls");

  cout<<"\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n";
cout<<"\n\t\t\t\tFOR THE YEAR 2018\n";
cout<<"\t\t\t-------------------------------\n";
cout<<"\n\t\t\t\tONE MONTH=30 DAYS\n\n";
cout<<"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n";
    cout<<"\t\t\tENTER CHECK IN DATE(1-30)\n\n";
    cin>>date;
    if (date>30 || date<0){


        cout <<"CANNOT COMPREHEND" << endl;
           system("pause");
        admin();
    }

    cout << "\t\t\tENTER 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<<"\n\n";

    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<<" \n\n";
    temp = temp->link;
}
 cout<<"\nDONE\n\n";

   }

   void user(){
 system("cls");
   slogan();

      cout<<"\n\n\n\t[1].REGISTER\n\n";
    cout<<"\t[2].UPDATE\n\n";
   cout<<"\t[3].BACK\n\n";
   cout<<"\t[4].EXIT\n\n";

    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<<"\n\nENTER 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 DATA\n";
   system("pause");
   admin();
  }

   }
   void update()//instead it jumps toward here even after breaking//
{
 slogan();
 cout<<"\n\n[1] UPDATE BOOKING\n";
 cout<<"\n\n[2] CANCEL BOOKING\n";
cout<<"\n\nCHOOSE: ";
cin>>num1;
   system("cls");
      switch(num1)
   {

  case 1:

cout<<"\n\n\t\t\t---   UPDATE   ---\n\n";
cout<<"\n\n\tENTER 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<< "\n\n\t!NO DATA!" <<endl;
system("pause");
user();

}


   case 2:
cout<<"\n\n\t\t\t---   CANCEL BOOKING ONLINE   ---\n\n";
cout<<"\n\n\tENTER YOUR NAME : ";
cin>>customer;
inputFile.open((customer+".txt").c_str());
getline( inputFile, customer );

if(inputFile){

remove((customer + ".txt").c_str());
cout<<"\n\n\tBOOKING CANCEL";
cout<<"\n\n\tINFO DELETED\n\n";
cout<<"\n\n\tBYE BYE\n\n";
system("pause");
start();
break;
   }   else

{
cout<< "\n\n\t!NO DATA!" <<endl;
system("pause");
start();

   }

default:
    system("cls");
    start();

       }
  }

我认为唯一相关的函数是user()和update(),因为如果删除update()函数,它不会继续调用任何其他函数。

c++ function output display
1个回答
0
投票

你忘记添加“;”在第110行的中断代码

© www.soinside.com 2019 - 2024. All rights reserved.