0% found this document useful (0 votes)
13 views10 pages

11 ITNovember 2022 P1 MEMO

Uploaded by

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

11 ITNovember 2022 P1 MEMO

Uploaded by

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

11 IT November 2022 MEMO:

Question 1:
procedure TfrmQuestion1.btnQuestion1_1Click(Sender: TObject); 8
begin
//Question 1.1
imgPic.Stretch := true;
imgPic.Width := 377; 
lblWelcome.Caption := 'Life Long Learning'; 
lblWelcome.Font.Style := [fsUnderline]; 
lblWelcome.Font.Name := 'Elephant'; 
end;

procedure TfrmQuestion1.btnQuestion1_2Click(Sender: TObject); 5


const
GameCost = 59.99; //Provided
var
iGame : integer; //Provided
rCost : Real;
begin
//Question 1.2
iGame := sedGames.Value;

rCost := GameCost* (iGame - iGame div 10);

edtCost.Text := FloatToStrF(rCost,ffCurrency,10,2);
end;

procedure TfrmQuestion1.btnQuestion1_3Click(Sender: TObject); 10


var
iHeight, iLen, iWidth : Integer;
rVolume, rPerc, rRoof : Real;
begin
//Question 1.3
iHouseHeight := 6; //Provided code

iHeight := StrToInt (InputBox('Height','Enter height of the roof',''));


iWidth := StrToInt(InputBox('Width','Enter width of the house',''));
iLen := StrToInt(InputBox('Length','Enter length of the roof','')); 

rRoof := 1/2*iHeight*iWidth*iLen; 
rVolume := iHouseHeight * iWidth * iLen + rRoof; 
rPerc := rRoof / rVolume * 100; 
redOutput.Lines.Add ('Total Volume = '+FloatToStrF(rVolume,ffFixed,10,1));
redOutput.Lines.Add('Percentage = '+FloatToStrF(rPerc,ffFixed,10,1)+'%');
Labelsvars
end;

Page 1 of 10
procedure TfrmQuestion1.btnQuestion1_4Click(Sender: TObject); 9
var
sTerm, sAcronym : string;
k : integer;
begin
//Question 1.4
sTerm := edtTerm.Text; 
sAcronym := upcase(sTerm[1]); 

for k := 2 to length(sTerm)  do May start at 1

if sTerm[k] =' ' then


sAcronym := sAcronym + upcase (sTerm[k+1] );

Alternative using while loop:


sTerm := uppercase (edtTerm.Text) ;
while pos(' ',sTerm) > 0 do OR while pos(' ',sTerm) <> 0 do
begin
ipos := pos(' ',sTerm); 
sAcronym := sAcronym + sterm[ipos+ 1] ;
delete(sterm,1,ipos);
end;

lblAcronym.Caption := sAcronym; 
end;

Page 2 of 10
procedure TfrmQuestion1.btnQuestion1_5Click(Sender: TObject); 18
var
inum, k, iCode: integer;
begin
redCollatz.Lines.Clear;
//Question 1.5
Val(edtCollatz.Text,inum,icode);

if (icode > 0)  then OR { if TryStrToInt(edtCollatz.Text,iNum) = false then}


begin
edtCollatz.Clear; 
edtCollatz.setfocus; 
edtCollatz.Color := clYellow;
Exit; 
end;

k := 1; 
redCollatz.Lines.Add(inttostr(k) + ': ' + inttostr(inum)); 
while inum <> 1 do  conditional loop
begin
if inum mod 2 = 0  then
inum := inum div 2 
else 
inum := (inum * 3)  + 1;
inc(k); 
redCollatz.Lines.Add(inttostr(k) + ': ' + inttostr(inum)); 
end;
{Alternative:
k := 1;
repeat
redCollatz.Lines.Add(IntToStr(k)+':'+IntToStr(iNum)); 
if Odd(iNum) then
iNum := iNum * 3 + 1
else
iNum := iNum div 2; 
inc(k); 
until iNum = 1 ; 
redCollatz.Lines.Add(IntToStr(k)+':'+IntToStr(iNum)) ;}

end;

end.

Page 3 of 10
Question 2 MEMO
unit frmQuestion2_U;

procedure TfrmQuestion2.btnQ2_1Click(Sender: TObject); //12


begin

// Provided code - do not change


redQ2.Lines.clear;
//Question 2.1 Network Acronyms
tblterms.first; 
while not tblterms.eof do 
begin
if (tblterms['Acronym'] <>  null ) and (pos ('NETWORK', uppercase
(tblterms['term'] )) > 0) then
redQ2.Lines.Add (tblterms['Acronym'] + #9 + tblterms['term']); 
tblterms.next; 
end;
end;

procedure TfrmQuestion2.btnQ2_2Click(Sender: TObject); //18


var
sTopic: string;
iCount: integer;
begin
// Question 2.2 Questions per topic
sTopic := cmbTopic.Items [cmbTopic.ItemIndex];  or cmbTopic.Text;
tblTopics.First; 
while not tblTopics.eof do 
begin
if sTopic = tblTopics['topic']  then
begin
tblTerms.First; 
iCount10 := 0;
iCount11 := 0;  both here or before tblTopics loop
while not tblTerms.eof do  nested
begin
if (tblTopics['TopicID']  = tblTerms['TopID'])  then
case tblTerms['Grade'] of  or nested if-statement
10 : Inc(icount10);
 11 : Inc(icount11); 
end;

{Alternative for the Case:


if tblTerms['Grade'] = 11 then
inc(iGrade11)
else
if tblTerms['Grade'] = 10 then
inc(iGrade10); 

Page 4 of 10
tblTerms.Next; 
end;
end;
tblTopics.Next; 
end;
lblGrade10.Caption := inttostr(iCount10) ; 
lblGrade11.Caption := inttostr(iCount11) ; 

end;

procedure TfrmQuestion2.btnQ2_3Click(Sender: TObject); //10


var
ilow: integer;
sLow: string;
tFile: Textfile;
begin
redQ2.Lines.clear;
//Question 2.3 Lowest percent
ilow := 100; 

tblTopics.First;
while not tblTopics.eof do
begin
if tblTopics['CAPS_Percent']  < ilow then
begin
ilow := tblTopics['CAPS_Percent']; 
sLow := tblTopics['Topic']; 
end;
tblTopics.Next;
end;

AssignFile(tfile,'lowest.txt'); 
Rewrite(tfile); 
writeln(tFile , sLow,' is the lowest weighted at ',ilow,'%');  variables
OR //writeln(tFile,sLow+' is the lowest weighted at '+IntToStr(iLow)+'%');
CloseFile(tfile);
btnQ2_2.Enabled := False; 
end;

Page 5 of 10
procedure TfrmQuestion2.btnQ2_4Click(Sender: TObject); //5
begin
// Question 2.4 Update marks
tblterms.Edit; 
tblterms['Practical']  := chkPractical.checked;
tblterms.post;
ShowMessage(tblterms['Term']  + ' has been changed'); 
end;

procedure TfrmQuestion2.btnQ2_5Click(Sender: TObject); //5


begin
//Given code
//TopID : DAT3117
//Definition : Binary digit 0 or 1
// Question 2.5 Add a definition
tblTerms.Insert; 
tblTerms['Marks'] := 1; 
tblTerms['Practical'] := False; 
tblTerms['Term'] := 'Bit';
tblTerms['TopID'] := 'DAT3117';
tblTerms['Definition'] := 'Binary digit 0 or 1';  3 strings
tblTerms.Post; 
end;

Page 6 of 10
Question 3 MEMO
unit frmQuestion3_u;

private
arrName, , arrBinary: array[1..100] of string;
arrAnswer: array[1..100] of integer;
iCount: integer;
function ConvertToDecimal (pBinary: string): Integer; ;
procedure SetTabs;
{ Private declarations }
public
{ Public declarations }
end;

procedure TfrmQuestion3.FormActivate(Sender: TObject); //13


var
tFile: textFile;
sLine: string;
begin
//Provided code - DO NOT change
if fileexists('Decimal.txt') = false then
begin
Showmessage('File doesn''t exist');
exit;
end;
//Question 3.1 Form Activate
Assignfile(tFile, 'Decimal.txt'); this mark is awarded in Question 2
Reset(tFile); 
iCount := 0; 

while (not eof(tFile))  and  (iCount < 100)  do


begin
inc(iCount); 
readln(tFile, sLine); 
iPos := pos(',', sLine); 
arrName[iCount] := copy(sLine, 1, iPos - 1); 
Delete(sLine, 1, pos(',', sLine)); 

iPos := pos(',', sLine);


arrBinary[iCount] := copy(sLine, 1, iPos - 1);
Delete(sLine, 1, pos(',', sLine));  other
arrAnswer[iCount] := strtoint(sLine); 
end;
closefile(tFile); 
end;

Page 7 of 10
procedure TfrmQuestion3.btnDisplayClick(Sender: TObject); //4
var
k: Integer;
begin
settabs; //Provided code - DO NOT change
//Question 3.2 Display
for k := 1 to iCount do 
begin
redOutput.Lines.Add(arrName[k] + #9 + arrBinary[k] + #9 + inttostr
(arrAnswer[k]));
end;
end;

procedure TfrmQuestion3.btnGenerateClick(Sender: TObject); //6


var
I: Integer;
iLength: integer;
irandom : integer;
sRandom: string;
begin
//Question 3.3 Generate Random Binary
iLength := randomrange(5, 9);  or randomrange(4, 8) and for loop starts at 1;
sRandom := '1'; 
for I := 2 to iLength do  or 1 to iLength - 1
sRandom := sRandom + inttostr(random(2)) ; or IntTostr(RandomRange(0,2));

edtBinary.Text := sRandom; 
end;

Page 8 of 10
procedure TfrmQuestion3.btnSearchClick(Sender: TObject); //14
var
sCorrect: string;
K, iAnswer: Integer;
bflag: boolean;
sBinary: string;
begin
//Provided code - DO NOT change
redOutput.Lines.Clear;
redoutput.SelAttributes.Style := [fsBold];
redoutput.SelAttributes.Color := clBlue;
redOutput.Lines.Add('Answers tested');

//Question 3.5 Search Random


sBinary := edtBinary.Text; 
iAnswer := converttoDecimal (sBinary) ;
lblAnswer.Caption := 'Decimal number: '+IntToStr(iAnswer); 
bFlag := false; 
for k := 1 to iCount do
if arrBinary[k] = sBinary then
begin
bFlag := true; 
if arrAnswer[k]  = iAnswer then
redOutput.Lines.Add(arrName[k]+' : <CORRECT>') 
else 
redOutput.Lines.Add(arrName[k]+' : '+IntToStr(arrAnswer[k])); 
end;

if bFlag = false then 


ShowMessage(sBinary+ 'was not found'); 
end;

Page 9 of 10
//Question 3.4 Function
function TfrmQuestion3.ConvertToDecimal(pBinary: string): Integer;  //13
var
iExp, k : Integer;
rDec, rPower : real;
begin
iExp := Length(pBinary)-1; 
rDec := 0; 
for k := 1 to Length(pBinary) do 
begin
if pBinary[k] = '1' then 
begin
rPower := power (2,iExp); 
rDec := rDec + rPower; 
end;
dec(iExp); 
Result := Round (rDec);
end;

{Alternative:
iExp := Length(pBinary)-1; 
rDec := 0; 
k := 1;
while k <= Length(pBinary) do //Including initializing k and inc(k)
begin
if pBinary[k] = '1' then
begin
rPower := power (2,iExp); 
rDecimal := rDecimal + rPower; 
end;
dec(iExp); 
inc(k);
end;}
Result := Round (rDec);
end;

procedure TfrmQuestion3.SetTabs; //Provided code


begin
redoutput.Lines.Clear;
redoutput.SelAttributes.Style := [fsBold];
redoutput.SelAttributes.Color := clBlue;
redoutput.Paragraph.TabCount := 2;
redoutput.Paragraph.Tab[0] := 120;
redoutput.Paragraph.Tab[1] := 200;
redoutput.Lines.Add('Name' + #9 + 'Binary number' + #9 + 'Answer');
end;
end.

Page 10 of 10

You might also like