Question
How would I create a C program? This application helps in reserving flight seats. This is done via implementing the 8 user-defined functions as explained
How would I create a C program?
This
application helps in reserving flight seats. This is done via implementing the 8 user-defined
functions as explained below.
Your program must print a menu for the user to select what he needs to do with the application.
There will be admin mode which requires log-in via a passcode. There will be an option for
reserving a seat on a flight. Third option is to exit the application.
Comments and prototypes have been given for you to help you out in the process.
GLOBAL CONSTANTS and VARIABLES:
#define ROW 6 //for row length
#define COL 4 //for column length
#define MAX 25 // for strings
int costMatrix[ROW][COL]={{500,200,200,500},
{500,200,200,500},
{500,200,200,500},
{500,200,200,500},
{500,200,200,500},
{500,200,200,500}};
Functions to implement:
1.
void initialSeats(char flight[][COL], int count);
The
initialSeats
function takes in a two-dimensional
char
array created in main. It will initialize
all array elements to the character
O. O
symbolizes the seat on the plane is open and can be
taken. The
int count
parameter is used to symbolize the number of people who already have a
seat on the plane; this is a random number sent from main (use rand() to send this number). In
this function it will randomly create and assign an index in the two-dimensional array with the
character
X
for each person up to value of
count
.
X
is used to symbolize that an element in
the two dimensional array is occupied. This will be used later on in the program.
MAKE SURE
TO SEED RAND in MAIN.
Below is the way to randomly generate the seats for each
passenger to take. This function should be called as soon as your program starts.
Keep in mind
the possibility of the randomized index overwriting
X,
if it was already there.
You have to handle that case. Beware!!
int row = rand() % ROW;
int col = rand() % COL;
2.
void displayMenu();
Prints the display options. Admin mode, Reserve a seat and Exit. This is the main menu.
3.
void printFlightMap(char flight[][COL]);
The printFlightMap function is printing off a two-dimensional character array. Thus, printing off
the characters stored in each index of the two-dimensional array either O or X. As noted
above the ROW and COL are #defined in your program, use them. For loops are your friends
here. Called in admin mode and during reserving a seat (specifically in seatReservation).
4.
int loginMatch(int passcode,int adminPasscode);
The loginMatch function is called to compare a pair of integers, the function returns 1 if both
numbers match and 0 if there is no match. This is called with the number the user entered and the
admin password. This is called in admin mode.
5
.
int getTotalRevenue(char f1[][COL], char f2[][COL], char f3[ ][COL]);
Note: f1, f2, f3 are flight1, flight2, flight3, just shorthanded.
The getTotalRevenue function will take in all three two-dimensional character arrays created in
main and calculate the total revenue using the costMatrix two dimensional array. With each two-
dimensional array f1, f2, and f3, search for the character X stored in them, upon finding the
index of the character X, use the index to reference inside of the global two-dimensional array
costMatrix (look above in Constants and Global Variables).
While inside of costMatrix array,
add the value stored in the two-dimensional array with a running total variable (Hint use +=).
The function will return the total revenue earned thus far from seats reserved in all 3 flights. So,
you will need
nested for-loops
. This is called only in admin mode.
6.
void flightMenu();
Prints the three flight options as shown. Flights to Miami, Nashville and Las Vegas. This is done
when reserve a seat option is chosen.
7.
void seatReservation(char flight[][COL]);
The seatReservation function takes in a two-dimensional array and allows the user to reserve an
index on the two-dimensional array. Before any reserving is done, this function calls the
printFlightMap
function mentioned earlier to allow the user to
see
the already populated two-
dimensional array for that flight. Then, the user is asked to enter a row and column to reserve a
seat. Additionally, this function
will have built in error checking (look below at output
example)
Once the user has inputted a correct index within [0, ROW) and [0, COL) in the two-
dimensional array, this function needs to check if that index entered is already taken in the two-
dimensional array with the character
X.
If the index is populated with
X
, an error will be
shown to the user (
look at the output below
) and have them re-enter a new possible row and
column again. If the index entered is not filled with X, then assign that index with
X
, i.e.
changing the element from
O
to
X
. Before the function ends, it will call the function
printFlightMap
again and prints a success message.
Remember rows run from 0-5 and columns from 0-3. Error check for this too.
8.
void printMessage(char name[],char num[]);
This function is called for each flight option after the seatReservation() is called. It takes in two
strings, name of passenger and the flight number for that particular case. Both are character
arrays (strings). For flight Cou->Miami number must be set as MIA1050, for Cou->Nashville
number must be set as BNA1050, for flight Cou->Las Vegas num must be set as LAS1050,
this must be done in main and the name and particular number must be sent to this function.
Once in this function, you will merge (important part) the two strings into third string and print
that as the e-Ticket as shown below and print a confirmation message.
Eg1: name is Fred number is MIA1050, your merged string should be FMrIeAd1050. Print
this as the booking confirmation number.
Eg2: name is Guilliams number is LAS1050, you merged string should be
GLuAiSl1l0i5a0ms.
Eg3: name is Christopher number is BNA1050, your merged string should be
CBhNrAi1s0t5o0pher
9.
int main(void)
The main function will be doing all (most of) the function calls. In main, you will need to create
four character arrays of
flight_1[ROW][COL]
,
flight_2[ROW][COL]
,
flight_3[ROW][COL]
,
and strings
name[MAX],flight_number[MAX]
adminPasscode
= 105016;
Also, before you call
initialSeats
function on all the flights arrays individually, make sure to find
how many people already reserved seats. This is done by creating a local variable
seats = rand % 5 + 1 (this is your
int counts
in initialSeats function), rand()%5 +1 will give a
random number between 1-5; you only need to do this once. A menu system will be displayed
for the users to run specific parts of the program (See output below of what the menu system
needs to look like).
Make sure to implement error checking for invalid input!
On the main menu, the user will see a display of options: The options are 1: Admin Portal, 2:
Reserve a seat on a flight, and 3: Quit. The menu will need to loop until the exit option is
chosen.
To access the
Admin Portal,
the user enters a 1, and then must type a passcode that will be
stored in a variable
.
Now, verify the passcode, call the
loginMatch
function (you should
compare) with passcode and adminPasscode to verify if it is an authentic log-in attempt. If the
pair
match, that is, they are equivalent then it means successful log-in. Upon successful
verification, inside of the admin portal, call
printFlightMap
on each flight array and
getTotalRevenue
(See output below). Declare these variables in main().
To access
Reserve a seat
, the user enters a 2. Inside of this portal, the user is displayed the three
flights that can be accessed to book a seat. (See below output).
As always
verify the user input
for flight option (1-5). 2 character arrays will be used, name and flight_number. Once a valid
flight option is chosen. Ask for the users first name and store it in name[] and store the flight
numbers (MIA1050,BNA1050,LAS1050) in flight_number[] as specified above for that flight.
Then, send the corresponding flight array to
seatReservation
, after successful reservation the
user will be relocated back to the main menu. (If you are doing the bonus) then call the
printMessage with name[] and that particular flight_number[],
. Note: flight1 is Miami,
flight2 is Nashville, flight3 is Las Vegas.
Please go through Sample Output and the document clearly before starting out.
Sample Output
Character in bold are inputs from the user.
Yours will vary but the outline must look similar. It is big,
dont worry, but will help give you a better idea. I have run it twice completely, thats why it is 10
pages.
[dpstm3@bengal-vm2 ~]$ ./a.out
********* WELCOME TO JOE'S AIRLINE BOOKING SYSTEM *********
1.) Admin Log-in
2.) Reserve a seat
3.) Exit
Choose an option:
4
Wrong option! Choose a right option again
1.) Admin Log-in
2.) Reserve a seat
3.) Exit
Choose an option:
0
Wrong option! Choose a right option again
1.) Admin Log-in
2.) Reserve a seat
3.) Exit
Choose an option:
3
Terminating the Program
Thank you for using Joe's Airline Booking System.
[dpstm3@bengal-vm2 ~]$ ./a.out
********* WELCOME TO JOE'S AIRLINE BOOKING SYSTEM **********
1.) Admin Log-in
2.) Reserve a seat
3.) Exit
Choose an option:
1
Enter the login passcode to log in as admin:
123
Invalid Passcode combination
Enter the login passcode to log in as admin:
111
Invalid Passcode combination
Enter the login passcode to log in as admin:
105015
Invalid Passcode combination
Enter the login passcode to log in as admin:
205016
Invalid Passcode combination
Enter the login passcode to log in as admin:
105016
//Print all 3 flight maps after admin login
Printing the Flight Map of flight Columbia to Miami.... //
Initially 5(random) seats taken by all 3 flights
O O O O
O X X O
O O X X
O O O O
O O O X
O O O O
Printing the Flight Map of flight Columbia to Nashville....
O O O O
O O X O
O O O O
X X O X
X O O O
O O O O
Printing the Flight Map of flight Columbia to Las Vegas....
O O X O
O O O O
O O X O
O O O X
O O X O
O X O O
The total earning from all the flights: $4800
You are logged out now!
//end of case 1
1.) Admin Log-in
2.) Reserve a seat
3.) Exit
Choose an option:
2
1.) COU ----> MIA
2.) COU ----> BNA
3.) COU ----> LAS
Choose a flight:
4
//Error check for flightoption
1.) COU ----> MIA
2.) COU ----> BNA
3.) COU ----> LAS
Choose a flight:
0
1.) COU ----> MIA
2.) COU ----> BNA
3.) COU ----> LAS
Choose a flight:
1
Enter your first name:
Guacamole
//store in name[]
O O O O
//goto seatReservation
O X X O
O O X X
O O O O
O O O X
O O O O
Which Seat row do you want? :
1
//Error check for rows and columns
Which seat column do you want? :
1
Sorry!! someone has reserved that seat. Please Try Again.
Which Seat row do you want? :
6
Seat Rows are between 0 and 5.
Try Again.Which Seat row do you want? :
0
Which seat column do you want? :
4
Seat columns are between 0 and 3.
Try Again.Which seat column do you want? :
3
Your requested seat has been reserved
O O O
X
//The bold one is the chosen, just for your reference.
O X X O
O O X X
O O O O
O O O X
O O O O
Congrats Guacamole, your flight MIA1050 is booked, enjoy your trip.
// STOP HERE IF NO BONUS
Your e-ticket number is: GMuIcAa1m0o5l0e //
call printMessage with name[] and flightnumber[]
Enjoy your Thanksgiving Break :)
//
end of case 2
1.) Admin Log-in
2.) Reserve a seat
3.) Exit
Choose an option:
1
Enter the login passcode to log in as admin:
10501601
Invalid Passcode combination
Enter the login passcode to log in as admin:
105016
Printing the Flight Map of flight Columbia to Miami....
O O O X
//Updated flight map for Miami
O X X O
O O X X
O O O O
O O O X
O O O O
Printing the Flight Map of flight Columbia to Nashville....
O O O O
O O X O
O O O O
X X O X
X O O O
O O O O
Printing the Flight Map of flight Columbia to Las Vegas....
O O X O
O O O O
O O X O
O O O X
O O X O
O X O O
The total earning from all the flights: $5300
// $500 for the ticket purchased is added here
You are logged out now!
1.) Admin Log-in
2.) Reserve a seat
3.) Exit
Choose an option:
3
Terminating the Program
Thank you for using Joe's Airline Booking System.
[dpstm3@bengal-vm2 ~]$
[dpstm3@bengal-vm2 ~]$ ./a.out
********* WELCOME TO JOE'S AIRLINE BOOKING SYSTEM **********
1.) Admin Log-in
2.) Reserve a seat
3.) Exit
Choose an option:
1
Enter the login passcode to log in as admin:
105016
Invalid Passcode combination
Printing the Flight Map of flight Columbia to Miami..... //
2(random) seats reserved on all 3 flights
O O X O
O O O O
O O O O
O O O O
O O O O
X O O O
//revenue from this $700
Printing the Flight Map of flight Columbia to Nashville....
O O O O
X O O O
O O O O
O X O O
O O O O
//Revenue from this $700
O O O O
Printing the Flight Map of flight Columbia to Las Vegas....
O X O O
O O O O
X O O O
O O O O
//Revenue from this $700
O O O O
O O O O
The total earning from all the flights: $2100
//Hence the total
You are logged out now!
1.) Admin Log-in
2.) Reserve a seat
3.) Exit
Choose an option:
2
1.) COU ----> MIA
2.) COU ----> BNA
3.) COU ----> LAS
Choose a flight:
2
Enter your first name: Fred
O O O O
X O O O
O O O O
O X O O
O O O O
O O O O
Which Seat row do you want? : 1
Which seat column do you want? : 1
Your requested seat has been reserved
O O O O
X
X
O O
//Bold is chosen, just for your reference $200
O O O O
O X O O
O O O O
O O O O
Congrats Fred , your flight BNA1050 is booked, enjoy your trip.
Your e-ticket number is : FBrNeAd1050
Enjoy your Thanksgiving Break :)
1.) Admin Log-in
2.) Reserve a seat
3.) Exit
Choose an option:
2
1.) COU ----> MIA
2.) COU ----> BNA
3.) COU ----> LAS
Choose a flight:
3
Enter your first name:
Sue
O X O O
O O O O
X O O O
O O O O
O O O O
O O O O
Which Seat row do you want? :
2
Which seat column do you want? :
0
Sorry!! someone has reserved that seat. Please Try Again.
Which Seat row do you want? :
2
Which seat column do you want? :
3
Your requested seat has been reserved
O X O O
O O O O
X O O
X
//Chosen seat $500
O O O O
O O O O
O O O O
Congrats Sue, your flight LAS1050 is booked, enjoy your trip.
Your e-ticket number is : SLuAeS1050
Enjoy your Thanksgiving Break :)
1.) Admin Log-in
2.) Reserve a seat
3.) Exit
Choose an option:
1
Enter the login passcode to log in as admin:
123
Invalid Passcode combination
Printing the Flight Map of flight Columbia to Miami....
O O X O
O O O O
O O O O
O O O O
O O O O
X O O O
Printing the Flight Map of flight Columbia to Nashville.... //Updated flight maps for Nashville and Vegas
O O O O
X X O O
O O O O
O X O O
O O O O
O O O O
Printing the Flight Map of flight Columbia to Las Vegas....
O X O O
O O O O
X O O X
O O O O
O O O O
O O O O
The total earning from all the flights: $2800
//Total increased by $700 from the two flights
You are logged out now!
1.) Admin Log-in
2.) Reserve a seat
3.) Exit
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started