Introduction
C,,。
,,,
。
Requirement
CS 1050 Homework Assignment 2
JOE’S AIRLINE RESERVATION SYSTEM
Fall-2016
Due : 14 th October, Friday 5:00 PM (No Extension). Submission system shuts off at 5pm.
Directions
Complete the following homework assignment using the description given in each section.
IMPORTANT INFO
tc.rnet will be down for maintenance during the course of the week of 10/3, it is anticipated
to be back up quickly but in order to be safe there is a temporary server created to work on hw2,
which will be taken down as soon as the former is back up and running. So in order to not lose your
code follow the instructions.
Logging in to the new server:
Putty: hostname = test.rnet.missouri.edu
Terminal on a mac: ssh
Notice the change of server, you will be logging into a different server (test.rnet.missouri.edu) and
not your original server (tc.rnet.missouri.edu).
USE FTP clients like FileZilla or WinSCP to back up your files to your local machine. The test.rnet
server is a temporary one and will be take down during the week of 10/3 after tc.rnet is back,
unfortunately we have no control over the timings, so whenever you code something make sure you
keep backing the file up immediately on your local machine. Like, every 15 minutes or once you
finish one function or whenever you quit out of test.rnet.
Once you get an announcement on BLACKBOARD from DHEERAJ, saying “tc.rnet is back and
running” move the local copy to tc.rnet server. Again, by using FTP.
After that, Log into putty / terminal again using
tc.rnet.missouri.edu as the new host name and continue the way you have been doing it all this
while and submit it from here only. You cannot submit from test.rnet.missouri.edu.
I really hope you know how to use ftp or file transfer by now. All the TAs have spoken at least twice
about it in the labs.
Submission information:
Submit the assignment by the due date using the similar submission command as used for labs
Please include your lab section in the file name.
This will work only when you are on tc.rnet.missouri.edu and not on test.rnet
Filename must be: sectionletter-hw2.c (Include your respective lab section)
e.g. m-hw2.c
$ submit
$ submit CS1050 HW2 m-hw2.c
Purpose:
Learn to use multiple types of two-dimensional arrays for data input and access.
Use character arrays and strings and perform. string manipulation.
Learn to develop a complex menu system.
Learn the importance of using functions.
Description
Thanksgiving Break is fast approaching, so, we hereby present Mizzou’s state-of-the-art online
ticket booking system, Joe’s Airline Reservation System. Which will be developed by you. 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.
A file templateHW2.c is attached on Blackboard which will guide you on how to start the
program and what are the global variables you need to use and how. You can follow that.
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
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 variable is used to symbolize the number of people who already have a seat
on the plane, this is a random number generated and sent from main. 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 the passcodes, the function returns 1 if both match
and 0 if there is no match. This is called in admin mode. Should prompt for the passcode entry
until the passcode matches. The adminPasscode is specified, everyone should use the same
adminPassocde, then compare that with the passcode user enters in main() when they wish to
log-in.
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[]);
//DO THIS, IF YOU ARE DOING THE BONUS
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 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; // everyone must keep this the same
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. Switch to that particular case and ask for the user’s 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. Then print a
success message using name and fligh_number, just to confirm the booking.
Must be done for each case (each flight).
Then, if you are doing the bonus, 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,
don’t worry, but will help give you a better idea. I have run it twice completely, that’s why it is 10
pages.