Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- http://www.cplusplus.com/forum/beginner/75558/
- #include <iostream>
- #include <iomanip>
- using namespace std;
- const int row=13;
- const int col=4;
- void printSeat(bool seat[row][col], int t1, int t2)
- {
- int wsize=3;
- cout<<setw(9)<<"A"<<setw(5)<<"B"<<setw(5)<<"C"<<setw(5)<<"D"<<endl;
- for(int i=t1;i<t2+1;i++)
- {
- if (i>8)wsize=2;
- cout<<" Row "<<i+1<<setw(wsize);
- for(int j=0;j<col;j++)
- {
- if(seat[i][j]==1){cout<<'X'<<setw(5);}
- else{cout<<'*'<<setw(5);}
- }
- cout<<endl;
- }
- }
- void setSeat(bool seat[row][col])
- {
- int row_num, col_num;
- char col_char;
- cout<<"Please input your row number: ";
- cin>>row_num;
- row_num--;
- cout<<"Please input your coloum letter: ";
- cin>>col_char;
- col_num=col_char-'A';
- if(seat[row_num][col_num]==0)
- {seat[row_num][col_num]=1;
- cout<<"You select seat "<<++row_num<<col_char<<endl;}
- else {cout<<"This seat is occupied!"<<endl;}
- }
- int main()
- {
- bool seat[row][col]={false};
- char choice_ticket,choice_again;
- bool finish=false;
- while(!finish){
- cout<<"Please select your ticket type:(1 as first class, 2 as business, 3 as economy):"<<endl;
- cin>>choice_ticket;
- if(choice_ticket=='1')
- {
- cout<<"Belowis the seat map for first class."<<endl;
- printSeat(seat,0,1);
- setSeat(seat);
- printSeat(seat,0,1);
- }
- else if(choice_ticket=='2')
- {
- cout<<"Belowis the seat map for business."<<endl;
- printSeat(seat,2,6);
- setSeat(seat);
- printSeat(seat,2,6);
- }
- else if(choice_ticket=='3')
- {
- cout<<"Belowis the seat map for economy."<<endl;
- printSeat(seat,7,12);
- setSeat(seat);
- printSeat(seat,7,12);
- }
- else {cout<<"Error input! Please select again:"<<endl;}
- cout<<"Do you want to book another ticket? 1 for yes, 0 for no: ";
- cin>>choice_again;
- if(choice_again=='0') {cout<<"Thank you~ Bye~"<<endl; finish=true;}
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement