A computer program is designed to simulate horses doing show jumping. In show jumping, horses jump over obstacles called fences. A horse successfully jumps a fence if it does not knock the fence down. The program is written using Object-Oriented Programming (OOP). The class Horse stores data about the horses. Horse Name : STRING stores the name given to the horse MaxFenceHeight : INTEGER stores the maximum height in cm that the horse can jump, for example 132 PercentageSuccess : INTEGER stores the percentage chance of a horse not knocking down a fence, for example 70 represents a 70% chance of jumping a fence successfully Constructor() initialises Name, MaxFenceHeight and PercentageSuccess to its parameter values GetName() returns the name of the horse GetMaxFenceHeight() returns the maximum height the horse can jump Success() calculates and returns the percentage chance of a horse successfully jumping a specific fence
- (a)(i)Write program code to declare the class Horse and its constructor. Do not declare the other methods. Use your programming language's appropriate constructor. All attributes must be private. If you are writing in Python, include attribute declarations using comments. Save your program as Question2_N24. Copy and paste the program code into part 2(a)(i) in the evidence document.[4]
- (a)(ii)The get methods GetName() and GetMaxFenceHeight() each return the relevant attribute. Write program code for the get methods. Save your program. Copy and paste the program code into part 2(a)(ii) in the evidence document.[3]
- (b)(i)The array Horses stores objects of type Horse. The program has two horses: • The horse named 'Beauty' can jump a maximum height of 150 cm and has a success percentage rate of 72%. • The horse named 'Jet' can jump a maximum height of 160cm and has a success percentage rate of 65%. Write program code to: • declare the array, Horses, local to the main program with space for two Horse objects • store the two horses described in the array • output the name of both Horse objects from the array.[5]
- (b)(ii)Test your program. Take a screenshot of the output. Save your program. Copy and paste the screenshot into part 2(b)(ii) in the evidence document.[1]
- (c)(i)The class Fence stores data about the fences. Each fence has a height in cm and a risk number. The risk is a whole number between 1 and 5 inclusive. A risk of 1 means the fence is the easiest type to jump. A risk of 5 means the fence is the hardest type to jump. Fence Height : INTEGER stores the height of the fence in cm the height is between 70 and 180 inclusive Risk: INTEGER stores the risk as a whole number between 1 and 5 inclusive Constructor() initialises Height and Risk to its parameter values GetHeight() returns the height of the fence GetRisk() returns the risk of the fence Write program code to declare the class Fence, its constructor and get methods. Use your programming language's appropriate constructor. All attributes must be private. If you are writing in Python, include attribute declarations using comments. Save your program. Copy and paste the program code into part 2(c)(i) in the evidence document.[4]
- (c)(ii)The array Course stores four Fence objects. The user inputs the height and risk for each fence, and these are validated before each fence is created. Amend the main program to: • declare the local array Course • take as input the data for four fences from the user • loop the input until both the height and risk are valid for each fence • create an instance of Fence for each of the four valid fences and store each instance in the array. Save your program. Copy and paste the program code into part 2(c)(ii) in the evidence document.[5]
- (d)The chance of a horse jumping a fence without knocking it down is calculated as follows. If the height of the fence is more than the maximum height a horse can jump, the success percentage is 20% of the horse's PercentageSuccess. The risk does not affect this value. If the height of the fence is less than or equal to the maximum height a horse can jump, the risk gives a modifier value to multiply with the horse's PercentageSuccess. The risk values and their modifiers are given in this table: Risk Modifier 5 0.6 4 0.7 3 0.8 2 0.9 1 1.0 For example: • The horse Jet has PercentageSuccess of 65 and MaxFenceHeight of 160. • A fence has a height of 140 and a risk of 3. • The height of the fence is less than the horse's MaxFenceHeight, therefore the risk is used. • The risk of 3 gives the modifier 0.8. • The modifier 0.8 is multiplied by the horse's PercentageSuccess of 65, which gives 52. • The chance of the horse successfully jumping this fence is 52%. The method Success() in the Horse class: • takes the height and risk of a fence as parameters • calculates the percentage chance of success for that horse jumping the fence without knocking it down • returns the calculated percentage chance of success as a real number. Write program code for Success(). Save your program. Copy and paste the program code into part 2(d) in the evidence document.[5]
- (e)(i)Write program code to amend the main program to: • calculate and output the chance of the first horse jumping each of the four fences without knocking each fence down • calculate and output the chance of the second horse jumping each of the four fences without knocking each fence down. All outputs must have appropriate messages including the name of the horse and the fence number. An example output for one horse jumping two fences is: "The horse Fox at fence 1 has a 68% chance of success The horse Fox at fence 2 has a 72% chance of success" Save your program. Copy and paste the program code into part 2(e)(i) in the evidence document.[3]
- (e)(ii)Write program code to amend the main program to: • calculate and output the average chance of success for each horse jumping over all four fences without knocking each fence down (the average is the total of values divided by the quantity of values). An example output for one horse jumping all of the fences is: "The horse Fox has an average 70% chance of jumping over all four fences" • output the name of the horse that has the highest average chance of success. You can assume that each average will be different. All outputs must have appropriate messages. Save your program. Copy and paste the program code into part 2(e)(ii) in the evidence document.[2]
- (e)(iii)Test your program with the following input data for four fences: Height Risk 152 5 121 1 130 3 145 4 Take a screenshot of the output. Save your program. Copy and paste the screenshot into part 2(e)(iii) in the evidence document.[2]
Mark scheme
Marking points from the official mark scheme (Oct/Nov 2024). The mark or mark type is shown in brackets.
- [4] 1 mark each: Class Horse declaration (and end where appropriate)
- [4] All 3 attributes declared as private with appropriate data types (declaration or comment)
- [4] Constructor header (and end) taking 3 parameters (constructor must be within class)
- [4] ... constructor assigns parameters to attributes
- [3] 1 mark each: 1 get method header with no parameter ...
- [3] ... returning correct attribute (without change)
- [3] 2nd get method correct
- [5] 1 mark each: Instantiating one object of type Horse with correct data ...
- [5] ... and storing in first element of a 1D array Horses
- [5] Instantiating second object of type Horse with correct data and storing in second index of the array
- [5] Outputting name of both horse objects from array ...
- [5] ... using GetName()
- [1] 1 mark for both names output: Beauty Jet
- [4] 1 mark each: Class Fence header (and end where appropriate) with no inheritance
- [4] Height and Risk private with integer data type
- [4] Constructor taking 2 parameters and storing in attributes (constructor must be within class)
- [4] 2 get methods (no parameter) returning correct attributes (within class)
- [5] 1 mark each to max 5: Declaration/use of array Course of type Fence (with at least 4 elements)
- [5] Taking Height and Risk as input four times and store/use
- [5] Instantiating a Fence object for each set of valid input values and storing in array
- [5] Taking each height as input until it is between 70 and 180 (inclusive)
- [5] Taking each risk as input until it is between 1 and 5 (inclusive)
- [5] 1 mark each: Method header taking 2 parameters (and end where appropriate, returning real)
- [5] Checking if fence height parameter is more than max attribute for that horse, if true multiplying percentage success by 0.2
- [5] (Otherwise) selection checking risk value parameter between 1 and 5, multiplying modifier by percentage success
- [5] Returning correct value as a real number in all instances
- [5] Correct use of attributes and parameters throughout
- [3] 1 mark each: Calling Success() for each horse with the height and risk of all 4 fences
- [3] ... using get methods for height and risk of each fence
- [3] Outputting the horse name, fence number and calculated success at fence in appropriate message
- [2] 1 mark each: Calculating average of all 4 fences for each horse and outputting in suitable message
- [2] Identifying the highest percentage of success and outputting the horse's name in an appropriate message
- [2] 1 mark each: Outputting showing correct input values for all fences, and correct chance for each horse on each jump
- [2] Outputs of average chance of each horse and horse name with highest average
Write your answer and get it marked
On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.
Sign up free →