Photo AI

5.1 Give a reason for the use of EACH of the following structures in a Delphi program: 5.1.1 FormCreate event 5.1.2 A WHILE loop instead of a FOR loop 5.1.3 Ord function 5.2 Students can log in on the university's website or portal to access resources - NSC Information Technology - Question 5 - 2018 - Paper 2

Question icon

Question 5

5.1-Give-a-reason-for-the-use-of-EACH-of-the-following-structures-in-a-Delphi-program:--5.1.1-FormCreate-event-5.1.2-A-WHILE-loop-instead-of-a-FOR-loop-5.1.3-Ord-function--5.2-Students-can-log-in-on-the-university's-website-or-portal-to-access-resources-NSC Information Technology-Question 5-2018-Paper 2.png

5.1 Give a reason for the use of EACH of the following structures in a Delphi program: 5.1.1 FormCreate event 5.1.2 A WHILE loop instead of a FOR loop 5.1.3 Ord fun... show full transcript

Worked Solution & Example Answer:5.1 Give a reason for the use of EACH of the following structures in a Delphi program: 5.1.1 FormCreate event 5.1.2 A WHILE loop instead of a FOR loop 5.1.3 Ord function 5.2 Students can log in on the university's website or portal to access resources - NSC Information Technology - Question 5 - 2018 - Paper 2

Step 1

5.1.1 FormCreate event

96%

114 rated

Answer

The FormCreate event is essential as it contains the code that runs when the application starts. This allows for initialization tasks such as setting up components, loading necessary resources, or defining initial states.

Step 2

5.1.2 A WHILE loop instead of a FOR loop

99%

104 rated

Answer

A WHILE loop is advantageous when the number of iterations is not predetermined. It allows the program to continue executing as long as a specified condition remains true, making it suitable for situations where the exact iteration count is variable.

Step 3

5.1.3 Ord function

96%

101 rated

Answer

The Ord function is used to obtain the ordinal value of a character. This is helpful in various programming situations that require comparison or manipulation of character data.

Step 4

5.2.1 (a) Define the term encapsulation.

98%

120 rated

Answer

Encapsulation refers to the practice of restricting access to certain details of an object and only exposing a controlled interface. This ensures that the internal state of an object can only be modified through its methods, promoting data integrity and hiding implementation details.

Step 5

5.2.1 (b) Suggest a suitable date type for the fDateOfEntry attribute.

97%

117 rated

Answer

A suitable data type for the fDateOfEntry attribute would be 'DateTime', as it allows the storage of both the date and time of the entry.

Step 6

5.2.1 (c) Define a method that can be added to the class diagram that receives a parameter and changes login number.

97%

121 rated

Answer

A method that can be added is:

procedure setLoginNumber(LoginNumber: integer);
begin
  self.LoginNumber := LoginNumber;
end;

This method allows the modification of the LoginNumber attribute based on the provided parameter.

Step 7

5.2.2 (a) Name the type of search technique used in the code above.

96%

114 rated

Answer

The search technique used in the code is a Linear search, as it checks each element in the array sequentially until it finds the required student number.

Step 8

5.2.2 (b) Criticise the program code provided in terms of good and effective programming techniques.

99%

104 rated

Answer

The provided code has several drawbacks:

  • It does not handle cases where the student number may not exist, leading to potential errors.
  • The code uses a fixed limit (1000), which limits its usability for larger datasets.
  • There is no user feedback or confirmation after updating an entry, potentially confusing the user about the success of the operation.

Step 9

5.2.2 (c) Write pseudo code that uses a more effective search technique that will terminate the search process when the update has been done.

96%

101 rated

Answer

Here is a pseudocode implementation that incorporates an early termination after the update:

Search := InputBox('Search','Enter student number','S0001');
bFound := false;
For A := 1 to 1000 do
  if arrStudNumbers[A] = Search then
  begin
    arrMathResults[A] := StrToInt(InputBox('Update result','Enter updated result','0'));
    bFound := true;
    Break; // Exit the loop after updating
  end;
if not bFound then
  ShowMessage('Student number not found.');

This approach ensures that the search stops immediately once the result has been updated.

Step 10

5.3 Copy and complete the trace table below to determine the output of this program segment if the name entered into the edit box edtName is 'Mark Simon'.

98%

120 rated

Answer

sNameNOT(Upcase(sName[A]) in ['A','E','I','O','U'])sCodeAIs sName[A] = ' 'Display
Mark SimonFalse1False
TrueM2False
FalseMr3False
FalseMrS4False
TrueMrSi5False
TrueMrSim6TrueMark Sim

Join the NSC students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

;