Question 6

OCR Computer Science June 2022 Computer principles (H046-01)AS11 marks

On the specification

(a)
1.4 Data types, data structures and algorithms
(b)
2.2 Problem solving and programming
(c)
2.2 Problem solving and programming
Question text

6 George owns a small book shop. He wants a program to work out the daily sales figures. He uses a text file called “Sales.txt” shown in Fig. 1. Each line represents the sales total for a different day of the week. The program can run at any point during the week and therefore the text file may not have seven lines. 2367.34 1986.92 2251.49 1882.40 2412.83 3411.32 2721.76 Fig. 1 The program needs to read the text file and then calculate: • The number of days that the program is calculating over • The total sales over that period • The average daily sales over that period At the end of the text file, it should then print the results of these calculations to the screen. (a) When the values are being read from the Sales.txt file they will be a string data type. In order for them to be processed they will need to be cast (i.e. converted) to a different data type. Explain what data type the values in “Sales.txt” should be converted to. [2] (b) George will use iteration to read through the values in the text file. Describe how George can use iteration when reading from the text file. [2] (c) Write a procedure called salesAnalysis that will meet the rules of George’s program. You should write your procedure using pseudocode or program code. [7]