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
Step 2
Answer
To implement the functionalities detailed in 1.2, do the following:
Retrieve Age: Extract the age from the edit box edtQ1_2
and convert it to an integer:
age := StrToInt(edtQ1_2.Text);
Check Citizenship: Verify if the South African citizen checkbox is checked. If it’s not checked, show a message:
if not chkSouthAfricanCitizen.Checked then
ShowMessage('The applicant must be a South African citizen.');
Age Validation: Test if age
meets the criteria of being 16 or older:
if age < 16 then begin
YearToApply := CURRENT_YEAR + (16 - age);
ShowMessage('The applicant is too young. Can apply in the year ' + IntToStr(YearToApply));
end;
Success Case: If both conditions are satisfied and age >= 16, set edtQ1_2
to 'SUCCESSFUL':
if age >= 16 then
edtQ1_2.Text := 'SUCCESSFUL';
Step 3
Answer
Initialize all variables:
var
Total, Top, Bottom: integer;
Term: real;
begin
Total := 0;
Top := 1;
Bottom := 1;
Term
until the condition is met:while (Total <= 4) do begin
Term := Top / Bottom;
Total := Total + Term;
Inc(Bottom);
end;
redQ1_3.Text := FloatToStrF(Total, ffGeneral, 4, 4);
redQ1_4.Text := IntToStr(Bottom - 1);
Step 4
Answer
Extract Letter and Sentence:
var
letter: char;
sentence: string;
count: integer = 0;
begin
letter := edtQ1_4_1.Text[1];
sentence := edtQ1_4.Text;
Count Occurrences: Loop to check each character in the sentence:
for i := 1 to Length(sentence) do begin
if UpCase(sentence[i]) = UpCase(letter) then
Inc(count);
end;
Display Count: Show the result on the panel:
pnlQ1_4_1.Caption := 'Number: ' + IntToStr(count);
Step 5
Answer
Initialize Length Variables:
var
longestWord: string;
maxLength: integer = 0;
begin
Loop Through Sentence: Split the sentence to identify individual words:
sentence := edtQ1_4.Text + ' ';
word := '';
for i := 1 to Length(sentence) do begin
if sentence[i] = ' ' then begin
if Length(word) > maxLength then begin
maxLength := Length(word);
longestWord := word;
end;
word := '';
end else
word := word + sentence[i];
end;
Display Longest Word: Show the length:
ShowMessage('Length of longest word: ' + IntToStr(maxLength));
Report Improved Results
Recommend to friends
Students Supported
Questions answered