University of Leeds School ofComputingProcedural Programming XJCO1711Semester 1, 2019-2020Coursework 280 Marks(40% of the total module marks)Submission DeadlineYour coursework must be uploaded to Minerva before11pm on Friday 29/11/2019Late Penalties5% will be deducted from your overall mark for every late dayThis coursework is comprised of two tiers. Tier 1 is compulsory and must becompleted by all students. If you satisfy all the requirements of Tier 1, youwill earn the full mark of the coursework. Tier 2 is optional, and you can choose to do it if you would like to stand outfrom 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 theProcedural Programming Module. TIER 11 Skills TestedThis coursework tests your ability to define and use functions and arrays. It alsotests your ability to properly declare global and local variables, use the assignment, conditional execution, and iteration statements. It will also test your ability towrite well-structured C programs with correct indentation of statements. Finally, you need to show that you are able to use comments to explain how yourprogram works.22 The BriefYou will write a program for an airline. The program enables users to achieve taskssuch as booking flights, reserving seats on aircraft, viewing seat reservations, andcancelling flight bookings or seat reservations. 3 The Details3.1 OverviewAn airline company has an aircraft with a maximum seating capacity of 150passengers 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 whichhas 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, shownin 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 inthe first-class cabin, and premium class passengers can only reserve seats in thepremium section. Likewise, economy passengers can only reserve seats in theeconomy section. Budget class customers cannot reserve their seats and they areassigned any remaining seats in the economy section after all economypassengers 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,3are automatically assigned to the remaining seats of their respective travel class. 3.1.1 Air cr aft Seat Configur ationThere are 3 rows of seats in the first-class cabin numbered 1-3. Each row has fourseats 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, seeFigure 1. The back section is used to seat both economy and budget class customersand 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 thefirst-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 oneshown in Figure 1, do not have all sequential row numbers, take a look at thisarticle [1]. 3.2 The taskYou will write a program that provides the following options:3.2.1 Option 1: Book a FlightThis option enables the user of the program to book a flight for one or morepassengers who intend to travel together under the same booking (e.g. familymembers travelling together). The flight booking process has the following steps:1. The program prompts the user to enter the travel class as a numberbetween [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 travellingtogether under this booking. 4. The user enters the number of passengers. 5. The program checks if there are enough remaining seats in the requiredtravel class for all passengers in this booking. 6. The program creates a unique booking reference number for this booking.4The 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 thebooking reference number. Note that at this stage no specific seats are reserved for the passengers. Bookinga flight only guarantees that there are seats available for every passenger in theirchosen travel class. It does not assign passengers to seats in the aircraft. Seatreservation 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 fourcolumns as shown in Figure 2. Each column is used to store certain informationabout 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 togetherunder this booking. Column 3 is used to store a flag that indicates if seats have been reservedfor the passengers of this booking. This flag is initially set to zero when abooking is first added to the table. If seats are later reserved for thisbooking, the flag is set to 1.Figure 2. Booking information are stored in a two-dimensional array3.2.2 Option 2: List all Flight BookingsThis option displays the flight bookings table, as shown below:3.2.3 Option 3: Show Seat MapThis option is used to display the seat map of the aircraft showing all vacant andreserved seats, and to highlight the seats reserved for a certain booking. Theprogram prompts the user to enter the booking number for which reserved seats5should be highlighted, or 0 if it is not desired to highlight any booking. Theprogram then displays the seat map as follows:In the above display, seats are shown on the OS terminal using characters torepresent 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 BookingThis 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 seatsare 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 thetable of bookings. 4. The program retrieves the booking information (travel class, number ofpassengers, and the seats reserved flag) from the table of bookings.65. If the travel class is 4 (budget) or seats have already been reserved for thisbooking (the seats reserved flag=1), the process cannot continue. 6. For each passenger is this booking the program displays the seating mapand prompts the user to enter the desired seat coordinates, i.e. row numberand column letter. 7. The program checks that the entered seat coordinates are valid on thisaircraft. 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 mapagain, with the seats being reserved for the current booking highlighted as‘#’ so that the user can easily see and reserve adjacent seats for thepassengers 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 representone row of seats in the aircraft. Column 0 is used to store the actual row numberfor each of the 26 rows of seats. Remember that seat rows do not havesequential numbers and therefore we cannot use the row index of the array as theseat 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 reservedfor a passenger, the booking number of this passenger is stored in the cell. Notethat in the first-class cabin seat columns C and D are missing therefore we shouldnot use the cells at the intersection of rows 1-3 and columns 3-4.Figure 3. The Seat Reservations Table3.2.5 Option 5: Cancel Seats ReservationThis option is used to cancel the seats reservation for a booking. The process forcancelling 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 thebookings table). 4. The program checks that seats have been reserved for this booking. If seats7have 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 ReservationThis option is used to cancel a booking and free any seats reserved for it. Theprocess 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 proXJCO1711代写、代做C++编程设计、c/c++语言代写gram checks the booking number is valid (the booking exists in thebookings table). 4. The program checks if seats have been reserved for this booking. If seatshave been reserved, then the program frees these seats. 5. The program deletes this booking from the booking table. 4 Gener al Implementation Guidelines1. 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 withthem. 3. Write the program in standard C. If you write your code in any otherlanguage, 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 orpairs with other students. 5. Be aware that plagiarising your code will earn you a zero mark and will havevery serious consequences. It is much better to submit your own partiallyfinished work, than to fall into the trap of plagiarism. We use a software todetect plagiarism automatically, so if you do work with someone else, orsubmit someone else’s work it WILL be detected. 6. At the top of you program file please include the following informationwithin a comment, and fill in your name, student id, email, and the date onwhich you commenced writing your program:/*************************************************************************8University of LeedsSchool of ComputingCOMP1711- Procedural ProgrammingCoursework 2I confirm that the following program has been developed and written by me and it is entirelythe result of my own work. I also confirm that I have not copied any parts of this program fromanother 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 thesemester. Student Name:Student ID:Email:Date Work Commenced: *************************************************************************/If you do not include the above statement in your submitted file, yourcoursework may be rejected, and you will score 0 in this coursework. 5 Developing and testing your progr am1. To simplify program development and facilitate automatic testing, I haveprovided you with C files containing declarations of the data structures andfunction prototypes that you will use to develop the program. 2. Please use these declarations as given and do not for any reason changethem. 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 toautomatically test and mark your program. You will run this harness on yourcode to make sure that you have implemented functions correctly, and toimmediately see you mark on the screen. 4. Together with the file you are reading now, you will be able to find anddownload the following files: air.h: This file contains declarations of the program data structures, aswell as the prototype declarations of all the functions that you are9required to implement. FOR YOU, THIS FILE IS READ ONLY AN SHOULDNEVER BE ALTERED. If you suspect that you have accidentallychanged anything in this file, please download a fresh copy fromMinerva. template.c: This file contains all the functions that you are required toimplement. They all return a value of type int. The body of eachfunction initially contains just one statement: return -99. This specialvalue 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 deletethe ‘return -99’ statement. In some cases, you will need to call someof the provided functions within other functions; in this case, youhave to implement the called function first. You can also add otherfunctions of your own if you think that you need them, but these willnot be tested by the test harness. main.c: This file contains the main function of the program. To helpyou, I have already implemented the main menu interface. All youhave 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 anycode in it. All the marks are assigned to implementing the functions inthe template.c file. test.c: This is the test harness file. You will use it to test yourfunctions, and to see your mark. FOR YOU, THIS FILE IS READ ONLYAN SHOULD NEVER BE ALTERED. If you suspect that you haveaccidentally changed anything in this file, please download a freshcopy from Minerva. 5. To compile your program as a stand-alone application with the interactivemenu, type the following into the Linux terminal:gcc -std=c99 air.h template.c main.c -o mainthen run it by typing:./main6. To compile your program with the provided test harness, type:gcc -std=c99 air.h template.c test.c -o testthen test your program by typing:./test6 Submission Instructions1. Before submitting your coursework, you must make sure that you cancompile your program on our school’s Linux machines (e.g. X9318 Labmachines). You must also thoroughly test your program on these machines. Submissions that do not compile and run on our Linux machines will scorezero even if they work perfectly well on another platform. Hence, if you10have developed your program on a Windows or Mac PC or laptop, you mustnot submit your project until you have made sure that it does compile andrun on our Linux computers without any problems. 2. You should test your program using the provided test harness on one of ourLinux machines to make sure that the functions you have implemented willpass 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 downloadingthem from Minerva and checking that it is indeed what you intended tosubmit. If you submit non-plain text or a corrupt file, your coursework maybe rejected, and you will score 0. 5. Do not upload executable or binary files. 7 Marking SchemeThis coursework is automatically marked by a test harness and the marks assignedto each function can be seen in the provided air.h header file. These arereproduced below:void InitialiseBookings (); // alreadyimplementedint newBookingNumber (); // 4marksint hasCapacity (int travel_class, int n); // 6marksint addBooking(int booking_number, int travel_class, int number_passengers); //6 marksint findBooking (int booking_number); // 6marksint numberPassengers (int booking_number); // 2marksint seatsAreReserved (int booking_number); // 2marksint travelClass (int booking_number); // 2marksint showBookingsTable(); // 4marksint rowIsMissing (int row_number); // 4marks11int isValidSeat (int travel_class, int row, char letter); // 4marksint letterToColumnIndex (char letter); // 2marksint InitialiseSeatMap (); // 6 marksint rowIndex (int row); // 2 marksint reserveSeat (int booking_number, int travel_class , int row, char letter); //6 marksint seatIsReserved (int travel_class , int row , char letter); //4 marksint ShowSeatMap (int booking_number); // 8marksint cancelSeatReservation (int booking_number); //6 marksint cancelBooking (int booking_number); // 6marksTotal 80 marksTIER 2It was mentioned above that the program should be able to automatically assignseats to passengers who have not reserved seats or cannot do so (such as budgetclass 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 algorithmto automatically assign seats to all passengers in an ‘optimum’ manner that makesthe vast majority of passengers happy with their assigned seats. To make theproblem 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 (be assigned seats, but their accompanying adults are given preference torow 7 of the main cabin because it has additional baby care fixtures. 3. Passengers can be accompanied by children (be seated away from their accompanying adults. 4. Some passengers are members of a frequent flier’s club and should beassigned better seats (e.g. window seats) or given a free upgrade to ahigher class if this would improve the seating assignment for otherpassengers in a lower class. 5. A female passenger should not be assigned a middle seat unless one of the12adjoining seats is occupied by a passenger in the same booking or byanother female passenger. To test your algorithm, you need to implement a function that automaticallygenerates 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, youwill rate the success of your algorithm by testing the resulting assignmentsagainst the above five criteria and counting the number of cases that violate eachcriterion. Keep your solution to this tier of the coursework completely separate from that oftier 1, and do not upload it to Minerva. You will need to demonstrate your solutionto me during one of the practical sessions. Please inform me by email if you havesuccessfully finished this part of the coursework. 8 Refer ences[1] Brett Snyder, ‘When row 21 is actually row 9: The method behind airline rownumbers’, available online at the CNN website转自:http://www.6daixie.com/contents/13/4470.html
讲解:XJCO1711、C++、c/c++、ProgrammingWeb|R
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- The Inner Game of Tennis W Timothy Gallwey Jonathan Cape ...