IT March 2013 Paper 1 MEMO
IT March 2013 Paper 1 MEMO
SENIOR CERTIFICATE
GRADE 12
INFORMATION TECHNOLOGY P1
FEBRUARY/MARCH 2013
MEMORANDUM
MARKS: 120
GENERAL INFORMATION
• These marking guidelines are to be used as the basis for the marking session.
They were prepared for use by markers, all of whom are required to attend a
rigorous standardisation meeting to ensure that the guidelines are consistently
interpreted and applied in the marking of candidates’ scripts.
• Note that learners who provide an alternate correct solution to that given in the
marking guidelines will be given full credit for the relevant question.
• ANNEXURES A, B and C (pages 3–6) include the marking grid for each question
for using either one of the two programming languages.
• ANNEXURES D, E and F (pages 7–16) contain the solutions for Delphi for
QUESTIONS 1 to 3 in programming code.
• ANNEXURES G, H, I and J (pages 17–29) contain the solutions for Java for
QUESTIONS 1 to 3 in programming code.
• Copies of ANNEXURES A, B and C (pages 3–6) should be made for each learner
and completed during the marking session.
ANNEXURE A
ANNEXURE B
QUESTION 2: MARKING GRID – OBJECT-ORIENTED PROGRAMMING
ANNEXURE C
QUESTION 3: MARKING GRID - PROBLEM-SOLVING PROGRAMMING
unit Question1U_MEMO;
//Solution for Question 1
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, Grids, DBGrids, ExtCtrls, Buttons, Menus;
type
TfrmRec = class(TForm)
qryRec: TADOQuery;
dsrQry: TDataSource;
grdRec: TDBGrid;
mnuMain: TMainMenu;
mnuOptionA: TMenuItem;
mnuOptionB: TMenuItem;
mnuOptionC: TMenuItem;
mnuOptionD: TMenuItem;
mnuOptionE: TMenuItem;
mnuOptionF: TMenuItem;
mnuOptionG: TMenuItem;
mnuQuit: TMenuItem;
procedure mnuOptionAClick(Sender: TObject);
procedure mnuOptionBClick(Sender: TObject);
procedure mnuOptionCClick(Sender: TObject);
procedure mnuOptionDClick(Sender: TObject);
procedure mnuOptionEClick(Sender: TObject);
procedure mnuOptionFClick(Sender: TObject);
procedure mnuOptionGClick(Sender: TObject);
procedure mnuQuitClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmRec: TfrmRec;
implementation
{$R *.dfm}
//=============================================================================
procedure TfrmRec.mnuOptionAClick(Sender: TObject);
begin
qryRec.Close;
qryRec.SQL.Text := 'SELECT * FROM tblTours ORDER BY Destination, StartDate
Desc';
qryRec.Open;
end;
//=============================================================================
procedure TfrmRec.mnuOptionBClick(Sender: TObject);
begin
qryRec.Close;
qryRec.SQL.Text := 'SELECT TourID, FirstName, Surname ' +
'FROM tblTourists ' +
'WHERE Surname LIKE "C%" AND FirstName LIKE "C%" AND ' +
'Gender = "F"';
qryRec.Open;
end;
//=============================================================================
Copyright reserved Please turn over
Information Technology/P1 8 DBE/Feb.–Mar. 2013
NSC – Memorandum
end.
CLASS UNIT:
unit uQuest2_MEMO;
//solution for Question 2 - class
interface
TYPE
TData = class(TObject)
private
fGName : String;
fDName : String;
fMName : String;
fNumD : Integer;
fNumT : Integer;
fTariff : Real;
public
function getGName : String;
function getDName : String;
function getMName : String;
function getNumD : Integer;
function getNumT : Integer;
function getTariff: Real;
implementation
uses SysUtils;
{ TData }
//=============================================================================
constructor TData.Create(sGuide, sDestination, sMonth: String; iDays, iNum:
Integer);
begin
fGName := sGuide;
fDName := sDestination;
fMName := sMonth;
fNumD := iDays;
fNumT := iNum;
setTariff;
end;
//=============================================================================
procedure TData.setTariff;
var
sMonth : String;
begin
sMonth := Uppercase(fMName);
//accept solution without the use of uppercase.
iF (sMonth = 'APRIL') OR (sMonth = 'SEPTEMBER') OR (sMonth = 'DECEMBER')
then
fTariff := 1250.00
else
iF (sMonth = 'MARCH') OR (sMonth = 'MAY') OR (sMonth = 'JUNE') OR (sMonth
= 'JULY')
then
Copyright reserved Please turn over
Information Technology/P1 10 DBE/Feb.–Mar. 2013
NSC – Memorandum
fTariff := 900.00
else
fTariff := 1000.00;
end;
//=============================================================================
function TData.shortenString: String;
var
a : Integer;
sTemp : String;
begin
sTemp := fMName[1];
for a := 2 to length(fMName) do
if NOT(Upcase(fMName[a]) in ['A','E','I','O','U'])
then sTemp := sTemp + fMName[a];
Result := sTemp;
//accept solution without upcase where small letters are added to set
end;
//=============================================================================
function TData.findLuckyChar: Char;
var
iMax, iLuckyNum : Integer;
begin
iMax := length(fDName);
Repeat
iLuckyNum := random(iMax)+1;
Until fDName[iLuckyNum] <> #32;
Result := fDName[iLuckyNum];
end;
//=============================================================================
function TData.toString: String;
begin
Result := 'Month: ' + shortenString + #13 +
'Destination: ' + fDName + ' with ' + fGName + ' as the tour
guide' + #13 +
'Price: ' + FloatToStrF(fTariff, ffCurrency, 9,2) + ' per day for
a period of '+ IntToStr(fNumD) + ' days' +
#13+InttoStr(fNumT) + ' tourists are taking this tour.';
end;
//=============================================================================
function TData.getGName: String;
begin
Result := fGName;
end;
end.
FORM UNIT:
unit Question2U_MEMO;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, Menus,
uQuest2_MEMO;
type
TfrmQ2 = class(TForm)
mnuMain: TMainMenu;
mnuOptionA: TMenuItem;
mnuQuit: TMenuItem;
redQ2: TRichEdit;
procedure mnuQuitClick(Sender: TObject);
procedure mnuOptionAClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmQ2: TfrmQ2;
implementation
{$R *.dfm}
{$R+}
//=============================================================================
procedure TfrmQ2.FormCreate(Sender: TObject);
var
TF : TextFile;
sLineA, sLineB : String;
sGName, sDName, sMnth, sDays, sNumT : String;
begin
{Code for onCreate event of form}
randomize;
IF NOT FileExists('DataQ2.txt')
then
begin
MessageDlg('ERROR: File not found.', mtError, [mbOk], 0);
mnuOptionA.Enabled := False;
Exit;
end;
AssignFile(TF, 'DataQ2.txt');
Reset(TF);
Inc(iCount, 1);
arrTours[iCount] := TData.Create(sGName, sDName, sMnth, StrtoInt(sDays),
StrToInt(sNumt));
End; //while
CloseFile(TF);
end;
//=============================================================================
procedure TfrmQ2.mnuOptionAClick(Sender: TObject);
var
sMnth, sLucy : String;
a, iTNum : Integer;
rNTariff : Real;
cLChar : Char;
begin
{Code Option A}
sMnth := InputBox('Question 2', 'Enter the month of tour (e.g. February)?',
'');
redQ2.Lines.Clear;
redQ2.Paragraph.TabCount := 1;
redQ2.Paragraph.Tab[0] := 100;
redQ2.Lines.Add('Tours for the month of ' + sMnth);
redQ2.Lines.Add('===============================');
redQ2.Lines.Add('Number' + #9 + 'Destination');
for a := 1 to iCount do
begin
if Uppercase(arrTours[a].getMName) = Uppercase(sMnth)
then redQ2.Lines.Add(intToStr(a) + #9 + arrTours[a].getDName);
end;
redQ2.Lines.Add(' ');
sLucy := InputBox('Question 2', 'Enter any character from '+
arrTours[iTNum].getDName +' .', 'a');
cLChar := arrTours[iTNum].findLuckyChar;
IF Upcase(cLChar) = UpCase(sLucy[1])
then
begin
rNTariff := arrTours[iTNum].getTariff * 0.75; //25% discount
redQ2.Lines.Add('Congratulations! You have received 25% discount '+
'on the daily tariff!' + #13 +
'The tariff was ' +
FloatToStrF(arrTours[iTNum].getTariff, ffCurrency, 8,2) +
' per day. It has been reduced to ' +
FloattoStrF(rNTariff, ffCurrency, 8, 2) + ' per day');
end
else
begin
redQ2.Lines.Add('The lucky character was the letter '+ cLChar +'.'+#13 +
'No discount. The tariff is still ' +
FloatToStrF(arrTours[iTNum].getTariff, ffCurrency, 8,2) + ' per
day');
end;
end;
//=============================================================================
procedure TfrmQ2.mnuQuitClick(Sender: TObject);
begin
Application.Terminate;
end;
end.
unit Question3U_MEMO;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, Menus;
type
TfrmQ3 = class(TForm)
mnuMain: TMainMenu;
mnuOptionA: TMenuItem;
mnuOptionB: TMenuItem;
mnuQuit: TMenuItem;
redQ3: TRichEdit;
mnuOptionC: TMenuItem;
procedure mnuQuitClick(Sender: TObject);
procedure mnuOptionAClick(Sender: TObject);
procedure mnuOptionBClick(Sender: TObject);
procedure mnuOptionCClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmQ3: TfrmQ3;
VAR
//array used for Option 3.
arrDest : array[1..6] of string =
('Cape Winelands','Garden Route','Kruger National Park',
'Robben Island (English tour)', 'Robben Island (Other tour)',
'Shakaland');
{$R *.dfm}
{$R+}
//=============================================================================
procedure TfrmQ3.mnuOptionAClick(Sender: TObject);
var
a : Integer;
rRand, rTotal : Real;
sTemp : String;
begin
{Code Option A}
redQ3.Lines.Clear;
rTotal := 0;
for A := 1 to 40 do
begin
IF ((pos('France', arrData[a]) > 0) OR (pos('Germany', arrData[a]) > 0)
OR (pos('Spain', arrData[a]) > 0))
then
begin
sTemp := arrData[a];
Delete(sTemp, 1, pos('#', sTemp));
Delete(sTemp, 1, pos('#', sTemp));
rTotal := rTotal + StrToFloat(sTemp);
end;
end;
rRand := rTotal * 10.75;
redQ3.Lines.Add('Total amount in euro: '+ FloatToStr(rTotal));
redQ3.Lines.Add('Total amount in South African rand: ' +
FloatToStrF(rRand, ffCurrency, 8, 2));
end;
//=============================================================================
procedure TfrmQ3.mnuOptionBClick(Sender: TObject);
var
a, Index : Integer;
begin
{Code Option B}
redQ3.Lines.Clear;
redQ3.Lines.Add('List of English-speaking tourists to Robben Island:');
redQ3.Lines.Add('===================================================');
for a := 1 to 40 do
begin
if pos('#RO#', arrData[a]) > 0
then
begin
Index := pos('#RO#', arrData[a]);
IF (pos('Canada', arrData[a]) > 0) OR
(pos('England', arrData[a]) > 0)
then
begin
Delete(arrData[a], Index, 4);
Insert('#ROEnglish#', arrData[a], Index);
//Insert('English', arrData[a], Index+4); //alternative
redQ3.Lines.Add(Copy(arrData[a], 1, pos('@', arrData[a])-1));
end //Canada & England
else
begin
Delete(arrData[a], Index, 4);
Insert('#ROOther#', arrData[a], Index);
//Insert('Other', arrData[a], Index+4); //alternative
end;
end; //Robben Island
end;
end;
//=============================================================================
var
arrCount :array[1..6] of integer;
a, b,iRating :integer;
sDest :string;
sRating :string;
begin
redQ3.Lines.Clear;
redQ3.Paragraph.TabCount := 2;
redQ3.Paragraph.Tab[0] := 150;
redQ3.Paragraph.Tab[1] := 200;
redQ3.Lines.Add('Star rating of tours');
redQ3.Lines.Add('======================================');
redQ3.Lines.Add('Destination' + #9 + 'Rating' + #9 + 'Number of tourists');
redQ3.Lines.Add('======================================');
for a := 1 to 6 do
arrCount[a] := 0;
for a := 1 to 40 do
begin
sDest := Uppercase(copy(arrData[a], pos('#',arrData[a])+1,3));
case sDest[1] of
'C' : inc(arrCount[1],1);//Cape Winelands
'G' : inc(arrCount[2],1);//Garden Route
'K' : inc(arrCount[3],1);//Kruger National Park
'R' : case sDest[3] of //Robben Island
'E' : inc(arrCount[4],1);//English
'O' : inc(arrCount[5],1);//Other
end;
'S' : inc(arrCount[6],1);//Shakaland
end;
end;//for
// Output
For a := 1 to 6 do
begin
sRating := '';
iRating := arrCount[a] div 3;
for b := 1 to iRating do
sRating := sRating + '*';
redQ3.Lines.Add(arrDest[a] + #9 + sRating + #9 + '(' +
IntToStr(arrCount[a]) + ')');
end;/
end;
//=============================================================================
procedure TfrmQ3.mnuQuitClick(Sender: TObject);
begin
Application.Terminate;
end;
end.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.sql.*;
break;
}
//=============================================================================
case 'D': // Question 1.4
{
sql = "SELECT Surname, StartDate, EndDate, (Enddate-
StartDate)+1 AS NumberOfDays FROM tblTours WHERE (Startdate >= #2012/06/12#)
AND (StartDate <= #2012/10/31#) AND (endDate-StartDate + 1 > 5)";
DB.query(sql);
break;
}
//=============================================================================
case 'E': // Question 1.5
{
sql = "DELETE FROM tblTours WHERE YEAR(EndDate) = 2011";
DB.query(sql);
break;
}
//=============================================================================
case 'F': // Question 1.6
{
sql = "SELECT Country, Format(SUM(AmountPaid),'Currency') AS
IncomePerCountry FROM tblTourists GROUP BY Country";
DB.query(sql);
break;
}
//=============================================================================
case 'G': // Question 1.7
{
sql = "SELECT Destination, StartDate, Seats,
Count(tblTourists.Surname) AS [SeatsBooked] FROM tblTours, tblTourists WHERE
tblTourists.TourID = tblTours.TourID GROUP BY Destination, StartDate, Seats
HAVING Count(tblTourists.Surname) < tblTours.Seats";
DB.query(sql);
break;
}
}
}while (choice != 'Q');
DB.disconnect();
System.out.println("Done");
}
}
OBJECT CLASS:
import java.text.DecimalFormat;
/**
*
* Memo Question 2
*/
public class Quest2_MEMO {
private String gName;
private String dName;
private String mName;
private int numD;
private int numT;
private double tariff;
public Quest2_MEMO(String gName, String dName, String mName, int numD, int
numT) {
this.gName = gName;
this.dName = dName;
this.mName = mName;
this.numD = numD;
this.numT = numT;
setTariff();
}
//=============================================================================
private void setTariff()
{
String sName = mName.toUpperCase();
//accept solution that doesn't use toUpperCase()
if (sName.equals("DECEMBER") || sName.equals("APRIL") ||
sName.equals("SEPTEMBER"))
tariff = 1250;
else
if (sName.equals("MAY") || sName.equals("MARCH") ||
sName.equals("JUNE") || sName.equals("JULY"))
tariff = 900;
else
tariff = 1000;
}
//=============================================================================
private String shortenString()
{
String shortname = mName.substring(0,1);
String vowels = "AEIOU";
//accept solution using lower case letters as well
for (int cnt = 1; cnt < mName.length();cnt++)
{
char letter = mName.charAt(cnt);
if(vowels.indexOf(mName.toUpperCase().charAt(cnt))<0)
{
shortname =shortname + letter;
}
}
return shortname;
}
//=============================================================================
public char findLuckyChar()
{
Copyright reserved Please turn over
Information Technology/P1 20 DBE/Feb.–Mar. 2013
NSC – Memorandum
APPLICATION/DRIVER CLASS:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.FileReader;
import java.io.FileNotFoundException;
{
String line1 = bf.readLine();
String line2 = bf.readLine();
String[] temp1 = line1.split("&");
String[] temp2 = line2.split(" for ");
String[] temp3 = temp2[1].split(" days#");
tourArray[cnt] = new Quest2_MEMO(temp1[0], temp1[1], temp2[0],
Integer.parseInt(temp3[0]), Integer.parseInt(temp3[1]));
}
}
catch (FileNotFoundException e) {
System.out.println(e);
System.exit(0);
}
catch (Exception f) {
System.out.println(f);
}
char choice = ' ';
do {
System.out.println(" MENU\n");
System.out.println("Option A");
System.out.println("");
System.out.println("Q - QUIT");
System.out.println("\nYour choice? ");
choice = kb.readLine().toUpperCase().charAt(0);
switch (choice) {
case 'A':
System.out.print("Enter the month of tour(e.g. February): ");
Copyright reserved Please turn over
Information Technology/P1 22 DBE/Feb.–Mar. 2013
NSC – Memorandum
destination = temp[1];
money = Double.parseDouble(temp[2]);
}
//=============================================================================
BufferedReader kb;
//=============================================================================
public void runMenu() throws Exception {
System.out.println();
System.out.println("Q - QUIT");
System.out.println();
System.out.println("Your choice?");
choice = kb.readLine().toUpperCase().charAt(0);
switch (choice) {
case 'A': convertEuros();
break;
case 'B': divideGroup();
break;
case 'C': determinePopularity();
break;
case 'Q':
System.out.println("QUIT");
}
} while (choice != 'Q');
//=============================================================================
//Option A
public void convertEuros()
{
double value = 0;
for (int c = 0; c < arrData.length; c++)
{
Tourist tourist = new Tourist(arrData[c]);
String country = tourist.getCountry();
if (country.equalsIgnoreCase("France")
||country.equalsIgnoreCase("Spain")||country.equalsIgnoreCase("Germany"))
{
value = value + tourist.getMoney();
}
} //for
System.out.printf("%s%-8.0f\n","Total amount in euro: ", value);
double rand = value*10.75;
System.out.printf("%sR%10.2f\n\n","Total amount in South African rand: ",
rand);
}
//===========================================================================
// Option B
public void divideGroup()
{
System.out.println("List of English-speaking tourists to Robben
Island");
System.out.println("==================================================");
for (int c = 0; c < arrData.length; c++)
{
Tourist tourist = new Tourist(arrData[c]);
String dest = tourist.getDestination();
if (dest.equals("RO"))
{
String country = tourist.getCountry();
if (country.equalsIgnoreCase("England") ||
country.equalsIgnoreCase("Canada"))
{
System.out.println(tourist.getName());
arrData[c] = arrData[c].replace("#RO#","#ROEnglish#");
tourist.setDestination("ROEnglish");
}
else
{
arrData[c] = arrData[c].replace("#RO#","#ROOther#");
tourist.setDestination("ROOther");
} // else
} // if
}// for
System.out.println("\n\n");
}
//=============================================================================
// Option C
public void determinePopularity()
{
System.out.println("\n\n");
}
}
//=============================================================================
// Test class creating an object of the menu class
import java.io.IOException;
BufferedReader kb;
//============================================================================
//Option A
public void convertEuros()
{
double value = 0;
for (int cnt = 0; cnt < arrData.length; cnt++)
{
if (arrData[cnt].indexOf("France")>=0
||arrData[cnt].indexOf("Spain")>=0||arrData[cnt].indexOf("Germany")>=0)
{
String[] temp = arrData[cnt].split("#");
value = value + Double.parseDouble(temp[2]);
}
}
System.out.printf("%s%-8.0f\n","Total amount in euro: ", value);
double rand = value*10.75;
System.out.printf("%sR%10.2f\n\n","Total amount in South African rand: ",
rand);
}
//=========================================================================
//Option B
public void divideGroup()
{
System.out.println("List of English-speaking tourists to Robben Island");
System.out.println("==================================================");
for (int cnt = 0; cnt < arrData.length; cnt++)
Copyright reserved Please turn over
Information Technology/P1 28 DBE/Feb.–Mar. 2013
NSC – Memorandum
{
if (arrData[cnt].indexOf("#RO#") >= 0)
{
if (arrData[cnt].indexOf("England")>=0 ||arrData[cnt].indexOf("Canada") >= 0)
{
String[] temp = arrData[cnt].split("@");
System.out.println(temp[0]);
arrData[cnt] = arrData[cnt].replace("#RO#","#ROEnglish#");
}
else
{
arrData[cnt] = arrData[cnt].replace("#RO#","#ROOther#");
}
}
}
System.out.println("\n\n");
}
//=============================================================================
// Option C
public void determinePopularity()
{
int[] arrCount = new int[6];
System.out.println("Star rating of tours");
System.out.println("========================================================");
System.out.println("Destination Rating Number of
tourists");
System.out.println("========================================================");
for (int c = 0; c < 6; c++)
{
arrCount[c]=0;
}
do {
System.out.println("MENU");
System.out.println();
System.out.println(" Option A");
Copyright reserved