0% found this document useful (0 votes)
5 views9 pages

Software Development - Problem Solving

This document outlines a Grade 12 Information Technology lesson focused on software development and problem-solving skills, specifically related to a rainfall application. It includes details on resources, concepts, skills, and activities, as well as a scenario involving the manipulation of two-dimensional arrays for rainfall data. The document provides specific coding tasks for buttons in the application to display rainfall data, calculate averages, create graphs, and add new rainfall data.

Uploaded by

fezekankomo8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views9 pages

Software Development - Problem Solving

This document outlines a Grade 12 Information Technology lesson focused on software development and problem-solving skills, specifically related to a rainfall application. It includes details on resources, concepts, skills, and activities, as well as a scenario involving the manipulation of two-dimensional arrays for rainfall data. The document provides specific coding tasks for buttons in the application to display rainfall data, calculate averages, create graphs, and add new rainfall data.

Uploaded by

fezekankomo8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

INFORMATION TECHNOLOGY: GRADE 12

TERM 3 Week 4
TOPIC Software Development – Problem Solving
AIMS OF LESSON Develop problem solving skills
RESOURCES Paper based resources Digital resources DBE Textbooks
Gr 12 – Chapter 3 Links on the WCED ePortal: DataFiles
The e-resources below has the actual URL to the websites
INTRODUCTION Reinforce problem solving principals
CONCEPTS AND Two-dimensional array Decision making
SKILLS Loops / nested loops Random numbers
Sting manipulation
ACTIVITIES / Open the incomplete project RainfallApp_p
ASSESSMENT This incomplete project has no functionality.

Scenario: Rainfall
You have been contacted to help with the capture and calculations of rainfall for SA Weather.
You have been supplied with an incomplete program, RainfallApp_p, with the following arrays.

arrRainfall: A two-dimensional array that contains the data for 2016 – 2019 rainfall per month.
arrRainfall: array [1 .. 4, 1 .. 12] of Double = ((3.80, 42.86, 39.70, 5.49,
19.52, 8.60, 25.24, 3.40, 14.59, 74.53, 47.30, 34.85),
(24.38, 0.49, 21.87, 1.79, 3.22, 7.37, 13.73, 1.56, 4.15, 31.74, 22.39,
10.25), (5.55, 21.43, 57.54, 14.71, 9.30, 14.22, 2.02, 3.21, 0.00, 29.47,
1.12, 8.63), (18.63, 15.94, 71.63, 6.83, 21.15, 17.26, 38.06, 2.75, 31.54,
34.21, 10.73, 12.33));
arrMonths: An array that contains the months of the year.
arrMonths: array [1 .. 12] of string = (
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct',
'Nov', 'Dec');
arrYears: An array that contains the years.
arrYears: array [1 .. 4] of Integer = (2019, 2018, 2017, 2016);

1 Button [Display]
Add code for this button to do the following:
• Display the rainfall in neat columns
• Use the arrMonths and arrYears for column and row headings
INFORMATION TECHNOLOGY: GRADE 12
Example output

2 Button [Rainfall per Term]


Add code for this button to do the following:
• Calculate and display the total rainfall for each term of the year i.e. Jan to March is Term 1 etc.
• The output should be in neat columns and formatted to two decimal places

Example output

3 Button [Graph]
A bar graph is a visual way to see how much it rained in a specific month.
Add code to this button to do the following:
• Use speMonth to determine the month
• Add a X on the redOutput for every 5mm of rain next to the year.
Example Output before the new year is added

4 Button [Add Rainfall]


This program only stores data for the past four years. When a new years’ data is added, the oldest
year is removed from arrRainfall and the rest of the data is shifted to accommodate the new years’
data.
The new years’ rainfall will be added as a CSV (comma separated values) line. The CSV line will be
added into edtRainfall. You can expect all twelve months’ rainfall (from January to December)
separated by a comma in the CSV line.
For testing purposes, a CSV line has been added to the edtRainfall.
Add code for this button to do the following:
• Move the data in arrRainfall and arrYears to accommodate the new years’ rainfall
• Extract the rainfall for the new year from edtRainfall and add it to the arrRainfall
• Display a message if the process is completed.
INFORMATION TECHNOLOGY: GRADE 12
Example Output

CONSOLIDATION In this problem, you worked with a two-dimensional array and used problem solving
techniques.
VALUES Thank you for working through this document! Stick to your hard work. You are
creating an opportunity to better yourself. Your perseverance will bring dividends.
E-RESOURCES Data Files: https://wcedeportal.co.za/eresource/135351
Term 3 Week 3 – Solutions – PlantIO_P
1 btnDisplay
Add code for this button to do the following:
• Display the array with column and row heading on redOutput component.
• The output should be formatted with a line between every second row.
procedure TForm1.btnDisplayClick(Sender: TObject);
var
I: Integer;
J: Integer;
sLine: String;
begin
redOutput.Clear;
sLine := #9;
for I := 1 to 20 do
sLine := sLine + intToStr(I) + #9;
redOutput.Lines.Add(sLine);
for I := 1 to 6 do
begin
sLine := intToStr(I) + #9;
for J := 1 to 20 do
begin
sLine := sLine + arrPlant[I, J] + #9;
end;
redOutput.Lines.Add(sLine);
if I mod 2 = 0 then
begin
redOutput.Lines.Add('');
INFORMATION TECHNOLOGY: GRADE 12
end;
end;
end;
2 btnAdd
Add code for this button to do the following:
• Get the selected plant from the radio group
• Get the position the plant should be planted from the input box. You can expect the input in the
following format: <Row><Space><Column>
Example: 5 17
• You should check if the space is available for a plant. Display a message to indicate the space is
available and add the selected plant to the array at that index. Display an error message when
the space in not available.
procedure TForm1.btnAddClick(Sender: TObject);
var
sInput: String;
iIndex1, iIndex2: Integer;
begin
sInput := edtPos.Text;
iIndex1 := StrToInt(sInput[1]);
iIndex2 := StrToInt(Copy(sInput, 3));
if (arrPlant[iIndex1, iIndex2] = ' ') then
begin
arrPlant[iIndex1, iIndex2] := rdgAddCrop.Items[rdgAddCrop.ItemIndex][1];
ShowMessage(rdgAddCrop.Items[rdgAddCrop.ItemIndex] + ' was added to '
+ sInput);
end
else
begin
ShowMessage('Sorry, no space');
end;
redOutput.Clear;
btnDisplay.Click;
end;
3 btnAmount
Add code for this button to do the following
• Get the selected plant from the combo box
• Run through the two-dimensional array and count how many of the selected plants are in the
garden.
• Display the amount on the redOutput component. The output should be in the following format
<plant>: <amount>
Example if carrots were selected: Carrots: 21
function TForm1.countPlant(sPlant: String): Integer;
var
I: Integer;
J: Integer;
iTotal: Integer;

begin
iTotal := 0;
if sPlant = 'E' then
sPlant := ' ';
INFORMATION TECHNOLOGY: GRADE 12
for I := 1 to 6 do
begin
for J := 1 to 20 do
begin
if arrPlant[I, J] = sPlant then
begin
Inc(iTotal);
end;
end;
end;
Result := iTotal;
end;

procedure TForm1.btnAmountClick(Sender: TObject);


begin
redOutput.Lines.Add
(cmbPlants.Text + ': ' +
intToStr(countPlant(cmbPlants.Items[cmbPlants.ItemIndex][1])));
end;
4 btnPlant
Add code for this button to do the following:
• Get the plant the user wants to plant in the garden via an input box. The user is expected to type
in the letter of the plant. This should be converted to a capital letter and checked against the list
of the plant that is allowed in the garden.
• Get the amount the user wants to plant from the spin edit.
• Add the plants to the array at random positions.

procedure TForm1.btnPlantClick(Sender: TObject);


var
iRandom1, iRandom2, iAmount, iSpaceAvailable: Integer;
sInput: String;
bFlag: Boolean;
I: Integer;
begin
sInput := UpperCase(InputBox('Plant', 'What plant?', ''));
iAmount := speAmount.Value;
iSpaceAvailable := countPlant('E');
if iAmount > iSpaceAvailable then
begin
ShowMessage('No space for all the plants');
exit;
end;
for I := 1 to iAmount do
begin
if sInput[1] in ['L', 'T', 'C', 'H'] then
begin
repeat
bFlag := false;
iRandom1 := RandomRange(1, 7);
iRandom2 := RandomRange(1, 21);
if arrPlant[iRandom1, iRandom2] = ' ' then
begin
bFlag := true;
arrPlant[iRandom1, iRandom2] := sInput[1];
INFORMATION TECHNOLOGY: GRADE 12
end;
until (bFlag);
end
else
begin
ShowMessage('Not a valid crop.');
exit;
end;
end;
ShowMessage(intToStr(iAmount) + ' plants planted');
end;
5 Button [Rainfall per Term]
Add code for this button to do the following:
• Calculate and display the total rainfall for each term of the year i.e. Jan to March is Term 1 etc.
• The output should be in neat columns and formatted to two decimal places
procedure TForm1. btnRainfallPerTermClick(Sender: TObject););
var
sDelete: String;
I: Integer;
J: Integer;
begin
sDelete := rdgDeleteCrop.Items[rdgDeleteCrop.ItemIndex][1];
for I := 1 to 6 do
begin
for J := 1 to 20 do
begin
if arrPlant[I, J] = sDelete then
arrPlant[I, J] := ' ';
end;
end;
end;

Term 3 Week 4 – Solutions – Rainfall


1 Button [Display]
Add code for this button to do the following:
• Display the rainfall in neat columns
• Use the arrMonths and arrYears for column and row headings

procedure TForm1.btnDisplayClick(Sender: TObject);


var
I, J: Integer;
sLine: String;
begin
sLine := '';
for I := 1 to 4 do
sLine := sLine + #9#9 + intToStr(arrYears[I]);
redOutput.Lines.Add(sLine);
for I := 1 to 12 do
begin
sLine := arrMonths[I] + #9#9;
for J := 1 to 4 do
begin
sLine := sLine + floatToStrF(arrRainfall[J, I], ffFixed,20,2) + #9#9;
INFORMATION TECHNOLOGY: GRADE 12
end;
redOutput.Lines.Add(sLine);
end;
end;
2 Button [Average]
Add code for this button to do the following:
• Calculate and display the average of each years’ terms.
• The output should be in neat columns and formatted to two decimal places
procedure TForm1.btnAverageClick(Sender: TObject);
var
dTerm1, dTerm2, dTerm3, dTerm4: Double;
I: Integer;
J: Integer;

begin
redOutput.Clear;
redOutput.Lines.Add('Average rainfall per term');
redOutput.Lines.Add('');
redOutput.Lines.Add(format('%15s%12s%12s%12s', ['Term 1', 'Term 2', 'Term
3',
'Term4']));
for I := 1 to 4 do
begin
dTerm1 := 0;
dTerm2 := 0;
dTerm3 := 0;
dTerm4 := 0;
for J := 1 to 12 do
Begin
case J of
1 .. 3:
dTerm1 := dTerm1 + arrRainfall[I, J];
4 .. 6:
dTerm2 := dTerm2 + arrRainfall[I, J];
7 .. 9:
dTerm3 := dTerm3 + arrRainfall[I, J];
10 .. 12:
dTerm4 := dTerm4 + arrRainfall[I, J];
end;
End;
redOutput.Lines.Add(format('%d:%10.2fmm%10.2fmm%10.2fmm%10.2fmm',
[arrYears[I], dTerm1, dTerm2, dTerm3, dTerm4]));
end;
end;
3 Button [Graph]
A bar graph is a visual way to see how much it rained in a specific month.
Add code to this button to do the following:
• Use speMonth to determine the month
• Add a X on the redOutput for every 5mm of rain next to the year.

procedure TForm1.btnGraphClick(Sender: TObject);


var
iMonth : Integer;
INFORMATION TECHNOLOGY: GRADE 12
I: Integer;
dTemp : Double;
sLine : String;

begin
redOutput.Clear;
iMonth := speMonth.Value;
redOutput.Lines.Add('Rainfall graph for: '+ arrMonths[iMonth]);
redOutput.Lines.Add('');

for I := 1 to 4 do
begin
dTemp := arrRainfall[I, iMonth];
sLine := intToStr(arrYears[I]) + #9;

while dTemp - 5 > 0 do


begin
sLine := sLine + 'X';
dTemp := dTemp - 5;
end;
redOutput.Lines.Add(sLine);
end;
end;
4 Button [Add Rainfall]
Add code for this button to do the following:
• Move the data in arrRainfall and arrYears to accommodate the new years’ rainfall
• Extract the rainfall for the new year from edtRainfall and add it to the arrRainfall
• Display a message if the process is completed.
procedure TForm1.btnAddRainfallClick(Sender: TObject);
var
I: Integer;
J: Integer;
sLine: String;
iPos, iCounter: Integer;
dRainfall: Double;

begin
for I := 4 downto 2 do
begin
for J := 1 to 12 do
begin
arrRainfall[I, J] := arrRainfall[I - 1, J];
end;
end;
for I := 1 to 4 do
arrYears[I] := arrYears[I] + 1;
sLine := edtRainfall.Text;
iCounter := 1;
while iCounter <= 12 do
begin
if iCounter < 12 then
begin
iPos := Pos(',', sLine);
end;
INFORMATION TECHNOLOGY: GRADE 12
dRainfall := strToFloat(copy(sLine, 1, iPos - 1));
Delete(sLine, 1, iPos);
arrRainfall[1, iCounter] := dRainfall;
Inc(iCounter);
end;
ShowMessage('New rainfall added');
end;

You might also like