Photo AI

The trees at the nursery are categorised using the types Citrus, Deciduous, Nut, and Tropical - NSC Information Technology - Question 4 - 2019 - Paper 1

Question icon

Question 4

The-trees-at-the-nursery-are-categorised-using-the-types-Citrus,-Deciduous,-Nut,-and-Tropical-NSC Information Technology-Question 4-2019-Paper 1.png

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

Answer

To solve this part, follow these steps:

  1. Initialize Loop: Set up a loop that iterates from 1 to the number of types in arrTypes (iTypes).
  2. Set Column: For each iteration, initialize the column value to 0.
  3. Nested Loop: Add a nested loop that iterates through each tree in arrList from index 1 to 24.
  4. 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.
  5. Store by Type: Based on the type determined, increase the column for arrTrees[row, column] storing the value accordingly.
  6. Enable Buttons: After processing all entries, enable buttons btnQ4_2 and btnQ4_3.

Step 2

Button [4.2 - Display]

99%

104 rated

Answer

To display the information, execute the following:

  1. Initialize Loop: Set up a loop that again iterates from 1 to the number of types (iTypes).
  2. String Variable: Declare a string variable sLine initialized to an empty string for each row.
  3. Nested Loop: Create another loop to iterate through each column up to the number of trees in that type (iNum).
  4. Concatenate Values: For each entry (arrTrees[row, col]), concatenate it to sLine followed by a space for better formatting.
  5. Display Output: Finally, print the value of sLine to the output area.

Step 3

Button [4.3 - Sort alphabetically]

96%

101 rated

Answer

To handle the sorting, perform the following steps:

  1. Initialize Outer Loop: Loop from 1 to iTypes to iterate over each type of tree.
  2. 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.
  3. Sorting Algorithm: Implement a sorting mechanism to arrange arrTrees[row] in alphabetical order according to tree names.
  4. Execute Button: Run the code in button btnQ4_2 to ensure and display the sorted list of trees.

Join the NSC students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

;