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 transcribed

image text in transcribed

image text in transcribedimage text in transcribed

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) 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). M101 12 B202 21 C303 15 F404 9 F404 27 C303 25 3202 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 "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. Cost (RM) 11.5 Code M101 B202 C303 F404 Table 1 Name Double Mushroom Double BBQ Beef Grilled Chicken Fish'n Crisp 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-retuming 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) 41.40 22 31.30 16.88 50.62 52.50 27 16 M101 B202 C303 5404 F404 C302 B202 M101 M101 C303 B202 5404 M101 C303 B202 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 31.05 54.60 31 13 24.36 31.05 79.80 100.96 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. 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. 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 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) 12 41.40 21 15 27 25 16 M102 B202 C303 F404 F404 C303 B202 M102 M102 C303 B202 F404 M102 C303 B202 Double Mushroom Double BBQ Bees Grilled Chicken Fish'n Crisp Fish'n Crisp Grilled Chicken Double BBQ Bees Double Mushroom Double Mushroom Grilled Chicken Double BBQ Bees Fish'n Crisp Double Mushroom Grilled Chicken Double BBQ Bees 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 31.50 16.88 50.62 52.50 48.96 31.05 48.30 54.60 14 26 31 13 24.30 31.05 79.80 100.90 33 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

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

More Books

Students also viewed these Databases questions

Question

Ty e2y Evaluate the integral dy

Answered: 1 week ago

Question

=+j Explain the relationship between unions and MNEs.

Answered: 1 week ago