Question 15
AQA Computer Science November 2020 Paper 1 (7516/1)AS13 marks
On the specification
- 15.1
- 3.1 Fundamentals of programming3.2 Fundamentals of data structures3.5 Fundamentals of data representation
- 15.2
- 3.3 Systematic approach to problem solving
Question text
15 This question extends the functionality of the Skeleton Program. A new option, C, is to be added to compress an existing ASCII art image file using run-length encoding and store it in a new file. The number of symbols in a run of symbols is to be counted and this count, separated by a comma from the symbol, is stored in the new file. Each count and symbol pair should be put on a new line. For example, Figure 6 shows the contents of the ascii.txt data file. Figure 6 TestImage1,5,3,A ###@@@@@AABB!!! The compressed file will contain the file header followed by several value pairs and the file type in the header should be changed from A to C, as shown in Figure 7. Figure 7 TestImage1,5,3,C 3,# 5,@ 2,A 2,B 3,! You can assume that there are no newline characters in the ASCII art image file. What you need to do: Task 1 Write a new subroutine, CompressFile This subroutine is to: • ask the user for the name of the file to be compressed • read the existing file header and change the file type to C to indicate that this is a compressed file • create a new file with the existing filename preceded by CMP, for example, if the file read in was image2 the new filename should be CMPimage2 • save the edited file header to the new file • save each pair of symbol count and symbol separated by a comma on a new line to the new file. Task 2 Amend subroutine DisplayMenu to include the new option: C – Compress file Task 3 Amend subroutine Graphics to call CompressFile when the user chooses option C Task 4 Test that the changes you have made work by conducting the following test: • run the program • enter C • enter the file name image2 • load the file CMPimage2 into a text editor. Evidence that you need to provide Include the following evidence in your Electronic Answer Document. 15.1 Your PROGRAM SOURCE CODE for the entire subroutine CompressFile [12 marks] 15.2 SCREEN CAPTURE(S) showing the requested test, including the menu and all of the contents of the file CMPimage2 in the text editor. [1 mark]