A computer program will store data about trees. The user can enter their requirements for a tree and a suitable tree will be selected. The program is written using object-oriented programming. The class Tree stores data about the trees. Tree TreeName : STRING stores the name of the tree HeightGrowth : INTEGER stores the number of cm the tree will grow each year MaxHeight : INTEGER stores the maximum height in cm that the tree will grow MaxWidth : INTEGER stores the maximum width in cm that the tree will grow Evergreen : STRING stores whether the tree keeps its leaves as "Yes", or loses its leaves as "No" Constructor() initialises TreeName, HeightGrowth, MaxHeight, MaxWidth and Evergreen to its parameter values GetTreeName() returns the name of the tree GetGrowth() returns the number of cm the tree will grow each year GetMaxHeight() returns the maximum height in cm that the tree will grow GetMaxWidth() returns the maximum width in cm that the tree will grow GetEvergreen() returns whether the tree keeps its leaves or loses its leaves
- (a)(i)Write program code to declare the class Tree and its constructor. Do not declare the other methods. Use the appropriate constructor for your programming language. All attributes must be private. If you are writing in Python, include attribute declarations using comments.[4]
- (a)(ii)The get methods GetTreeName(), GetGrowth(), GetMaxHeight(), GetMaxWidth() and GetEvergreen() each return the relevant attribute. Write program code for the get methods.[3]
- (b)The text file Trees.txt stores data about 9 trees. The data in the file is stored in the format: Tree name, Height growth each year, Maximum height, Maximum width, Evergreen For example, the first row of data is: Beech,30,400,200,No The tree is a Beech. It can grow 30 cm each year. It has a maximum height of 400 cm. It has a maximum width of 200 cm. It is not evergreen (it loses its leaves). The function ReadData(): • creates an array of type Tree • reads the data from the file • raises an exception if the file is not found • creates a new object of type Tree for each tree in the file • appends each object to the array • returns the array. Write program code for ReadData().[7]
- (c)The procedure PrintTrees() takes a Tree object as a parameter and outputs the tree's name, height growth each year, maximum height, maximum width and whether it is evergreen. The output message changes depending on whether it is evergreen. If it is evergreen, it is in the format: TreeName has a maximum height MaxHeight a maximum width MaxWidth and grows HeightGrowth cm a year. It does not lose its leaves. If it is not evergreen, it is in the format: TreeName has a maximum height MaxHeight a maximum width MaxWidth and grows HeightGrowth cm a year. It loses its leaves each year. Write program code for PrintTrees().[4]
- (d)(i)Write program code for the main program.[2]
- (d)(ii)Test your program. Take a screenshot of the output(s).[1]
- (e)(i)Write program code for ChooseTree().[6]
- (e)(ii)The procedure ChooseTree() needs amending. After the procedure has output the list of trees that meet all the requirements, the procedure needs to: • take as input the name of one of the trees that the user would like to buy from those that meet all the requirements • take as input the height of the tree in cm when it is bought • calculate and output how many years it will take the tree to grow to its maximum height. For example, the user inputs the tree, Beech. The tree's height is 40 cm when bought. The tree will take 12 years to reach its maximum height of 400 cm. Write program code to amend ChooseTree().[2]
- (e)(iii)Write program code to amend the main program to call ChooseTrees(). Test your program with the following tree requirements: • a maximum height of 400 cm • a maximum width of 200 cm • a tree that is evergreen (does not lose its leaves). When asked for the tree selection, use the following data: • first tree name entered is 'Blue Conifer' • starting height is 100 cm. Take a screenshot of the outputs.[2]
Mark scheme
Marking points from the official mark scheme (May/June 2024). The mark or mark type is shown in brackets.
- [4] 1 mark each to max 4 • Class Tree declaration (and end where appropriate) • All 5 attributes declared as private with correct identifiers and data types • Constructor header (and end) taking 5 parameters • Constructor assigns parameters to attributes
- [3] 1 mark each • 1 get method with no parameter ... • ... returning correct attribute • Remaining 4 correct
- [7] 1 mark for: • appropriate use of exception handling, with catch and output 1 mark each to max 6 • Function header (and end where appropriate) and declaration of array (of type Tree with min 9 elements) • Opening text file Trees.txt to read and closing the file • Reading each line of text (until EOF, or 9 times) • Splitting each line into the 5 elements • casting height growth, max height and max width to integers • creating a new object of type Tree with the 5 values • storing each object in the array and returning the array
- [4] 1 mark each • Procedure heading (and end) taking one parameter (of type Tree) and using get methods to access tree name, height, width, growth • Outputs all 4 attributes (TreeName, MaxHeight, MaxWidth, GetGrowth) • Checks if it is evergreen... • ... correct messages are output if evergreen and otherwise
- [2] 1 mark each • Calling ReadData() and storing/using return value (as array of type Tree)... • ...calling PrintTrees() with first object in returned array as parameter
- [1] Screenshot showing output
- [6] 1 mark each to max 6 • Procedure header (and close) taking array of Tree objects as a parameter and reading evergreen, max height and max width once as input from the user • Looping through each array object ... • ... comparing each width input >= MaxWidth, height input >= MaxHeight • ... comparing each evergreen input with Evergreen • ... when all true (all requirements met) - appending object in new array • Calling PrintTrees() with each valid object • Outputting suitable message if no trees appropriate
- [2] 1 mark each to max • Taking tree name and initial height as input • Finding the tree, calculating and outputting the number of years to get to maximum height
- [2] 1 mark each • Screenshot shows the user requirements input (height 400, width 200, evergreen) and outputs the correct trees (Blue conifer and green conifer) • Screenshot shows the tree selection input (Blue Conifer with height 100) and outputs the correct result (3 years / 3.75 / 4 years)
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 →