Write a program that can be used to show available seats for
Solution
#include<iostream>
#include<cctype>
#include<iomanip>
using namespace std;
void getdata(char& tickettype, int& row,char& column);
void printform(char form[][6], int row, char column);
int main()
{
char ch,tickettype,column;
int row;
char form[13][6];
cout<<\"This Program for assigns seats for a plane...\ \" <<\"Do u want to start booking now? Y/y for yes , N/n for no.\"<<endl;
cin>>ch;
ch=static_cast<char>(toupper(ch));
while(ch==\'Y\')
{
getdata(tickettype,row,column);
printform(form,row,column);
cout<<\"This Program for assigns seats for a plane...\ \" <<\"Do u want to start booking now? Y/y for yes , N/n for no.\"<<endl;
cin>>ch;
ch=static_cast<char>(toupper(ch));
if(ch==\'N\')
return 0;
}
system(\"PAUSE\");
return 0;
}
void getdata(char& tickettype, int& row,char& column)
{
cout<<\"The airpalne has 13 rows,with six seats in each row.\"<<endl;
cout<<\"Enter ticket type,\ \"<<\"F for first class: \ \"<<\"B for business class: \ \"<<\"E for economy class:\"<<endl;
cin>>tickettype;
tickettype=static_cast<char>(toupper(tickettype));
while(tickettype != \'F\' && tickettype != \'B\' && tickettype != \'E\')
{
cout<<\"Invlaid ticket type.\"<<endl;
cout<<\"Enter ticket type: \ \"<<\"F/f for first class: \ \"<<\"B/b for business class: \ \"<<\"E/e for economy class:\"<<endl;
cin>>tickettype;
tickettype=static_cast<char>(toupper(tickettype));
}
switch(tickettype)
{
case \'F\':cout<< \"Row 1 and 2 are first class: \ \";
break;
case \'B\':cout<< \"Row 3 through 7 are business class: \ \";
break;
case \'E\':cout<< \"Row 8 through 13 are economy class: \ \";
break;
}
cout<<\"Enter the row number u want to sit: \"<<endl;
cin>>row;
cout<<\"Enter the seat number (from A to f). \"<<endl;
cin>>column;
column=static_cast<char>(toupper(column));
}
void printform(char form[][6], int row, char column)
{
int i,j;
cout<< \"* indicates that seat is available: \"<<endl;
cout<< \"X indicates that the seat is occupied. \"<<endl;
cout<<setw(12)<<\"A\" <<setw(6)<<\"B\"<<setw(6)<<\"C\"<<setw(6)<<\"D\"<<setw(6)<<\"E\"<<setw(6)<<\"F\"<<endl;
for(i=0;i<13;i++)
{
cout<<left<<setw(3) << \"Row\" << setw(2)<<i+1;
for(j=0;j<6;j++)
{
if(i==row-1 && j==static_cast<int>(column)-65)
cout<<right<<setw(6)<<\"X\";
else
cout<<right<<setw(6)<<\"*\";
}
cout<<endl;
}
}

