C Programming Language


Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due


C Programming Language
Contribution to module (weighting: 50 %)
1st Semester 2024-2025

Assignment name:Mini-app for grocery store management 

Out: THU. 5th Dec. 2024 Due: THU. 26nd Dec. 2024

Main objective of the assignment:


  • Learning to draw flow charts to describe the problem and the corresponding solution.
  • Practicing coding and building a C program to solve the given problem.
  • Learning to write a technical report to help others understand your program.


Instructions:

You are given a struct type to present products (see Table 1 and Table 2 as listed below). Finish the assignment with given information.

- Draw flow charts for all functions you want to write in your program (see Figure 1 for example);

- Explain how the structures and functions are used in your program;

- Wrte the source code in C language, and compile them to build the program;

- Run the program on your computer and screenshot the execution results;

- Write a technical report to include all the aforementioned contents

Figure 1 A flow chart showing a function that iteratively reads a char from the user and outputs the char.

Problem description:

You are required to use an array (or other data structure) of struct product to manage the records in Table 1 (which is originally stored in a file named “product.txt”).

HINT: does the C language provide us with functions to deal with FILEs?
struct product
{
int prono;
char fullname[20]
float price;
struct salelist;
};

Table 1 Product records (stored in a file named “product.txt”).

prono
fullname
price
101
mango
3.5
102
orange
2.4
103
banana
2.8
104
watermelon
3.7
105
pineapple
4.1
106
blueberry
5.0
107
cherry
5.5
108
cucumber
1.9
109
cabbage
2.0
110
broccoli
3.1
111
celery
1.9
112
pea
4.5
113
<product name>
<product price>
1. Modify the last record with any kind of product you like that can be found in the supermarket. You can assign an arbitrary price to your product.

2. Write a function to sort the records by price. Write another function to display the records to the screen. As a requirement, the sort function must be passed to the display function as a parameter.

HINT: function pointers.

3. Sales records can be retrieved from Table 2. First, write a function to sort sales records by month. Secondly, write another function to display sales records on the screen with the product information like the following example. Likewise, as a requirement, the sort function must be passed to the display function as a parameter.

Prono|month|sales volume|discount|fullname|price
……
101 |Sep. |41 |10% off. | mango | 3.5
……

Figure 2 A sample output on the screen.

Table 2 Sales records (stored in a file named “salelist.txt”).

prono
month
sales volume
discount
101
Sep.
41
10% off
101
Oct.
48
none
102
Nov.
50
10% off
103
Aug.
43
10% off
103
Sep.
56
none
104
Nov.
64
20% off
105
Sep.
71
none
105
Nov.
63
10% off
105
Dec.
33
10% off
106
Sep.
88
10% off
106
Aug.
78
none
106
Physics
91
none
106
Nov.
65
20% off
106
Dec.
82
10% off
107
Nov.
86
10% off
107
Dec.
48
none
107
Dec.
41
none
108
Sep.
38
none
108
Dec.
56
20% off
108
Nov.
58
none
108
Nov.
98
10% off
109
Aug.
63
10% off
110
Sep.
73
10% off
110
Nov.
43
none
110
Dec.
80
none
110
Dec.
65
20% off
111
Sep.
95
20% off
111
Nov.
89
none
111
Oct.
96
none
112
Sep.
36
none
112
Nov.
73
10% off
112
Oct.
21
none

4. Calculate the total sale volume and average sale volume of each product respectively, and output the them on screen.

5. Output all sales data of September with product information, write the result to a new txt file and name the file with your Brunel id.

6. Calculate the total sale of each product, and output the top three on the screen. To achieve this, you need to know that price of each product varies according to discount of each month. For example: the price of mango in September has a discount of 10% off. In other words, the price of mango in September is 3.15. The total sale of mango in September equals the total sale volume of mango in September multiple the price of mango in September. Finally, we can get the total sale of mango by adding up the sales of mango in September, October,November and December.

Remarks:
* Solutions to all questions above need to be included in one *.c file. In addition, you are required to define a function for each question. e.g.: main(), Q1_functionname(), Q2_functionname(), Q3_functionname(), Q4_functionname() and Q5_functionname(). Qx_functionname() should be given by yourself.
* The output for each question should be done in main() function.
* Do not include any Chinese characters in your assignment.
* You are required to write annotation before each function, and annotation / description for important statements. e.g.:/∗
@function function_name
@desc describe what is this function used for.
∗/
* The assignment should be submitted in a .doc/.docx or pdf file, all the source code should be included, and output screenshot should be included.

发表评论

电子邮件地址不会被公开。 必填项已用*标注