The trees at the nursery are categorised using the types Citrus, Deciduous, Nut, and Tropical - NSC Information Technology - Question 4 - 2019 - Paper 1
Question 4
The trees at the nursery are categorised using the types Citrus, Deciduous, Nut, and Tropical.
Do the following:
- Open the incomplete program in the Question 4 fo... show full transcript
Worked Solution & Example Answer:The trees at the nursery are categorised using the types Citrus, Deciduous, Nut, and Tropical - NSC Information Technology - Question 4 - 2019 - Paper 1
Step 1
Button [4.1 - Separate by type]
96%
114 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
To solve this part, follow these steps:
Initialize Loop: Set up a loop that iterates from 1 to the number of types in arrTypes (iTypes).
Set Column: For each iteration, initialize the column value to 0.
Nested Loop: Add a nested loop that iterates through each tree in arrList from index 1 to 24.
Character Test: Check the first character of each tree in arrList at the current index against the values in arrTypes.
For example, if the last character of arrList is 'C', use it to determine the tree's type.
Store by Type: Based on the type determined, increase the column for arrTrees[row, column] storing the value accordingly.
Enable Buttons: After processing all entries, enable buttons btnQ4_2 and btnQ4_3.
Step 2
Button [4.2 - Display]
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
To display the information, execute the following:
Initialize Loop: Set up a loop that again iterates from 1 to the number of types (iTypes).
String Variable: Declare a string variable sLine initialized to an empty string for each row.
Nested Loop: Create another loop to iterate through each column up to the number of trees in that type (iNum).
Concatenate Values: For each entry (arrTrees[row, col]), concatenate it to sLine followed by a space for better formatting.
Display Output: Finally, print the value of sLine to the output area.
Step 3
Button [4.3 - Sort alphabetically]
96%
101 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
To handle the sorting, perform the following steps:
Initialize Outer Loop: Loop from 1 to iTypes to iterate over each type of tree.
Remove Characters: For each tree, strip the last two characters. Use a loop from 1 to iNum and do the following:
For each arrTrees[row, col], execute the substring operation to remove the unwanted characters.
Sorting Algorithm: Implement a sorting mechanism to arrange arrTrees[row] in alphabetical order according to tree names.
Execute Button: Run the code in button btnQ4_2 to ensure and display the sorted list of trees.