//Airplane seatassignment #include<iostream> #include <cmath> using namespace st
ID: 3618067 • Letter: #
Question
//Airplane seatassignment
#include<iostream>
#include <cmath>
using namespace std;
const int MAX_ROW = 7;
const int MAX_SEAT =4;
void chooseseat(char[][MAX_SEAT]);
void purchase(int,int,char[][MAX_SEAT]);
voidclearseats(char[][MAX_SEAT]);
void display_seating(char[][MAX_SEAT]);
bool assign_seat(char[][MAX_SEAT], int rows, int row, int col);
int main()
{
int row, col;
int input_row,left;
left=MAX_SEAT*MAX_ROW;
char seat[MAX_ROW][MAX_SEAT],more='Y';
clearseats(seat);
display_seating(seat);
while(left>0&&toupper(more)=='Y')
{chooseseat(seat);
display_seating(seat);
cout<<"choose another seat(Y/N)? ";
cin>>more;
}
system("pause");
return 0;
}
void clearseats(charseats[][MAX_SEAT])
{int i,j;
for(i=0;i<MAX_ROW;i++)
for(j=0;j<MAX_SEAT;j++)
seats[i][j]=(char)(65+j); //65='A'
return;
}
void chooseseat(charseats[][MAX_SEAT])
{int row,col;
char seatcol;
do{
cout<<"Enter Seat row desired1-"<<MAX_ROW<<": ";
cin>>row;
while(row>MAX_ROW||row<1) //valid row?
{cout<<"invalidrow ";
cout<<"Enter Seatrow desired 1-"<<MAX_ROW<<": ";
cin>>row;
}
row--;
cout<<"Enter Seat desiredA-"<<(char)('A'-1+MAX_SEAT)<<": ";
cin>>seatcol;
seatcol=toupper(seatcol);//change to uppercase so that can always subtract 'A'
col=seatcol-'A'; //by subtracting A, it changes A to 0, B to 1, C to 2, D to 3
while(col>=MAX_SEAT||col<0) //validseat?
{cout<<col<<endl;
cout<<"invalidseat ";
cout<<"Enter Seatdesired A-"<<(char)('A'-1+MAX_SEAT)<<": ";
cin>>seatcol;
seatcol=toupper(seatcol);
col=seatcol-'A';
}
if(seats[row][col]=='X') //if seatvalid, mark it as "taken"
cout<<"Seat already chosen-rechoose ";
}while (seats[row][col]=='X');
seats[row][col]='X';
return;
}
void display_seating(char seats[][MAX_SEAT])
{int i,j;
for(i=0;i<MAX_ROW;i++)
{cout<<(i+1)<<" ";
for(j=0;j<MAX_SEAT;j++)
{cout<<seats[i][j]<<"";
if(j%2!=0)
cout<<" ";
}
cout<<endl;
}
return;
}
Explanation / Answer
please rate - thanks would you believe the line in red was omitted //Airplane seat assignment #include #include using namespace std; const int MAX_ROW = 7; const int MAX_SEAT = 4; void chooseseat(char[][MAX_SEAT]); void purchase(int,int,char[][MAX_SEAT]); void clearseats(char[][MAX_SEAT]); void display_seating(char [][MAX_SEAT]); bool assign_seat(char [][MAX_SEAT], int rows, int row, intcol); int main() { int row, col; int input_row,left; left=MAX_SEAT*MAX_ROW; char seat[MAX_ROW][MAX_SEAT],more='Y'; clearseats(seat); display_seating(seat); while(left>0&&toupper(more)=='Y') {chooseseat(seat); left--; display_seating(seat); coutmore; } system("pause"); return 0; } void clearseats(char seats[][MAX_SEAT]) {int i,j; for(i=0;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.