Advertisement
wnan42

2Darray_7/25/2012

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