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 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 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
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The FormCreate event is used to execute code when the application starts or when the form is opened. This is the suitable place to initialize variables, set up the interface, and perform any startup tasks that are necessary for the program to function correctly.
Step 2
5.1.2 A WHILE loop instead of a FOR loop
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
A WHILE loop is used when the number of iterations is unknown beforehand, meaning it will continue looping while a certain condition remains true. This flexibility makes it ideal for situations where the exit condition is based on user input or other dynamic criteria.
Step 3
5.1.3 Ord function
96%
101 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The Ord function is used to determine the ASCII or ordinal value of a character. This is helpful when conversions between character types and their corresponding numeric values are required, for example, in text processing.
Step 4
5.2.1 (a) Define the term encapsulation.
98%
120 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Encapsulation refers to the concept of restricting access to certain components of an object, thus preventing unauthorized access and modification. It ensures that the internal state of an object is hidden from the outside, exposing only what is necessary through methods.
Step 5
5.2.1 (b) Suggest a suitable data type for the fDateOfEntry attribute.
97%
117 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
A suitable data type for the fDateOfEntry attribute would be 'DateTime' as it allows for storing both date and time information, which is essential for capturing the exact moment of 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
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
A method that can be added to the class diagram is:
function setLoginNumber(LoginNumber: integer);
begin
self.fLoginNumber := LoginNumber;
end;
This method takes an integer as a parameter and updates the fLoginNumber attribute of the object.
Step 7
5.2.2 (a) Name the type of search technique used in the code above.
96%
114 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The type of search technique used in the code above is a 'Linear' or 'Sequential' search, as it checks each element in the array one by one until it finds a match or reaches the end.
Step 8
5.2.2 (b) Criticise the program code provided in terms of good and effective programming techniques.
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The program code can be improved by implementing better programming techniques. For instance, it should include error handling to manage cases where the student number is not found, and avoid using fixed values like 1000, making it less adaptable for different number of entries. Additionally, a more efficient search method could be employed.
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
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Here’s a pseudocode implementation of an effective search procedure:
// Initialize variables
Search = InputBox('Search','Enter student number','S0001')
Found = false
Pos = 1
while not Found and Pos <= length(arrStudNumbers) do
if arrStudNumbers[Pos] = Search then
arrMathResults[Pos] = new result input
Found = true
end if
Pos = Pos + 1
end while
This code will stop searching as soon as the relevant student number is found and 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
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!