1. Perform a program of an arrangement of 20 positions. Each position will repre
ID: 3936779 • Letter: 1
Question
1. Perform a program of an arrangement of 20 positions. Each position will represent the seat of a bus. By means of a menu can be made:to. Tickets sale
B. Inquiries
C. Report
D. Get out
Ticket sales will ask what seat you want if it is empty it will become busy. (0-empty, 1 Busy).
Inquiries will ask for the seat number and indicate if it is occupied or empty.
In Report will be all the seats and their status (Busy / Empty).
Note: After each operation a, b or c, the program must return to the main menu until the option exits. 1. Perform a program of an arrangement of 20 positions. Each position will represent the seat of a bus. By means of a menu can be made:
to. Tickets sale
B. Inquiries
C. Report
D. Get out
Ticket sales will ask what seat you want if it is empty it will become busy. (0-empty, 1 Busy).
Inquiries will ask for the seat number and indicate if it is occupied or empty.
In Report will be all the seats and their status (Busy / Empty).
Note: After each operation a, b or c, the program must return to the main menu until the option exits. 1. Perform a program of an arrangement of 20 positions. Each position will represent the seat of a bus. By means of a menu can be made:
to. Tickets sale
B. Inquiries
C. Report
D. Get out
Ticket sales will ask what seat you want if it is empty it will become busy. (0-empty, 1 Busy).
Inquiries will ask for the seat number and indicate if it is occupied or empty.
In Report will be all the seats and their status (Busy / Empty).
Note: After each operation a, b or c, the program must return to the main menu until the option exits.
Explanation / Answer
I have did it in C++
#include <iostream>
#define BUSY 1
#define EMPTY 0
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
int arr[20],ticket;
char ch;
cout << " WELCOME TO THE BUS TICKET INFORMATION SYSTEM ";
for(int i=0;i<20;i++)
arr[i] = 0;
do{
cout << " A.Ticket Sale() B.Inquires() C.Report() D.get Out['s' for exit] Choose your option: ";
cin >> ch;
switch(ch){
case 'A':
cout << " Enter the seat you want: ";
cin >> ticket;
if(ticket >0 && ticket <=20){
for(int i=0;i<20;i++){
if(arr[ticket]==EMPTY){
arr[ticket] = BUSY;
}
}
}
break;
case 'B':cout << " Enter seat number: ";
cin >> ticket;
if(arr[ticket] == BUSY)
cout << " " <<ticket << " is OCCUPIED: ";
else
cout << " " << ticket << " is NOT OCCUPIED: ";
break;
case 'C':
for(int i=0;i<20;i++){
if(arr[i] == BUSY)
cout << " " << i << " >>> BUSY ";
else
cout << " " <<i << " >>> EMPTY ";
}
break;
case 'D' : exit(0);
default : cout << "Wrong Input ";
}
}while(true);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.