Write a program that can be used to assign seats for a commercial airplane. The airplane has 13 rows, with six seats in each row. Rows 1 and 2 are first class, rows 3 through 7 are business class, and rows 8 through 13 are economy class.
Use two parallel arrays:
Your program must prompt the user to enter the following information:
Your program must contain at least the following functions:
#include<iostream>
using namespace std;
int seats[6];
char arr[13][6];
void initial_seat_plan(){
cout<<"Rows 1 and 2 are first class"<<endl;
cout<<"Rows 3, 4, 5,6 and 7 are business class"<<endl;
cout<<"\nRows 8, 9, 10, 11,12 and 13 are economy class\n"<<endl;
for(int i=0; i<13; i++){
for(int j=0; j<6; j++){
arr[i][j] = '*';
}
}
}
void display(){
for(int i=0; i<13; i++){
for(int j=0; j<6; j++){
cout<<arr[i][j]<<endl;
}
}
}
void seat_assignments(){
cout<<" \tA\tB\tC\tD\tE\tF"<<endl;
for(int i=0; i<13; i++){
cout<<"Row: "<<(i+1)<<"\t";
for(int j=0; j<6; j++){
cout<<arr[i][j]<<"\t";
}
cout<<endl;
}
}
void menu_to_assign_seat(){
initial_seat_plan();
seat_assignments();
}
void assign_desireds_seat(){
char yes_no;
do{
cout<<"Do you want reserve a seat. (Yes (Y/y) or No (N/n)):\n";
cin>>yes_no;
yes_no = toupper(yes_no);
cout<<"Enter ticket type. Ticket type can be (first class (F/f), business class (B/b), or economy class (E/e)):\n";
char ticket;
cin>>ticket;
ticket = toupper(ticket);
cout<<"Enter the desired row between 1 and 13:\n";
int row;
cin>>row;
cout<<"The seat you want (A,B,C,D,E or F):\n";
char seat;
if(seat=='A'){
arr[row][0] = 'X';
}
else if(seat =='B'){
arr[row][1] = 'X';
}
else if(seat=='C'){
arr[row][2] = 'X';
}
else if(seat=='D'){
arr[row][3] = 'X';
}
else if(seat=='E'){
arr[row][4] = 'X';
}
else if(seat=='F'){
arr[row][5] = 'X';
}
}while((yes_no != 'N'));
cout<<"Terminated\n";
}
void seat_is_occupied(){
cout<<"Enter the row\n";
int row;
cin>>row;
cout<<"Enter the seat number\n";
int seat_number;
if(arr[row][seat_number]=='X'){
cout<<"The seat is already occupied\n";
}
else{
cout<<"The seat is not occupied\n";
}
}
int main(){
assign_desireds_seat();
cout<<"All the seats marked * are available\n";
menu_to_assign_seat();
}
Comments
Leave a comment