Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a complete CH program. The program uses various types of structured data developed to calculate the profit of each item, the total amount of
Write a complete CH 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). 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 "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 Write a complete CH 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). 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 "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
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