Question
Task 1: Declare a structure named Item , with the following members: (3 marks) a) Code Name Cost Sale price Number of items sold Profit
Task 1: Declare a structure named Item, with the following members: (3 marks) a) Code
- Name
- Cost
- Sale price
- Number of items sold
- Profit
Task 2: Write a function named readInput. (10.5 marks)
- It receives an array of Item of type struct.
- The function should read the data from the given input file named data.txt. The file contains items codes and the number of items sold. Figure 1 shows an example of data that can be used to test the program.
M101, 12 B202, 21 C303, 15 F404, 9 F404, 27 C303, 25
B202, 16 M101, 9
M101, 14 C303, 26 B202, 31
F404, 13 M101, 9
C303, 38 B202, 33
Figure 1: Sample data in the input file "data.txt"
- Assuming you do not know, the number of items. Calculate the number of items sold based on the number of item records found in the input file.
- The function should return the number of items calculated in (c).
Task 3: Write a function named determineNameCost. (10.5 marks)
- This is a non-returning function.
- It takes an array of Item of type struct and the number of items calculated in Task 2 as input parameters.
- The function should determine the items names and cost based on the information given in Table 1.
Table 1
Code | Name | Cost (RM) |
M101 | Double Mushroom | 11.5 |
B202 | Double BBQ Beef | 10.0 |
C303 | Grilled Chicken | 12.5 |
F404 | Fish'n Crisp | 15.0 |
- The function should also calculate the sale price for each item by adding 30% (markup percentage) to the cost of the item. If an item costs RM50 to produce, and you want to apply a mark-up of 25%, you need to multiply 50 by 1.25. The sale price would be RM62.50.
Task 4: Write a function named displayOutput. (10 marks)
- This is a non-returning function.
- It takes an array of Item of type struct and the number of items calculated in Task 2 as input parameters.
- The function should display items code, name, cost, sale price, number of items sold, and profit. The formula for calculating item profit is as follows:
Item profit = Number of items sold (Sale price Cost)
- Figure 2 shows an example of the output that will be displayed on the screen based on the data in the input file "data.txt" shown in Figure 1.
-------------------------------------------------------------------- CODE ITEM NAME COST(RM) SALE(RM) QUANTITY PROFIT(RM)
--------------------------------------------------------------------
M101 Double Mushroom 11.50 14.95 12 41.40
B202 Double BBQ Beef 10.20 13.26 21 64.26
C303 Grilled Chicken 7.00 9.10 15 31.50
F404 Fish'n Crisp 6.25 8.12 9 16.88
F404 Fish'n Crisp 6.25 8.12 27 50.62
C303 Grilled Chicken 7.00 9.10 25 52.50
B202 Double BBQ Beef 10.20 13.26 16 48.96
M101 Double Mushroom 11.50 14.95 9 31.05
M101 Double Mushroom 11.50 14.95 14 48.30
C303 Grilled Chicken 7.00 9.10 26 54.60
B202 Double BBQ Beef 10.20 13.26 31 94.86
F404 Fish'n Crisp 6.25 8.12 13 24.38
M101 Double Mushroom 11.50 14.95 9 31.05
C303 Grilled Chicken 7.00 9.10 38 79.80
B202 Double BBQ Beef 10.20 13.26 33 100.98
--------------------------------------------------------------------
Figure 2: Expected output for Task 4
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started