Answer to Question #240601 in C++ for HelloWorld

Question #240601

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:

  • a one-dimensional array to store the row number of the seats (Row #)
  • a two-dimensional array of 13 rows and 6 columns to store the seat assignments (*) and seat letters (A-F)

Your program must prompt the user to enter the following information:

  • Reserve a seat (Yes (Y/y) or No (N/n))
  • Assign ticket type (first class (F/f), business class (B/b), or economy class (E/e))
  • Select desired seat (1-13 and A-F)

Your program must contain at least the following functions:

  • a function to initialize the seat plan.
  • a function to show the seat assignments.
  • a function to show the menu to assign a seat.
  • a function to assign and select your desired seat.
  • a function for each ticket type that determines if a seat is occupied and if that class is full .
1
Expert's answer
2021-09-22T23:43:50-0400
#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();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS