Question: C PROGRAMMING: GLOBAL CONSTANTS and VARIABLES: #define ROW 6 //for row length #define COL 4 //for column length #define MAX 25 // for strings int
C PROGRAMMING:
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]={{300,200,200,300},
{300,200,200,300}, {300,200,200,300}, {300,200,200,300}, {300,200,200,300}, {300,200,200,300}};
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.
Do not worry about the possibility of the randomized index overwriting an X, if it was already there. But if you can take care of that case, very good.
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(char string1[],char string2[]);
The loginMatch function is called to compare a pair of strings, the function returns 1 if both strings match and 0 if there is no match. This is called once with the pawprint the user entered and the admin pawprint; second time it takes in the password the user entered and the admin password. You are not allowed to use string.h functions here. 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 3 sets of 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 tosee 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 Johnathon number is LAS1050, you merged string should be JLoAhSn1a0t5h0on. 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 stringsinput_password[MAX],input_pawprint[MAX],name[MAX],flight_number[MAX]
adminPawprint[]="dpstm3";
adminPassword[]="cmp_sc1050";
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 pawprint and password that will be stored in the character arrays specified. Now, verify the pawprint and password, call the loginMatch function (you should perform string compare) once using input_pawprint and adminPawprint and again with input_password and adminPassword. If both the pairs 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-3). 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,LAS1050,SAN1050) in flight_number[] as specified above for that flight. Then, send the corresponding flight array to seatReservation, then call theprintMessage with name[] and that particular flight_number[], after successful reservation the user will be relocated back to the main menu. Note: flight1 is Miami, flight2 is Nashville, flight3 is Las Vegas.
Sample Output
********* WELCOME TO JOE'S AIRLINE BOOKING SYSTEM **********
1.) Admin Log-in
2.) Reserve a seat
3.) Exit
Choose an option: 1
Admin Pawprint: abcdef
Admin Passowrd: cmp_sc1050
Invalid Pawprint and Password combination
Admin Pawprint: dpstm3
Admin Passowrd: cs1050
Invalid Pawprint and Password combination
Admin Pawprint: dpstm3
Admin Passowrd: cmp_sc1050 //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: $3600
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: Jackson //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 //call printMessage with name[] and flightnumber[]
Congrats Jackson, your flight MIA1050 is booked. Your e-ticket number is: JMaIcAk1s0o5n0
Enjoy your Spring Break :) //end of case 2
1.) Admin Log-in
2.) Reserve a seat
3.) Exit
Choose an option: 1
Admin Pawprint: dpstm3
Admin Passowrd: cmp_sc1050
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: $3900 // $300 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
-------------
********* WELCOME TO JOE'S AIRLINE BOOKING SYSTEM **********
1.) Admin Log-in
2.) Reserve a seat
3.) Exit
Choose an option: 1
Admin Pawprint: dpstm3
Admin Passowrd: cmp_sc1050
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 $500
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 $500
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
O O O O
O O O O
The total earning from all the flights: $1500 //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. Your e-ticket number is : FBrNeAd1050
Enjoy your Spring 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 $300
O O O O
O O O O
O O O O
Congrats Sue, your flight LAS1050 is booked. Your e-ticket number is : SLuAeS1050
Enjoy your Spring Break :)
1.) Admin Log-in
2.) Reserve a seat
3.) Exit
Choose an option: 1
Admin Pawprint: dpstm3
Admin Passowrd: cmp_sc1050
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: $2000 //Total increased by $500 from the two flights
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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
