Question 13

AQA Computer Science June 2022 Paper 1A (8525/1A)GCSE10 marks

On the specification

13.1
3.2 Programming
13.2
3.2 Programming
Question text

13 A program is being developed in C# to simulate a card game. box Throughout the game each player always has 100 cards. Each card displays a number. Players take it in turns to swap one of their cards with another random card from a set of cards until a player has a run of five numbers in sequence within their 100 cards. 13.1 Figure 14 shows part of the program that will get a player to enter the position of a card to swap. Figure 14 Console.Write("Enter card position: "); int position = Convert.ToInt32(Console.ReadLine()); Extend the program in Figure 14. Your answer must be written in C#. The program should keep getting the user to enter the card position until they enter a card position that is between 1 and 100 inclusive. You should use meaningful variable name(s) and C# syntax in your answer. The answer grid below contains vertical lines to help you indent your code. [4 marks] 13 2 box . There are 500 cards within the game in total. Each card is numbered from 1 to 250 and each number appears twice in the whole set of cards. The player’s 100 cards are always stored in numerical order. When a player has a valid run of five cards within their 100 cards they have won the game. A valid run: • consists of five cards • can start from any position in the player’s 100 cards • the second card’s value is one more than the first card’s value, the third card’s value is one more than the second card’s value, the fourth card’s value is one more than the third card’s value, and the fifth card’s value is one more than the fourth card’s value. Below are examples of valid runs which means a player has won. Valid run example 1 Valid run example 2 Below are examples of invalid runs. Invalid run example 1 Invalid run example 2 Invalid run example 3 Write a C# program to check if a player has a valid run of five cards within their 100 box cards. When writing your program you should assume: • there is an array called cards that contains the values of the player’s 100 cards • cards[0] will contain the value of the first card and cards[99] will contain the value of the last card • the values in cards are already stored in numerical order • there is a Boolean variable called gameWon that has a value of False. Your program should set gameWon to True if there is a valid run. You should use meaningful variable name(s) and C# syntax in your answer. The answer grid below contains vertical lines to help you indent your code. [6 marks]