Answered step by step
Verified Expert Solution
Question
1 Approved Answer
input.txt: M101 12 B202 21 C303 15 F404 9 F404 27 C303 25 B202 16 M101 9 M101 14 C303 26 B202 31 F404 13
input.txt:
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
Write a complete C++ program. The program uses various types of structured data developed to calculate the profit of each item, the total amount of profit, and the highest profit. The program should perform the following tasks: Task 1: Declare a structure named Item, with the following members: (3 marks) a) Code b) Name c) Cost d) Sale price e) Number of items sold 1) Profit Task 2: Write a function named readInput. (10 marks) a) It receives an array of Item of type struct. b) The function should read data from the given input text file named input.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. c) 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. d) The function should return the number of items calculated in (c). M101 12 B202 21 C303 15 F404 9 F404 27 C303 25 B202 16 M1019 M101 14 C303 26 B202 31 F404 13 M101 9 C303 38 B202 33 Figure 1: Sample data in the input file "input.txt" Task 3: Write a function named calculateSalePrice. (10.5 marks) a) This is a non-returning function. b) It takes an array of Item of type struct and the number of items calculated in Task 2 as input parameters. c) The function should determine the items' names and cost based on the information given in Table 1. Code M101 B202 C303 F404 Table 1 Name Double Mushroom Double BBQ Beef Grilled Chicken Fish'n Crisp Cost (RM) 11.5 10.0 12.5 15.0 d) The function should also calculate the sale price for each item by adding 30% (markup percentage) to the cost of the item. Example, 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.5 marks) a) This is a non-returning function. b) It takes an array of Item of type struct and the number of items calculated in Task 2 as input parameters. c) 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) d) Figure 2 shows an example of the output that will be displayed on the screen based on the data in the input file "input.txt" shown in Figure 1. CODE ITEM NAME COST (RM) SALE (RM) QUANTITY PROFIT (RM) M101 Double Mushroom B202 Double BBQ Beef C303 Grilled Chicken 5404 Fish'n Crisp 1404 Fish'n Crisp Grilled chicken B202 Double BBQ Beef M101 Double Mushroom M101 Double Mushroom C303 Grilled Chicken B202 Double BBQ Beef 7404 Fish'n Crisp M101 Double Mushroom C303 Grilled Chicken B202 Double BBQ Beef C303 11.50 10.20 7.00 6.25 6.25 7.00 10.20 11.50 11.50 7.00 10.20 6.25 11.50 7.00 10.20 14.95 13.26 9.10 8.12 8.12 9.10 13.26 14.95 14.95 9.10 13.26 8.12 14.95 9.10 13.26 12 21 15 9 27 25 16 9 41.40 64.26 31.50 16.88 50.62 52.50 48.96 31.05 48.30 54.60 94.86 24.38 31.05 79.80 100.98 26 31 13 9 38 33 Figure 2: Expected output for Task 4 Task 5: Write a function named displayAnalysis. (17 marks) a) This is a non-returning function. b) It takes an array of Item of type struct and the number of items calculated in Task 2 as input parameters. c) The function should display items' names and total profit for each item. d) The function should also calculate and display the total amount of profit for all items and the highest profit. c) Figure 3 shows an example of the output that will be displayed on the screen based on the data in the input file "input.txt" shown in Figure 1. ITEM NAME Double Mushroom Double BBQ Beef Grilled Chicken Fish'n Crisp TOTAL PROFIT (RM) 151.80 309.06 218.40 91.BB The total amount of profit - RM 527.46 Highest profit - RM 309.06 Figure 3: Expected output for Task 5 Task 6: Write a main function to perform the following tasks: (5 marks) a) Declare one-dimensional array variable with 50 elements for a structure type Item b) The function may need to call the functions that are defined in the previous task to produce the output as shown in Figure 4. Note: Please use proper output formatting. c) Figure 4 shows the complete output that will be displayed on the screen based on the data in the input file "input.txt" shown in Figure 1. CODE ITEM NAME COST (RM) SALE (RM) QUANTITY PROFIT (RM) M101 B202 C303 F404 F404 C303 B202 M101 M101 C303 3202 F404 M101 C303 3202 Double Mushroom Double BBQ Beef Grilled chicken Fish'n Crisp Fish'n Crisp Grilled Chicken Double BBQ Beef Double Mushroom Double Mushroom Grilled Chicken Double BBQ Beef Fish'n Crisp Double Mushroom Grilled chicken Double BBQ Beef 11.50 10.20 7.00 6.25 6.25 7.00 10.20 11.50 11.50 7.00 10.20 6.25 11.50 7.00 10.20 14.95 13.26 9.10 8.12 8.12 9.10 13.26 14.95 14.95 9.10 13.26 8.12 14.95 9.10 13.26 12 21 15 9 27 25 16 9 14 26 31 13 9 38 33 41.40 64.26 31.50 16.88 50.62 52.50 48.96 31.05 48.30 54.60 94.86 24.38 31.05 79.80 100.98 ITEM NAME Double Mushroom Double BBQ Beef Grilled chicken Fish'n Crisp TOTAL PROFIT (RM) 151.80 309.06 218.40 91.88 The total amount of profit - RM 527.46 Highest profit - RM 309.06 Figure 4: Complete output for the data from the input file "input.txt" Task 7: List all function prototypes. (4 marks) (5 marks) Task 8: You must ensure your program fulfill the following criteria: a) The program is able to run. b) All required header files are included. Write a complete C++ program. The program uses various types of structured data developed to calculate the profit of each item, the total amount of profit, and the highest profit. The program should perform the following tasks: Task 1: Declare a structure named Item, with the following members: (3 marks) a) Code b) Name c) Cost d) Sale price e) Number of items sold 1) Profit Task 2: Write a function named readInput. (10 marks) a) It receives an array of Item of type struct. b) The function should read data from the given input text file named input.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. c) 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. d) The function should return the number of items calculated in (c). M101 12 B202 21 C303 15 F404 9 F404 27 C303 25 B202 16 M1019 M101 14 C303 26 B202 31 F404 13 M101 9 C303 38 B202 33 Figure 1: Sample data in the input file "input.txt" Task 3: Write a function named calculateSalePrice. (10.5 marks) a) This is a non-returning function. b) It takes an array of Item of type struct and the number of items calculated in Task 2 as input parameters. c) The function should determine the items' names and cost based on the information given in Table 1. Code M101 B202 C303 F404 Table 1 Name Double Mushroom Double BBQ Beef Grilled Chicken Fish'n Crisp Cost (RM) 11.5 10.0 12.5 15.0 d) The function should also calculate the sale price for each item by adding 30% (markup percentage) to the cost of the item. Example, 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.5 marks) a) This is a non-returning function. b) It takes an array of Item of type struct and the number of items calculated in Task 2 as input parameters. c) 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) d) Figure 2 shows an example of the output that will be displayed on the screen based on the data in the input file "input.txt" shown in Figure 1. CODE ITEM NAME COST (RM) SALE (RM) QUANTITY PROFIT (RM) M101 Double Mushroom B202 Double BBQ Beef C303 Grilled Chicken 5404 Fish'n Crisp 1404 Fish'n Crisp Grilled chicken B202 Double BBQ Beef M101 Double Mushroom M101 Double Mushroom C303 Grilled Chicken B202 Double BBQ Beef 7404 Fish'n Crisp M101 Double Mushroom C303 Grilled Chicken B202 Double BBQ Beef C303 11.50 10.20 7.00 6.25 6.25 7.00 10.20 11.50 11.50 7.00 10.20 6.25 11.50 7.00 10.20 14.95 13.26 9.10 8.12 8.12 9.10 13.26 14.95 14.95 9.10 13.26 8.12 14.95 9.10 13.26 12 21 15 9 27 25 16 9 41.40 64.26 31.50 16.88 50.62 52.50 48.96 31.05 48.30 54.60 94.86 24.38 31.05 79.80 100.98 26 31 13 9 38 33 Figure 2: Expected output for Task 4 Task 5: Write a function named displayAnalysis. (17 marks) a) This is a non-returning function. b) It takes an array of Item of type struct and the number of items calculated in Task 2 as input parameters. c) The function should display items' names and total profit for each item. d) The function should also calculate and display the total amount of profit for all items and the highest profit. c) Figure 3 shows an example of the output that will be displayed on the screen based on the data in the input file "input.txt" shown in Figure 1. ITEM NAME Double Mushroom Double BBQ Beef Grilled Chicken Fish'n Crisp TOTAL PROFIT (RM) 151.80 309.06 218.40 91.BB The total amount of profit - RM 527.46 Highest profit - RM 309.06 Figure 3: Expected output for Task 5 Task 6: Write a main function to perform the following tasks: (5 marks) a) Declare one-dimensional array variable with 50 elements for a structure type Item b) The function may need to call the functions that are defined in the previous task to produce the output as shown in Figure 4. Note: Please use proper output formatting. c) Figure 4 shows the complete output that will be displayed on the screen based on the data in the input file "input.txt" shown in Figure 1. CODE ITEM NAME COST (RM) SALE (RM) QUANTITY PROFIT (RM) M101 B202 C303 F404 F404 C303 B202 M101 M101 C303 3202 F404 M101 C303 3202 Double Mushroom Double BBQ Beef Grilled chicken Fish'n Crisp Fish'n Crisp Grilled Chicken Double BBQ Beef Double Mushroom Double Mushroom Grilled Chicken Double BBQ Beef Fish'n Crisp Double Mushroom Grilled chicken Double BBQ Beef 11.50 10.20 7.00 6.25 6.25 7.00 10.20 11.50 11.50 7.00 10.20 6.25 11.50 7.00 10.20 14.95 13.26 9.10 8.12 8.12 9.10 13.26 14.95 14.95 9.10 13.26 8.12 14.95 9.10 13.26 12 21 15 9 27 25 16 9 14 26 31 13 9 38 33 41.40 64.26 31.50 16.88 50.62 52.50 48.96 31.05 48.30 54.60 94.86 24.38 31.05 79.80 100.98 ITEM NAME Double Mushroom Double BBQ Beef Grilled chicken Fish'n Crisp TOTAL PROFIT (RM) 151.80 309.06 218.40 91.88 The total amount of profit - RM 527.46 Highest profit - RM 309.06 Figure 4: Complete output for the data from the input file "input.txt" Task 7: List all function prototypes. (4 marks) (5 marks) Task 8: You must ensure your program fulfill the following criteria: a) The program is able to run. b) All required header files are includedStep 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