CS1315 Computer Programming Assignment One (2024-25 Sem. A)
Problem description
Consider a buffet restaurant with two price settings: Adult (e.g. $200) and Child / Senior (e.g. $150). You may assume that both prices are non-negative (with the Adult price is always higher) and assume that there is no service charge. To attract more customers, the restaurant is offering two types of discounts:
A) Buy-X-get-Y-free:
-
X and Y are positive integers (>=1).
-
Customer must pay X people in Adult price and up to Y Children / Seniors will be free. (less than Y is okay. e.g. A group of 2 Adults and 1 Child can also make use of buy-2-get-2, so 2 Adults will pay and 1 Child will be free).
-
Child / Senior may also pay in Adult price if needed.
(e.g. Suppose the discount is buy-2-get-2. For a bill with 1 Adult and 3 Children, one of the Children could pay in Adult price to fulfill the X Adult requirement, then the remaining 2 Children will enjoy the Y free quotas). -
Creating “ghost” customer is also okay.
(e.g. Suppose the discount is buy-2-get-2. For a bill with 1 Adult and 2 Children, the customers could choose to pay for a non-existing adult to fulfill the X Adult requirement, so that the remaining 2 Children will be free).B) D-percent-offforZormore:
-
Z is positive integer (>=1) and D is between 0 and 100 (inclusive).
-
The Z (or more) customers could be of mixed (Adult/Child) types and the D percent off will be applied to the original bill for them.
-
Creating “ghost” customer is also okay.
(e.g. Suppose the discount is 50% off for 4. A table of 2 Adults and 1 Child could choose to pay for a non-existing child, so that the bill will be (2 Adults + 2 Children) * 50%))
The bill could be partitioned so that different customers in the bill could enjoy different discounts. However no single customer could enjoy both discounts. For instance, if the discounts are buy-1-get-1 as well as 40%-off-for-3. A group of 1 Adult and 2 Children may choose to:
-
Enjoy 40% off for all 3 of them, or,
-
Enjoy buy-1-get-1 for 1 Adult and 1 Child; paying the remaining Child normally. (i.e. 1 Adult pays, 1 Child is free and the “remaining Child” do not enjoy 40% off, as the number of “remaining” customer is 1, not 3)
-
Of course, they could choose to pay for a non-existing Adult to enjoy buy-1-get-1 two times...
However for a group of 2 Adults and 3 Children, they may choose to:
-
Enjoy 40% off for all 5 of them, or,
-
Enjoy buy-1-get-1 for 1 Adult and 1 Child; Enjoy 40% off for the remaining 1 Adult and 2 Children, or,
-
Enjoy buy-1-get-1 for 2 Adults and 2 Children; paying the remaining Child normally.
-
Of course, if they like, they can also pay for a non-existing Adult and enjoy buy-1-get-1 for a total of three times in the bill.
Your task is to find out the cheapest payment amount given the corresponding prices, discount settings and headcounts. The numbers are always in the valid range stated in page 1 (no checking is needed) but the numbers are not necessarily realistic (e.g. price of $0, buy-1-get-4, or 99% off could be possible).
Your program should output exactly in the format (spelling, spacing...etc) as shown in the next page, with the final amount shown in 3 decimal places.
Sample Input / Output:
Example 1: (User Input is underlined)
Example 2: (User Input is underlined)
Example 3: (User Input is underlined)
Example 4: (User Input is underlined)
Marking criteria
Submitted program will be tested repeatedly with PASS. Marks will be graded objectively
based on the number of correct outputs reported by PASS (no matter whether it’s the same as what you saw in your development platform or not).
If the program is not compilable in PASS, zero mark will be given.
Make sure that the output format (spelling, punctuations, spacing...etc) follows exactly the sample output above otherwise PASS will consider your answer incorrect. Marker will make NO manual attempt to check or re-mark program output.
Input the Price for Adult: 250
Input the Price for Child/Senior: 150
Input the counts of Adult and Child: 2 3
Input X Y for the Buy-X-get-Y: 1 1
Input D Z for group discount: 40 3
The payment is: $570.000
Input the Price for Adult: 250
Input the Price for Child/Senior: 150
Input the counts of Adult and Child: 2 3
Input X Y for the Buy-X-get-Y: 1 1
Input D Z for group discount: 30 3
The payment is: $635.000
Input the Price for Adult: 250
Input the Price for Child/Senior: 150
Input the counts of Adult and Child: 2 3
Input X Y for the Buy-X-get-Y: 1 1
Input D Z for group discount: 10 3
The payment is: $650.000
Input the Price for Adult: 499.9
Input the Price for Child/Senior: 299.9
Input the counts of Adult and Child: 2 3
Input X Y for the Buy-X-get-Y: 3 2
Input D Z for group discount: 33.33333 3
The payment is: $1266.333
Unlike tutorial exercises, for assignment, PASS will NOT make ALL test cases visible. (i.e. there are hidden test cases). Queries regarding hidden test case(s) will NOT be answered. It is the responsibility of a programmer to design own test cases in order to verify the correctness of the written program.
Note that the marking in PASS is automatic, therefore the following situations may lead to zero marks:
Input/output does not match the requirements as defined.
(e.g. incorrect spacing, incorrect spelling, letter cases or punctuations)
Submission of non .cpp files (e.g. .exe or .zip files)
Not uploading via “Submit” function. (Note: Upload via “Test” button will NOT be counted)
(Students may test or submit many times, only the last “submit” will be marked)
Please also note that the PASS plagiarism check will also be turned on. The same disciplinary action will be applied without distinguishing which one is the source / copier. Please safeguard your files if you work on your assignment using public computers (e.g. CityU Lab)
Testing and Submission
Students should submit cpp file to PASS before the deadline. All other submission methods (e.g. hardcopy, email...etc) will be ignored. Students may use whatever IDE/compiler for development, but program which is not compilable in PASS will lead to zero mark (e.g. program using non-standard, platform-specific features). The marker will make no attempt to fix the syntax error or make the code compilable.
If you observe that the answer in PASS is different from the one you get in your PC, most likely it is caused by programming bugs like uninitialized variables. The result by PASS will be used for marking without consideration of what you observed in your local PC.
Please also note that the PASS system could be extremely busy and may become sluggish in responding near deadline. You’re suggested to reserve enough time for submission (Not the usual button, but the “Submit” button for assignments).
To protect yourself, it is advised that you write down your particulars (full name, student number, eid...) in the beginning of your source code as comment.