Practice
Tree Class Summary
2024/May/June·Variant 1·Q2
HARDObject-Oriented Programming
Adapted from Cambridge International AS & A Level Computer Science (9618), May/June 2024 Paper 41, Question 2.
Declare class Tree with private attributes:
TreeNameHeightGrowthMaxHeightMaxWidthEvergreen
Write the constructor and getter methods. Then write procedure PrintTree(Item) that outputs a formatted summary. If Evergreen is "No", the final phrase must be loses its leaves each year; otherwise it must be does not lose its leaves.
The test harness reads one tree, creates the object, and calls PrintTree().
Input: Name, growth, maximum height, maximum width, evergreen value. Output: One formatted sentence.
Example:
Input: Oak
30
20
12
No
Output: Oak has a maximum height 20 a maximum width 12 and grows 30 cm a year. It loses its leaves each year
Premium is coming soon. All grading features are currently unlocked.
Sample Test Cases
Test 1: Deciduous tree
Inputs: Oak, 30, 20, 12, No
Expected: Oak has a maximum height 20 a maximum width 12 and grows 30 cm a year. It loses its leaves each year
Test 2: Evergreen tree
Inputs: Pine, 25, 30, 8, Yes
Expected: Pine has a maximum height 30 a maximum width 8 and grows 25 cm a year. It does not lose its leaves