Advertisement
Need4Sleep

main.cpp (DailyC++) 7/25/12

Jul 25th, 2012
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.19 KB | None | 0 0
  1. http://www.cplusplus.com/forum/beginner/75558/
  2. #include <iostream>
  3. #include <iomanip>
  4. using namespace std;
  5. const int row=13;
  6. const int col=4;
  7. void printSeat(bool seat[row][col], int t1, int t2)
  8. {
  9.      int wsize=3;
  10.      cout<<setw(9)<<"A"<<setw(5)<<"B"<<setw(5)<<"C"<<setw(5)<<"D"<<endl;
  11.      for(int i=t1;i<t2+1;i++)
  12.      {
  13.              if (i>8)wsize=2;
  14.              cout<<" Row "<<i+1<<setw(wsize);
  15.              for(int j=0;j<col;j++)
  16.              {
  17.                  if(seat[i][j]==1){cout<<'X'<<setw(5);}
  18.                  else{cout<<'*'<<setw(5);}
  19.                  
  20.              }
  21.              cout<<endl;
  22.      }
  23. }
  24. void setSeat(bool seat[row][col])
  25. {
  26.      int row_num, col_num;
  27.      char col_char;
  28.      cout<<"Please input your row number: ";
  29.      cin>>row_num;
  30.      row_num--;
  31.      cout<<"Please input your coloum letter: ";
  32.      cin>>col_char;
  33.      col_num=col_char-'A';
  34.      if(seat[row_num][col_num]==0)
  35.      {seat[row_num][col_num]=1;
  36.      cout<<"You select seat "<<++row_num<<col_char<<endl;}
  37.      else {cout<<"This seat is occupied!"<<endl;}
  38. }
  39. int main()
  40. {
  41.     bool seat[row][col]={false};
  42.     char choice_ticket,choice_again;
  43.     bool finish=false;
  44.     while(!finish){
  45.     cout<<"Please select your ticket type:(1 as first class, 2 as business, 3 as economy):"<<endl;
  46.     cin>>choice_ticket;
  47.     if(choice_ticket=='1')
  48.     {
  49.          cout<<"Belowis the seat map for first class."<<endl;
  50.          printSeat(seat,0,1);
  51.          setSeat(seat);  
  52.          printSeat(seat,0,1);        
  53.     }
  54.     else if(choice_ticket=='2')
  55.     {
  56.          cout<<"Belowis the seat map for business."<<endl;
  57.          printSeat(seat,2,6);  
  58.          setSeat(seat);
  59.          printSeat(seat,2,6);          
  60.     }
  61.     else if(choice_ticket=='3')
  62.     {
  63.          cout<<"Belowis the seat map for economy."<<endl;
  64.          printSeat(seat,7,12);
  65.          setSeat(seat);
  66.          printSeat(seat,7,12);          
  67.     }
  68.     else {cout<<"Error input! Please select again:"<<endl;}
  69.     cout<<"Do you want to book another ticket? 1 for yes, 0 for no: ";
  70.     cin>>choice_again;
  71.     if(choice_again=='0') {cout<<"Thank you~ Bye~"<<endl; finish=true;}
  72. }
  73.     system("pause");
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement