Photo AI
Question 1
Open the incomplete program in the Question 1 folder. Enter your examination number as a comment in the first line of the Question1_U.pas file. Compile and execute t... show full transcript
Step 1
Answer
To implement the required functionality for the radio group rpgQ1_1
, you need to add a new item. The code for this can be structured as follows:
procedure TForm1.Button1Click(Sender: TObject);
begin
rpgQ1_1.Items.Add('Tablet');
rpgQ1_1.Color := clCream;
rpgQ1_1.ItemIndex := 0;
end;
Step 2
Answer
You will retrieve the age and handle the conditions for citizenship and age eligibility as follows:
procedure TForm1.Button2Click(Sender: TObject);
var
age: Integer;
yearToApply: Integer;
begin
age := StrToInt(edtQ1_2.Text);
if not chkSouthAfrican.Checked then
ShowMessage('The applicant must be a South African citizen')
else
begin
if age < 16 then
begin
yearToApply := CURRENT_YEAR + (16 - age);
ShowMessage('The applicant is too young.' + sLineBreak + 'Can apply in the year ' + IntToStr(yearToApply));
end
else
ShowMessage('SUCCESSFUL');
end;
end;
Step 3
Answer
For this part, ensure that you're capturing the sentence and performing your calculations accordingly:
procedure TForm1.Button3Click(Sender: TObject);
var
Total, Top, Bottom, Term: Double;
begin
Total := 0;
Top := 1;
Bottom := 1;
while Total <= 4 do
begin
Term := Top / Bottom;
Total := Total + Term;
Inc(Bottom);
end;
redQ1_3.Text := FormatFloat('0.0000', Total);
redQ1_3.Text := IntToStr(Bottom - 1);
end;
Step 4
Answer
To count the occurrences of a specific letter in the sentence:
procedure TForm1.Button4Click(Sender: TObject);
var
letter: Char;
count, i: Integer;
sentence: string;
begin
letter := edtQ1_4_1.Text[1];
count := 0;
sentence := LowerCase(edtQ1_4.Text);
for i := 1 to Length(sentence) do
if sentence[i] = LowerCase(letter) then
Inc(count);
pnlQ1_4_1.Caption := IntToStr(count);
end;
Step 5
Answer
To find the longest word, the following structured approach can be adopted:
procedure TForm1.Button5Click(Sender: TObject);
var
words: TStringList;
longestWord: string;
begin
words := TStringList.Create;
try
words.Text := StringReplace(edtQ1_4.Text, ' ', sLineBreak, [rfReplaceAll]);
longestWord := '';
for i := 0 to words.Count - 1 do
if Length(words[i]) > Length(longestWord) then
longestWord := words[i];
ShowMessage('Length of longest word: ' + IntToStr(Length(longestWord)));
finally
words.Free;
end;
end;
Report Improved Results
Recommend to friends
Students Supported
Questions answered