data编程代写、代做c/c++程序语言

- 首页 >> Java编程
Introduction to
Software
Engineering and
Programming
Coursework 2
Jing Wang
THE UNIVERSITY OF NOTTINGHAM NINGBO CHINA C Program Requirements
Develop a C program as the real-time inventory system for a newly opened supermarket. The
program should complete the 3 tasks below.
Task 1. Before the supermarket is open to all the customers for the first time, build the inventory
for all the products. This inventory shall be saved as a Text file (with a file extension of .txt) on
the computer, named as Inventory.txt. The supermarket staff (user of this program) will manually
input the information of each product with the following requirements:
1.1. Product name. The product name shall not include spaces (assume the user will not
input spaces), for example, BottledWater, FlatShoes. The number of characters included
in the name shall be no more than 20. If the entered string is longer than 20 characters,
just save the first 20 characters as the product name and ignore the rest characters. No need
to check if there is duplicate name in the inventory.
1.2. Product code. It is a 4-digit number, and shall be unique for each product. The product
code is numbered based on the entry sequence, i.e. product code for the 1
st
entry is 0001,
and 0002 for the 2
nd
entry, etc. The code shall be generated automatically by the program.
No more than 1000 products are allowed to input. When receiving 1000 product
information, finish entry and display a proper message to the user.
1.3. Unit Price. The unit price of each product shall be of data type “float”, and shall be less
than 1000 RMB. If the unit price is higher than or equal to 1000 RMB, display a proper
error message and request the user to input again until a valid input is received.
1.4. Quantity. The quantity of each product shall be of data type “integer” and shall be less
than 100. If the quantity is more than 100, display a proper error message and request the
user to input again until a valid input is received.
1.5. Terminate entry. If there are less than 1000 products, the user can press ctrl+z then press
enter to terminate input to the inventory.
1.6. Full information package for each product. For each product, 4 information should be
saved, i.e. items from step 1.1 to 1.4 (refer to N1).
1.7. User-friendly message. Prompting messages and error messages shall be designed to be
user-friendly.
1.8. Complete all the tasks in Task 1 in an external function.


Now the inventory is done. The supermarket is ready to welcome all the lovely customers. Task 2. For each customer, the products to purchase will be entered to the cashing system one by
one and the customer will received a receipt of all the purchased products by the end, meanwhile,
the inventory system shall be updated on the quantities of the corresponding products. All the tasks
in Task 2 shall be completed in function main(). Detailed requirements are followed.
2.1.Display a welcome message as shown below.
***********************************************
* UNNC-Super *
* Type the code ID *
* Type F to finish *
***********************************************
Note: Information in white color above shall be the same as in your program. The requirement is
the same for all the following white-color messages.
2.2.Show the message below to allow the cashier to enter the product code (assume the product
codes have been attached to the products beforehand). One entry per line.
Product Code:

2.3.For each product code entry, the system will search the inventory and locate the product
name, unit price and remaining quantity. If no match can be found, display the following
error message, and get back to step 2.2.
This product code does not exist! Try again!

2.4.For valid product code, display the product name and unit price to the screen. Design the
displayed information to be user-friendly.
2.5.Show the message below to enter the quantity of the product that the customer purchases.
One entry per line.
Product Quantity:

2.6.If the quantity to purchase is larger than the product’s quantity recorded in inventory,
display the following error message and input the quantity again until a valid input is
received.
Quantity entry is wrong! Check the quantity and enter again:

2.7.Update the product quantity in the inventory. For example, the quantity of BottledWater in
inventory is 90, after the customer purchases 10 of them, the quantity of this product in the inventory is updated to 80, while the information of all other products shall not be changed
(refer to N2).
2.8.The entry process of each product will keep repeating from step 2.2 to step 2.7, until the
cashier types F to finish.
2.9.Once the product entry for this customer finishes, display a receipt that shows a greeting,
the shopping list, and the total cost. The order of the items on the receipt should be in the
same order of the item entry sequence. An example receipt is shown below.
_____________________________________

THANK YOU FOR VISITING UNNC - Super!
_____________________________________
Here is your receipt:

Item Code Ut. Price Quant. Price
Dish 0071 25.00 3 75.00
Beef 0032 45.00 2 90.00
Bowl 0071 25.00 3 75.00
BottledWater 0001 5.00 5 25.00
FlatShoes 0123 268.00 1 268.00
_____________________________________
TOTAL COST: 533.00
Transaction Date: 15:00:00 Wed Nov 20 2024
Note: Information in red color above is presented only for the purpose of format demonstration,
and the information displayed by your program shall follow the same format but with different
content depending on program entry. All the information shall be displayed in the same color as
the default setting of CodeBlocks.
2.10. After printing the receipt, use the following message to allow for the entry of cash.
Cash Received:

2.11. Display the following message to indicate the change from the cash received. If the
cash received is not enough, display a proper error message and get back to step 2.10. Note:
in step 2.10, the cash received is the overall cash received, not the cash increment.
Change Given:

2.12. When the transaction finishes, display the following message. If Y is entered, repeat
steps from 2.1 to 2.12. If N is entered, proceed to Task 3.
Next customer? (Y/N) Now take a break when no customer is here.
Refreshed? Guess so.
Let’s check the inventory to see if any product is short of storage.

Task 3. Check the inventory and find all the products with short storage. Complete this task in the
2
nd
external function. Detailed requirements are followed.
3.1. In the inventory, find all the products with a quantity less than 5. These products shall be
saved in a new file named as Short_RedFlag.txt. The format of information to be saved in
Short_RedFlag.txt shall be the same as in Inventory.txt. Meanwhile, count how many
products are saved in Short_RedFlag.txt.
3.2. In the inventory, find all the products with a quantity more than 4 and less than 15. These
products shall be saved in a new file named as Short_BlueFlag.txt. The format of
information to be saved in Short_BlueFlag.txt shall be the same as in Inventory.txt.
Meanwhile, count how many products are saved in Short_BlueFlag.txt.
3.3. After finish step 3.1 and 3.2, display a message to the output screen as shown below.
Purchase now! There are 10 red-flag storage products.

Add to your To-Do List! There are 22 blue-flag storage products.
Note: Information in red color above is presented only for the purpose of format demonstration,
and the information displayed by your program shall follow the same format but with different
content depending on program entry. All the information shall be displayed in the same color as
the default setting of CodeBlocks.


Everything is done.
Happy Hour Time!

Note
N1. When inputting to the inventory in Task 1, specifying the field width for each information
will be very helpful.
N2. In Task 1, besides the 3 modes introduced at the lecture, there are more modes to open a
file, e.g. “r+”, “w+”, “a+”, “wb”, etc., which were mentioned briefly at the lecture as selfstudy
topics. Learn how to open files in a mode different from the 3 introduced modes in
order to work on this coursework (which is quite straightforward after you figure out how
to use the 3 introduced modes). Plenty of helpful resources are available online, and you
may kick off with this one and this one.
N3. Task 1 and Task 3 are completed in separate external functions.
N4. For coursework submission, the file, Inventory.txt, which is generated and completed in
Task 1, shall be saved and renamed as Inventory_sbm.txt for submission. Therefore, in the
file of Inventory_sbm.txt, the information of all the products before the 1st customer starts
shopping should be included.
N5. The C project and the file Inventory_sbm.txt shall be submitted as one archive file to
Moodle (allowed file extensions are .7z and .zip). An example of the submission file is
shown in the images below, together with the instruction on how to compress a folder.

N6. Comment your program properly and use proper indentation and blank lines to increase
the readability of your program.
N7. Submission deadline for this coursework is 3pm, 11 December 2024. Plan your time in
advance, and avoid last-minute submission.
N8. All C programs will be tested using the CodeBlocks installed on university computers.
Therefore, make sure that your C program runs well on a university computer as you
expected before submitting your work on Moodle.
N9. Messages displayed in green highlights are only for fun, and are not programming tasks.

Marking Scheme
Kindly be reminded that successful compilation and execution of a program doesn’t mean a full
mark for each task. The algorithm, efficiency, memory will be assessed as well.


站长地图