11 ITNovember 2022 P1 MEMO
11 ITNovember 2022 P1 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;
edtCost.Text := FloatToStrF(rCost,ffCurrency,10,2);
end;
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)+'%');
Labelsvars
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]);
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);
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;
Page 4 of 10
tblTerms.Next;
end;
end;
tblTopics.Next;
end;
lblGrade10.Caption := inttostr(iCount10) ;
lblGrade11.Caption := inttostr(iCount11) ;
end;
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;
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;
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;
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');
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;
Page 10 of 10