首页 > > 详细

XJCO1711辅导、讲解C++编程设计、c/c++语言辅导、讲解Programming辅导Web开发|讲解R语言编程

University of Leeds School of
Computing
Procedural Programming XJCO1711
Semester 1, 2019-2020
Coursework 2
80 Marks
(40% of the total module marks)
Submission Deadline
Your coursework must be uploaded to Minerva before
11pm on Friday 29/11/2019
Late Penalties
5% will be deducted from your overall mark for every late day
This coursework is comprised of two tiers. Tier 1 is compulsory and must be
completed by all students. If you satisfy all the requirements of Tier 1, you
will earn the full mark of the coursework. Tier 2 is optional, and you can choose to do it if you would like to stand out
from the crowd. Tier 2 is not marked, but if you accomplish it correctly, your name will be written in a Distinction List on the Minerva page of the
Procedural Programming Module. TIER 1
1 Skills Tested
This coursework tests your ability to define and use functions and arrays. It also
tests your ability to properly declare global and local variables, use the assignment, conditional execution, and iteration statements. It will also test your ability to
write well-structured C programs with correct indentation of statements. Finally, you need to show that you are able to use comments to explain how your
program works.
2 The Brief
You will write a program for an airline. The program enables users to achieve tasks
such as booking flights, reserving seats on aircraft, viewing seat reservations, and
cancelling flight bookings or seat reservations. 3 The Details
3.1 Overview
An airline company has an aircraft with a maximum seating capacity of 150
passengers as shown in Figure 1.
Figure 1. Seat plan for an Airbus 320 aircraft (source Delta Airlines)
Passengers can book flights in one of four travel classes:
1. First. 2. Premium. 3. Economy. 4. Budget. First class passengers can sit in the first-class cabin which has a total of 12 seats, shown in orange in Figure 1. Premium class passengers can sit in the premium section of the main cabin which
has a total of 42 seats, shown in blue in Figure 1. Economy and budget class passengers share the remaining seats of the main cabin. A total of 96 seats are available to economy and budget class passengers, shown
in white in Figure 1. After booking a flight, passengers of any travel class - except budget customers- can reserve their seats in advance. First class passengers can only reserve seats in
the first-class cabin, and premium class passengers can only reserve seats in the
premium section. Likewise, economy passengers can only reserve seats in the
economy section. Budget class customers cannot reserve their seats and they are
assigned any remaining seats in the economy section after all economy
passengers have chosen their seats. Reserving seats in advance is an option and not all passengers do that. Passengers who have not reserved their seats, as well as budget class customers,
are automatically assigned to the remaining seats of their respective travel class. 3.1.1 Air cr aft Seat Configur ation
There are 3 rows of seats in the first-class cabin numbered 1-3. Each row has four
seats identified by the letters A, B, E, and F, see Figure 1. The main cabin has two sections:  The front section is reserved for premium class customers and has 7 rows, numbered 7-21 with row number 9 and row numbers 13-19 missing, see
Figure 1.  The back section is used to seat both economy and budget class customers
and has 16 rows numbered 22-38 with row number 33 missing, see Figure 1. Each row in the main cabin has 6 seats identified by the letters A-F. Note that the seats with the letters C and D (the aisle seats) are missing from the
first-class cabin to allow for the extra wide seats in this section of the aircraft.
If you are curious to know why some aircraft seat configurations, such as the one
shown in Figure 1, do not have all sequential row numbers, take a look at this
article [1]. 3.2 The task
You will write a program that provides the following options:
3.2.1 Option 1: Book a Flight
This option enables the user of the program to book a flight for one or more
passengers who intend to travel together under the same booking (e.g. family
members travelling together). The flight booking process has the following steps:
1. The program prompts the user to enter the travel class as a number
between [1-4] corresponding to the 4 travel classes (first=1, premium=2, economy=3, and budget=4). 2. The user enters the travel class number. 3. The program prompts the user to enter the number of passengers travelling
together under this booking. 4. The user enters the number of passengers. 5. The program checks if there are enough remaining seats in the required
travel class for all passengers in this booking. 6. The program creates a unique booking reference number for this booking.
The booking reference number should be an integer between [1-999]. 7. The program stores the information of this booking in a table (see below). 8. The program confirms that a booking has been made and displays the
booking reference number. Note that at this stage no specific seats are reserved for the passengers. Booking
a flight only guarantees that there are seats available for every passenger in their
chosen travel class. It does not assign passengers to seats in the aircraft. Seat
reservation can be done later using Option 4. To keep track of all bookings the program stores booking information in a two- dimensional array (table). The table has a maximum of 150 rows (why?) and four
columns as shown in Figure 2. Each column is used to store certain information
about a flight booking:  Column 0 is used to store the booking number.  Column 1 is used to store the travel class (an integer between 1-4).  Column 2 is used to store the number of passengers travelling together
under this booking.  Column 3 is used to store a flag that indicates if seats have been reserved
for the passengers of this booking. This flag is initially set to zero when a
booking is first added to the table. If seats are later reserved for this
booking, the flag is set to 1.
Figure 2. Booking information are stored in a two-dimensional array
3.2.2 Option 2: List all Flight Bookings
This option displays the flight bookings table, as shown below:
3.2.3 Option 3: Show Seat Map
This option is used to display the seat map of the aircraft showing all vacant and
reserved seats, and to highlight the seats reserved for a certain booking. The
program prompts the user to enter the booking number for which reserved seats
5
should be highlighted, or 0 if it is not desired to highlight any booking. The
program then displays the seat map as follows:
In the above display, seats are shown on the OS terminal using characters to
represent the seats of the aircraft using the following nomenclature:  Vacant seats in the first-class cabin are shown as capital ‘O’.  Vacant seats in premium class are shown as small ‘o’.  Vacant seats in the economy class are shown as ‘.’.  Reserved seats in any class are shown as a ‘*’.  Seats reserved for the given booking number are shown as ‘#’. 3.2.4 Option 4: Reserve Seats for a Booking
This option is used to reserve seats for all the passengers of a certain booking. The seat reservation process is as follows:
1. The program prompts the user to enter the booking number for which seats
are to be reserved. 2. The user enters the booking number. 3. The program checks that the booking number is valid, i.e. it exists in the
table of bookings. 4. The program retrieves the booking information (travel class, number of
passengers, and the seats reserved flag) from the table of bookings.
6
5. If the travel class is 4 (budget) or seats have already been reserved for this
booking (the seats reserved flag=1), the process cannot continue. 6. For each passenger is this booking the program displays the seating map
and prompts the user to enter the desired seat coordinates, i.e. row number
and column letter. 7. The program checks that the entered seat coordinates are valid on this
aircraft. 8. The program checks that this seat is not reserved for another passenger. 9. The program reserves this seat for the passenger and displays the seat map
again, with the seats being reserved for the current booking highlighted as
‘#’ so that the user can easily see and reserve adjacent seats for the
passengers of this booking. To keep track of seat reservations, we will use a two-dimensional array (table)
with 26 rows and 7 columns as shown in Figure 3. Each row in the array represent
one row of seats in the aircraft. Column 0 is used to store the actual row number
for each of the 26 rows of seats. Remember that seat rows do not have
sequential numbers and therefore we cannot use the row index of the array as the
seat row number. Columns 1-6 represent the 6 seat columns (A-F) of the aircraft. A cell at the intersection of a row and a column represent one seat in the aircraft.
If the seat is not reserved a value of -1 is stored in the cell. If the seat is reserved
for a passenger, the booking number of this passenger is stored in the cell. Note
that in the first-class cabin seat columns C and D are missing therefore we should
not use the cells at the intersection of rows 1-3 and columns 3-4.
Figure 3. The Seat Reservations Table
3.2.5 Option 5: Cancel Seats Reservation
This option is used to cancel the seats reservation for a booking. The process for
cancelling seats reservation is as follows:
1. The program prompts the user to enter a booking number. 2. The user enters a booking number. 3. The program checks the booking number is valid (the booking exists in the
bookings table). 4. The program checks that seats have been reserved for this booking. If seats
7
have not been reserved for this booking, then the process cannot continue. 5. The program free the seats reserved for this booking. 3.2.6 Option 6: Cancel Seats Reservation
This option is used to cancel a booking and free any seats reserved for it. The
process for cancelling a booking is as follows:
1. The program prompts the user to enter a booking number. 2. The user enters a booking number. 3. The program checks the booking number is valid (the booking exists in the
bookings table). 4. The program checks if seats have been reserved for this booking. If seats
have been reserved, then the program frees these seats. 5. The program deletes this booking from the booking table. 4 Gener al Implementation Guidelines
1. In this program you can use the following types of C language constructs:  Variable declarations.  The define and include directives.  Arrays.  The printf and scanf functions.  Expressions and the assignment statement.  The ‘if else’ statement.  Iteration statements (loops).  Functions and function prototypes. 2. Please do NOT use structs or pointers even if you are already familiar with
them. 3. Write the program in standard C. If you write your code in any other
language, it will NOT be marked, and you will score zero. 4. This is an individual project, and you are not supposed to work in groups or
pairs with other students. 5. Be aware that plagiarising your code will earn you a zero mark and will have
very serious consequences. It is much better to submit your own partially
finished work, than to fall into the trap of plagiarism. We use a software to
detect plagiarism automatically, so if you do work with someone else, or
submit someone else’s work it WILL be detected. 6. At the top of you program file please include the following information
within a comment, and fill in your name, student id, email, and the date on
which you commenced writing your program:
/*************************************************************************
8
University of Leeds
School of Computing
COMP1711- Procedural Programming
Coursework 2
I confirm that the following program has been developed and written by me and it is entirely
the result of my own work. I also confirm that I have not copied any parts of this program from
another person or any other source or facilitated someone to copy this program.
I confirm that I will not post this program online or share it with anyone before the end of the
semester. Student Name:
Student ID:
Email:
Date Work Commenced: *************************************************************************/
If you do not include the above statement in your submitted file, your
coursework may be rejected, and you will score 0 in this coursework. 5 Developing and testing your progr am
1. To simplify program development and facilitate automatic testing, I have
provided you with C files containing declarations of the data structures and
function prototypes that you will use to develop the program. 2. Please use these declarations as given and do not for any reason change
them. Changing or deleting any of the declarations will stop the test harness
(see below) from working and you will score zero in this coursework. 3. For this coursework, I have provided you with a test harness to
automatically test and mark your program. You will run this harness on your
code to make sure that you have implemented functions correctly, and to
immediately see you mark on the screen. 4. Together with the file you are reading now, you will be able to find and
download the following files:  air.h: This file contains declarations of the program data structures, as
well as the prototype declarations of all the functions that you are
9
required to implement. FOR YOU, THIS FILE IS READ ONLY AN SHOULD
NEVER BE ALTERED. If you suspect that you have accidentally
changed anything in this file, please download a fresh copy from
Minerva.  template.c: This file contains all the functions that you are required to
implement. They all return a value of type int. The body of each
function initially contains just one statement: return -99. This special
value tells the test harness that the function is not implemented. Replace this statement with your implementation code of the function.
If you decide not to implement a function, then please do not delete
the ‘return -99’ statement. In some cases, you will need to call some
of the provided functions within other functions; in this case, you
have to implement the called function first. You can also add other
functions of your own if you think that you need them, but these will
not be tested by the test harness.  main.c: This file contains the main function of the program. To help
you, I have already implemented the main menu interface. All you
have to do is to add the appropriate code for menu option. However, this file is not tested or marked. You can even decide not to write any
code in it. All the marks are assigned to implementing the functions in
the template.c file.  test.c: This is the test harness file. You will use it to test your
functions, and to see your mark. FOR YOU, THIS FILE IS READ ONLY
AN SHOULD NEVER BE ALTERED. If you suspect that you have
accidentally changed anything in this file, please download a fresh
copy from Minerva. 5. To compile your program as a stand-alone application with the interactive
menu, type the following into the Linux terminal:
gcc -std=c99 air.h template.c main.c -o main
then run it by typing:
./main
6. To compile your program with the provided test harness, type:
gcc -std=c99 air.h template.c test.c -o test
then test your program by typing:
./test
6 Submission Instructions
1. Before submitting your coursework, you must make sure that you can
compile your program on our school’s Linux machines (e.g. X9318 Lab
machines). You must also thoroughly test your program on these machines. Submissions that do not compile and run on our Linux machines will score
zero even if they work perfectly well on another platform. Hence, if you
10
have developed your program on a Windows or Mac PC or laptop, you must
not submit your project until you have made sure that it does compile and
run on our Linux computers without any problems. 2. You should test your program using the provided test harness on one of our
Linux machines to make sure that the functions you have implemented will
pass the tests, and to know your mark. 3. You should only upload to Minerva the two C files that you have written, i.e. the template.c and main.c files. Do not upload the provided header file (air.h)
or the test harness file (test.c). 4. Please make sure that you have uploaded the correct files by downloading
them from Minerva and checking that it is indeed what you intended to
submit. If you submit non-plain text or a corrupt file, your coursework may
be rejected, and you will score 0. 5. Do not upload executable or binary files. 7 Marking Scheme
This coursework is automatically marked by a test harness and the marks assigned
to each function can be seen in the provided air.h header file. These are
reproduced below:
void InitialiseBookings (); // already
implemented
int newBookingNumber (); // 4
marks
int hasCapacity (int travel_class, int n); // 6
marks
int addBooking(int booking_number, int travel_class, int number_passengers); //
6 marks
int findBooking (int booking_number); // 6
marks
int numberPassengers (int booking_number); // 2
marks
int seatsAreReserved (int booking_number); // 2
marks
int travelClass (int booking_number); // 2
marks
int showBookingsTable(); // 4
marks
int rowIsMissing (int row_number); // 4
marks
11
int isValidSeat (int travel_class, int row, char letter); // 4
marks
int letterToColumnIndex (char letter); // 2
marks
int InitialiseSeatMap (); // 6 marks
int rowIndex (int row); // 2 marks
int reserveSeat (int booking_number, int travel_class , int row, char letter); //
6 marks
int seatIsReserved (int travel_class , int row , char letter); //
4 marks
int ShowSeatMap (int booking_number); // 8
marks
int cancelSeatReservation (int booking_number); //
6 marks
int cancelBooking (int booking_number); // 6
marks
Total 80 marks
TIER 2
It was mentioned above that the program should be able to automatically assign
seats to passengers who have not reserved seats or cannot do so (such as budget
class passengers). In Tier 1, you were not required to implement this feature.
In this optional part of the coursework, you are required to develop an algorithm
to automatically assign seats to all passengers in an ‘optimum’ manner that makes
the vast majority of passengers happy with their assigned seats. To make the
problem more interesting, we will introduce the following criteria into the problem:
1. Passengers travelling as a group should be assigned adjacent seats. 2. Passengers can be accompanied by infants (<= 2 yeas). Infants should not
be assigned seats, but their accompanying adults are given preference to
row 7 of the main cabin because it has additional baby care fixtures. 3. Passengers can be accompanied by children (<= 10 years) who should never
be seated away from their accompanying adults. 4. Some passengers are members of a frequent flier’s club and should be
assigned better seats (e.g. window seats) or given a free upgrade to a
higher class if this would improve the seating assignment for other
passengers in a lower class. 5. A female passenger should not be assigned a middle seat unless one of th
adjoining seats is occupied by a passenger in the same booking or by
another female passenger. To test your algorithm, you need to implement a function that automatically
generates a random sequence of booking requests until the aircraft is fully booked. Then you will apply your algorithm to assign seats to all passengers. Finally, you
will rate the success of your algorithm by testing the resulting assignments
against the above five criteria and counting the number of cases that violate each
criterion. Keep your solution to this tier of the coursework completely separate from that of
tier 1, and do not upload it to Minerva. You will need to demonstrate your solution
to me during one of the practical sessions. Please inform me by email if you have
successfully finished this part of the coursework. 8 Refer ences
[1] Brett Snyder, ‘When row 21 is actually row 9: The method behind airline row
numbers’, available online at the CNN website

 

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!