Question 4
AQA Computer Science June 2023 Paper 1A (8525/1A)GCSE4 marks
On the specification
- 4.1
- 3.1 Fundamentals of algorithms3.2 Programming
- 4.2
- 3.2 Programming
Question text
4 Figure 3 shows a program written in C# that calculates the area of a rectangle or the box volume of a box from the user inputs. Figure 3 public static int calculate(int width, int length, int height) { if (height == -1) { return width * length; } else { return width * length * height; } } public static void Main() { int numOne, numTwo, numThree, answer; Console.Write("Enter width: "); numOne = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter length: "); numTwo = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter height, -1 to ignore: "); numThree = Convert.ToInt32(Console.ReadLine()); answer = calculate(numOne, numTwo, numThree); if (numThree == -1) { Console.WriteLine($"Area {answer}"); } else { Console.WriteLine($"Volume {answer}"); } } 4.1 Complete the trace table using the program in Figure 3. [3 marks] numOne numTwo numThree Final output 56 –1 10 4 0 35 10 4.2 Describe one way that the program in Figure 3 could be made more robust. box [1 mark]