Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedWrite 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 f) 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). 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. 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 3 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 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. 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. -------------------------------------------------------------------- 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 -------------------------------------------------------------------- 4 d) The function should also calculate and display the total amount of profit for all items and the highest profit. e) 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. 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. Figure 4: Complete output for the data from the input file "input.txt" -------------------------------------------------------------------- ITEM NAME TOTAL PROFIT(RM) Double Mushroom 151.80 Double BBQ Beef 309.06 Grilled Chicken 218.40 Fish'n Crisp 91.88 -------------------------------------------------------------------- The total amount of profit = RM 527.46 Highest profit = RM 309.06 -------------------------------------------------------------------- -------------------------------------------------------------------- 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 -------------------------------------------------------------------- ITEM NAME TOTAL PROFIT(RM) Double Mushroom 151.80 Double BBQ Beef 309.06 Grilled Chicken 218.40 Fish'n Crisp 91.88 -------------------------------------------------------------------- The total amount of profit = RM 527.46 Highest profit = RM 309.06 -------------------------------------------------------------------- 5 Task 7: List all function prototypes. (4 marks) Task 8: You must ensure your program fulfill the following criteria: (5 marks) a) The program is able to run. b) All required header files are included.

Question 165 Marks 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: (3 marks) Task 1: Declare a structure named Item, with the following members: a) Code b) Namne 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 F4049 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 2 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 M101 Double Mushroom B202 Double BBQ Beet C303 Grilled Chicken 5404 Fish'n Crisp 5404 Fish'n Crisp C303 Grilled Chicken B202 Double BBQ Beef M101 Double Mushroom M101 Double Mushroom C303 Grilled chicken B202 Double BBQ Beer 5404 Fish'n Crisp M101 Double Mushroom C303 Grilled chicken B202 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.30 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 9 27 25 16 9 14 26 31 13 9 38 33 PROFIT (RM) ------- 41.40 64.26 31.50 16.88 50.62 52.50 48.96 31.05 48.30 54.60 94.86 24.38 32.05 79.80 100.98 Figure 2: Expected output for Task 4 Task 5: Write a function named display Analysis. (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. The function should display items' names and total profit for each item. 3 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 Beet 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 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) 14.95 13.26 9.10 8.12 M101 Double Mushroom B202 Double BBQ Beef C303 Grilled chicken 404 Fish'n Crisp 3404 Fish'n Crisp C303 Grilled Chicken B202 Double BBQ Beef M101 Double Mushroom M101 Double Mushroom C303 Grilled Chicken B202 Double BBQ Beef 3404 Fish'n Crisp M101 Double Mushroom C303 Grilled Chicken B202 Double BBQ Beet 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 3.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 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" 4 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. 5

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

New Trends In Databases And Information Systems Adbis 2019 Short Papers Workshops Bbigap Qauca Sembdm Simpda M2p Madeisd And Doctoral Consortium Bled Slovenia September 8 11 2019 Proceedings

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Robert Wrembel ,Mirjana Ivanovic ,Johann Gamper ,Mikolaj Morzy ,Theodoros Tzouramanis ,Jerome Darmont

1st Edition

ISBN: 3030302776, 978-3030302771

More Books

Students also viewed these Databases questions