INSTRUCTIONS AND INFORMATION

  1. This question paper is divided into FOUR sections. Candidates must answer ALL the questions in ALL FOUR sections.
  2. The duration of this examination is three hours. Because of the nature of this examination it is important to note that you will not be permitted to leave the examination room before the end of the examination session.
  3. This question paper is set with programming terms that are specific to Delphi programming language. The Delphi programming language must be used to answer the questions.
  4. Make sure that you answer the questions according to the specifications that are given in each question. Marks will be awarded according to the set requirements.
  5. Answer only what is asked in each question. For example, if the question does not ask for data validation, then no marks will be awarded for data validation.
  6. Your programs must be coded in such a way that they will work with any data and not just the sample data supplied or any data extracts that appear in the question paper.
  7. Routines, such as search, sort and selection, must be developed from first principles. You may NOT use the built-in features of Delphi for any of these routines.
  8. All data structures must be declared by you, the programmer, unless the data structures are supplied.
  9. You must save your work regularly on the disk/CD/DVD/flash disk you have been given, or on the disk space allocated to you for this examination session.
  10. Make sure that your examination number appears as a comment in every program that you code, as well as on every event indicated.
  11. If required, print the programming code of all the programs/classes that you completed. Your examination number must appear on all the printouts. You will be given half an hour printing time after the examination session.
  12. At the end of this examination session you must hand in a disk/CD/DVD/flash disk with all your work saved on it OR you must make sure that all your work has been saved on the disk space allocated to you for this examination session. Ensure that all files can be read.
  13. The files that you need to complete this question paper have been provided to you on the disk/CD/DVD/flash disk or on the disk space allocated to you. The files are provided in the form of password-protected executable files.

NOTE: Candidates must use the file DataENGNov2021.exe.
Do the following:

  • Double click on the following password-protected executable file:
    DataENGNov2021.exe.
  • Click on the 'Extract' button.
  • Enter the following password: eHikeNov2021

Once extracted, the following list of files will be available in the folder
DataENGNov2021:

Question 1:
Question1_P.dpr
Question1_P.dproj
Question1_P.res
Question1_U.dfm
Question1_U.pas

Question 2:
ConnectDB_U.pas
HikingDB - Copy.mdb
HikingDB.mdb
Question2_P.dpr
Question2_P.dproj
Question2_P.res
Question2_U.dfm
Question2_U.pas

Question 3:
HikingTrail_U.pas
Question3_P.dpr
Question3_P.dproj
Question3_P.res
Question3_U.dfm
Question3_U.pas
*.txt 9 files
*.jpg 9 files

Question 4:
Question4_P.dpr
Question4_P.dproj
Question4_P.res
Question4_U.dfm
Question4_U.pas

QUESTIONS

SECTION A
QUESTION 1: GENERAL PROGRAMMING SKILLS
Do the following:

  • 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 the program. The program has no functionality currently.
  • Use the variables provided to answer the questions.

Example of the graphical user interface (GUI):
1 yatfadda

  • Complete the code for each section of QUESTION 1, as described in QUESTION 1.1 to QUESTION 1.5 that follow.

1.1 FormCreate event
Write code to change the format of the label lblQ1_1 as follows:

  • Display the text 'Coding is' when the program is executed.
  • Change the colour of the text to green (clGreen).
  • Change the size of the font to 16 pt.
  • Change the font to 'Arial'.

Example of output:
1.1 adadada
(4)

1.2 Button [1.2 - Number of rolls]
Energy sweets recommended for hikers to have during each break while hiking are packaged in rolls of eight sweets per roll. Hikers normally eat four sweets during each break. Use the spnQ1_2 spin edit to select/enter the number of breaks a hiker plans on taking. The program must determine the number of sweet rolls that must be purchased for the hike.
Write code to do the following:

  • Create a constant SWEETS_PER_ROLL to store the value of 8.
  • Declare suitable integer variables for the number of breaks, the total number of sweets and the number of rolls to purchase.
  • Extract the number of breaks to be taken during a hike from the spnQ1_2 spin edit.
  • Calculate the total number of sweets that a hiker will have during the hike. Assume that hikers will consume four sweets during each break.
  • Calculate the minimum number of rolls that need to be purchased to supply the hiker with enough sweets for the hike.
  • Display the number of rolls on the lblQ1_2 label.

       Example of output for seven breaks:       Example of output for eight breaks:
1.2 adadada
(8)
1.3 Button [1.3 - Calculate volume]
The figure shown below was compiled using a combination of half a sphere and a tetrahedron (a solid shape with four flat sides that are triangles). The program must calculate and display the volume of the combined figure.
1.3 1 aihdada
The following information is provided:

  • The formula to calculate the volume of the combined figure is:
    𝑉 = 𝑣𝑜𝑙𝑢𝑚𝑒 𝑜ƒ 𝑡𝑒𝑡𝑟𝑎ℎ𝑒𝑑𝑟𝑜𝑛 + 1/2 (𝑣𝑜𝑙𝑢𝑚𝑒 𝑜ƒ 𝑠𝑝ℎ𝑒𝑟𝑒)
  • The volume of the tetrahedron in the figure is given as 133 cm3

1.3 2 aiudhada

  • The formula to calculate the volume of a sphere is:
    𝑉 = 4 𝜋𝑟3
          3

1.3. 3 aiduiajhdada

Use the information provided and write code to do the following:

  • Calculate the volume of the combined figure if the radius of the sphere is 3 cm.
  • Display the volume in a ShowMessage box formatted to ONE decimal place. 

Example of output:
1.3 4 audgayuda
(7)

1.4 Button [1.4 - Display pattern]
A pattern with a symbol selected from the cmbQ1_4 combo box must be displayed. The pattern is a square which consists of the same number of rows and columns. The number of rows and columns is obtained from the position of the symbol that has been selected from the combo box.

NOTE: The first item (@) in the combo box is situated in position one.
The first eight symbols in the combo box are shown below.
1.4 auydada
Write code to do the following:

  • Clear the output area redQ1_4.
  • Extract the symbol selected by the user from the cmbQ1_4 combo box.
  • Obtain the position of the symbol selected in the combo box to determine the number of rows and columns.
  • Use nested loop structures to display the pattern (block) in the rich edit, using the selected symbol.

Example of output if the first item (@) is selected in cmbQ1_4:
1.4 1 ugaduygad
Example of output if the third item ($) is selected in cmbQ1_4:
1.4 2 aiudhada
(11)

1.5 Button [1.5 - Characters]
A string must be compiled by randomly generating upper-case letters of the alphabet until the same letter is generated consecutively.

Code has been provided to clear the rich edit and to initialise an output string.
Write code to do the following:

  • Randomly generate a capital letter from the alphabet in the range 'A'..'Z'.
  • Compile a string using the generated letters.
  • Repeat the process until the generated letter is a duplicate of the previous (last) letter that was generated.
  • Display the generated string in the redQ1_5 rich edit. Each time the output string must include the final duplicate characters, as shown in the example output.

HINT: The ASCII values for the letters 'A' to 'Z' start at 65 for the letter 'A', 66 for the letter 'B', and so on up to the value of 90 for the letter 'Z'.
Example of output:
1.5 1 ahuguada
In the example above, the process was terminated because the letter 'U' was generated consecutively.
1.5 2 auydyada
In the example above, the process was terminated because the letter 'C' was generated consecutively.

NOTE: The output your program generates may differ from the output examples, because the letters are randomly generated. The string that is generated can contain less or more characters than the strings supplied in the examples. (10)

  • Enter your examination number as a comment in the first line of the program file.
  • Save your program.
  • Print the code if required.

TOTAL SECTION A: 40

SECTION B
QUESTION 2: SQL AND DATABASE PROGRAMMING
The database HikingDB contains information of members of different hiking clubs. The database contains two tables, namely tblClubs and tblMembers.

The data pages attached at the end of the question paper provide information on the design of the database and its contents.
Do the following:

  • Open the incomplete project file called Question2_P.dpr in the Question 2 folder.
  • Enter your examination number as a comment in the first line of the Question2_U.pas unit file.
  • Compile and execute the program. The program has no functionality currently. The contents of the tables are displayed as shown below on the selection of tab sheet Question 2.2 - Delphi code.

2 addada

  • Follow the instructions that follow to complete the code for each section as described in QUESTION 2.1 and QUESTION 2.2.

NOTE:

  • The 'Restore database' button is provided to restore the data contained in the database to the original content.
  • Code is provided to link the GUI components to the database. Do NOT change any of the code provided.
  • TWO variables are declared as public variables as described in the table below.
 Variable   Data type  Description 
 tblClubs   TADOTable  Refers to the table tblClubs
 tblMembers   TADOTable  Refers to the table tblMembers

2.1 Tab sheet [Question 2.1 - SQL]
Example of graphical user interface (GUI) for QUESTION 2.1:
2.1 adadda
NOTE: Code to execute the SQL statements and display the results of the queries is provided. The SQL statements assigned to the variables sSQL1, sSQL2, sSQL3, sSQL4 and sSQL5 are incomplete.
Use ONLY SQL code to complete the SQL statements for QUESTION 2.1.1 to QUESTION 2.1.5 that follow.

2.1.1 Button [2.1.1 - Clubs from Gauteng and SA affiliated]
Display the names and the towns of all clubs in Gauteng (GP) that are SA affiliated.
Example of output:
2.1.1 adadada
(3)

2.1.2 Button [2.1.2 - Birth year]
Display the name, surname and date of birth of all members who were born in 2002.
Example of output:
2.1.2 adadada
NOTE: The date format may differ from the example in the output. (3)
2.1.3 Button [2.1.3 - Display members]
Code has been provided to select a ClubName from the
cmbQ2_1_3 combo box.
Display the surname and name of members from the club selected in the combo box.
Example of output if Kamma Hiking is selected:
2.1.3 auygdad
(4)
2.1.4 Button [2.1.4 - Average membership fee]
Display the province and the average membership fee per province where the average membership fee is more than R400.
The average membership fee per province must be a calculated field with the heading AvgFee and it must be displayed as currency.
Example of output:
2.1.4 quygdada
(6)

2.1.5 Button [2.1.5 - Change member name]
Write code to change all member names spelled as 'Aiensley' to 'Ainsley'. (3)

2.2 Tab sheet [Question 2.2 - Delphi code]
Example of graphical user interface (GUI) for QUESTION 2.2:
2.2 Hfxytad
NOTE:

  • Use ONLY Delphi programming code to answer QUESTION 2.2.1 to QUESTION 2.2.3.
  • NO marks will be awarded for SQL statements in QUESTION 2.2.

2.2.1 Button [2.2.1 - Outstanding fees]
Write code to display the club name and annual membership fee as part of a heading and the surname, amount paid and outstanding fees for each club member in the redQ2_2_1 rich edit.
2.2.1 uzyguxada
(12)
2.2.2 Button [2.2.2 - Update hikes completed]
Select a member from the tblMembers table in the dbgrid (dbgrdMany) who completed another hike.
Write code to increment the HikesCompleted field, by one for the member selected in the dbgrid. (4)

2.2.3 Button [2.2.3 - Add member]
Only the following clubs allow new member to join:

Mountain Free
Boks Hiking
Printfoot Hiking

The IDs and names of these clubs are listed in the rgpQ2_2_3 component in the following format: <ClubID>. <ClubName> with the caption 'Clubname'.

Code has been provided to assign the surname, name, date of birth and membership code of a new member to variables.
NOTE: To add a new member, the user must first select a club name from the rgpQ2_2_3 radio group.
Write code to do the following:

  • Extract the ClubID from the club selected in the rgpQ2_2_3 radio group.
  • Assign the provided variables to the corresponding member fields and the ClubID to the ClubID member field.
  • Add the required statement(s) to ensure that the new member's details are saved in the database table.

NOTE: You can add the member ONCE only. If you want to test your code by adding the member again, first restore the database to its original content before testing the code again. (5)

  • Enter your examination number as a comment in the first line of the program file.
  • Save your program.
  • Print the code if required.

TOTAL SECTION B: 40

SECTION C
QUESTION 3: OBJECT-ORIENTATED PROGRAMMING

Do the following:

  • Open the incomplete program in the Question 3 folder.
  • Open the incomplete object class HikingTrail_U.pas.
  • Enter your examination number as a comment in the first line of both the Question3_U.pas file and the HikingTrail_U.pas file.
  • Compile and execute the program. The program has no functionality currently.

Example of graphical user interface (GUI):
3.1 auigdadad

  • Complete the code as specified in QUESTION 3.1 and QUESTION 3.2.

NOTE: For this question, you are NOT allowed to include any additional attributes or user-defined methods unless explicitly stated in the question.

3.1 The incomplete object class (THikingTrail) provided contains code for the declaration of five attributes that describe a HikingTrail object.
The attributes for a HikingTrail object have been declared as follows:

Attribute   Description 
 fTrailName   The name of the hiking trail
 fTerrainType   The type of terrain, e.g. Rocky
 fNumberOfDays   The number of days it takes to complete the trail
 fDistance   The total distance of the hiking trail in kilometres
 fCostPP   The cost to book the hiking trail per person

A constructor that assigns parameter values to the attributes has been provided.
Complete the code in the object class as described in QUESTION 3.1.1 to QUESTION 3.1.5 below.
3.1.1 Write an accessor method called getNumberOfDays for the fNumberOfDays attribute. (2)
3.1.2 Write a method calcDistPerDay to calculate and return the average number of kilometres that must be completed per day to complete the trail within the required number of days, rounded off to the nearest integer. (3)
3.1.3 Write a method called determineLevel to determine and return the difficulty level of the trail as a string. The difficulty level can be advanced, moderate or easy.
Write code to do the following:

  • Call the calcDistPerDay method to calculate and return the distance that must be completed per day.
  • Use the distance per day value to determine the difficulty level as follows:
    • 'Advanced' if the distance per day is more than 15 km and the terrain is 'Rocky' or 'Sandy'.
    • 'Moderate' if the distance per day is from 10 km to 15 km.
    • 'Easy' if the difficulty level is neither 'Advanced' nor 'Moderate'. (10)

3.1.4 Write a method called calcTotalCost to receive the number of hikers in a group as a parameter and return the total cost for the group, based on the fCostPP attribute value. (4)
3.1.5 Write a toString method to return all the attributes of the object in the following format:

<Name of hiking trail>: <Type of terrain>
<distance> km in <number of days> days
Cost per person: <Cost> formatted to currency

Example:

Amatola Hiking Trail: Rocky
100 km in 6 days
Cost per person: R1500.00 
(4)

3.2 An incomplete program has been supplied in the Question 3 folder. The program contains code for the object class to be accessible and declares an object variable called objHikingTrail.
Write code to perform the tasks described in QUESTION 3.2.1 to QUESTION 3.2.4.

3.2.1 Combo box - cmbQ3_2_1
Information on hiking trails are provided in different text files.
The name of the hiking trail, as provided in the combo box cmbQ3_2_1, is the same as the name of the text file. The extension of all text files is '.txt'.
Each text file contains four lines of information in the following format:

Type of terrain
Total distance in km
Total number of days
Cost of booking the trail for one person

For example, the content of the text file Amatola Hiking Trail is:

Rocky
100
6
1500

Code has been provided to extract the selected hiking trail from the combo box cmbQ3_2_1 and to display an image of the hiking trail in the image component.
Each time the name of the hiking trail is selected in the combo box, a new object must be instantiated.
Write code to do the following:

  • Open the correct text file to read from using the name of the selected hiking trail.
  • Read the terrain, distance, number of days and the cost per person from the text file.
  • Use this information and the name of the hiking trail to instantiate a new hiking trail object.
  • Display a message using a dialogue box to indicate that the object has been instantiated successfully.

Example of output:
3.2.1 auygdada
(8)

3.2.2 Button [3.2.2 - Display hiking trail details]
Write code to use the toString method to display the object's information in the redQ3_2_2 component.
Example of output if the Amatola Hiking Trail is selected:
3.2.2 auydada
(2)

3.2.3 Button [3.2.3 - Display cost]
Write code to do the following:

  • Use an input box to enter the number of hikers in the group.
  • Use the calculateCost method to assign the cost for the group to the provided cost variable.

Example of output if the Amatola Hiking Trail is selected and the size of the group is 7:
3.2.3 iuhdada
(4)
3.2.4 Button [3.2.4 – Calculate distance per day]
Write code to use the object's methods and display the difficulty level and recommended distance per day in the following format for the selected hiking trail in the redQ3_2_4 rich edit:

You have to cover at least <distance per day> km per day to complete this <difficulty level> hiking trail in <number of days> days.

Example of output if the Amatola Hiking Trail is selected:
pg 18 aigda
Example of output if the Rim of Africa hiking trail is selected:
page 18 2 adadad
(3)

  • Enter your examination number as a comment in the first line of the object class and the form class.
  • Save your program.
  • Print the code of the object class and the form class if required. 

TOTAL SECTION C: 40

SECTION D
QUESTION 4: PROBLEM-SOLVING PROGRAMMING
Hikers use a distance chart to plan their hiking trips. Checkpoints refer to rest areas or overnight locations on a hiking trail. A distance chart consists of the distances between different checkpoints on a hiking trail.

Do the following:

  • Open the incomplete program in the Question 4 folder.
  • Enter your examination number as a comment in the first line of the Question4_U.pas file.
  • Compile and execute the program. The program has no functionality currently.

Example of the graphical user interface (GUI):
4 auygda

The following have been provided in the program:

  • The names of checkpoints are stored in a one-dimensional array named arrNames: arrNames: array[1..5] of String =
    ('Morgan', 'Haga Haga', 'Cintsa', 'Beacon', 'Gonubie');
  • The distances between the checkpoints on the trail are stored in a two-dimensional array named arrDistances in number of kilometres:
    arrDistances: array[1..5,1..5] of real =
    ((0, 6.2, 9, 13.2, 16.2),
    (6.2, 0, 13.37, 8.74, 12.86),
    (9.57, 13.37, 0, 9.63, 24.63),
    (13.2, 8.74, 9.63, 0, 15.2),
    (16.2, 12.86, 24.63, 15, 0));
  • Code has been provided to display the headings for QUESTION 4.1 and QUESTION 4.2.
  • Write code to perform the tasks described in QUESTION 4.1 to QUESTION 4.3.

4.1 Button [4.1 - Display distance chart]
Write code to display the names of the checkpoints from the array, arrNames, and the contents of the two dimensional array, arrDistances, in neat columns in the rich edit redQ4 provided.

NOTE: The intersection between two of the same checkpoints has a value of 0.

Example of output:
NOTE: Tabs and blank lines in the example output are included for readability and are NOT required as part of the output of the program.
4.1 agydada
(5)

4.2 Button [4.2 - Validation]

Some of the values in the distance chart in the array arrDistances were rounded down to an integer value. These inaccurate integer values need to be replaced by the more accurate decimal value in the corresponding row and column.
Write code to do the following:

  • Check if the corresponding row and column in the arrDistances array are exactly the same.

For example:
The value at arrDistance[1,3] must be the same as the value at arrDistance[3,1], the value at arrDistance[4,2] must be the same as the value at arrDistance[2,4] and so on.

  • For each inaccurate value that is identified, replace the inaccurate integer value with the accurate corresponding decimal value.
  • Display the position of the inaccurate value(s) that were identified as a row and column number followed by the accurate decimal value that will replace the inaccurate integer value in the following format:
    [row value, column value] with <accurate value> 

Example of output:
pg 21 a aiudhad
Example of the updated two-dimensional array:
pg21 b adadad
(8)

4.3 Button [4.3 - Route planner]
Hikers can select one of different routes listed in the cmbRoutes combo box to do a hiking trail.

The hiker must select a possible route in the combo box.

If the hiker selects the route '4,3,1,2,5', it means that the hiking trail starts at the Beacon checkpoint. The route then continues towards the Cintsa, Morgan and Haga Haga checkpoints with Gonubie being the last checkpoint.

An itinerary needs to be compiled and displayed for the route selected.
Write code to do the following:

  • Extract the route from the cmbRoutes combo box and display the selected route in the redQ4 rich edit.
  • Use the information in the arrNames array to display the names of each pair of checkpoints and the array arrDistances to display the distance between each pair of checkpoints.
  • Determine and display the approximate time (in minutes) it will take to complete the hike between the pairs of checkpoints. Use the following information:
    • It takes 20 minutes to walk a distance of 1 km.
    • It takes double this time to walk the same distance on the rocky route between Haga Haga (checkpoint 2) and Beacon (checkpoint 4).
  • If the total time spent hiking for one day is more than 8 hours (480 minutes), the hiker must book accommodation to stay overnight at the last checkpoint for that day. The name(s) of the overnight checkpoint(s) must be displayed.
  • Calculate and display the total distance of the hike in kilometres.

Example of output if the selected route is 4,3,1,2,5:
pg 22 agdfgtadad
Example of output if the selected route is 2,4,3,5,1:
pg 22 b aiudhada

  • Enter your examination number as a comment in the first line of the program file.
  • Save your program.
  • Print the code if required.

TOTAL SECTION D: 30
GRAND TOTAL:  150

INFORMATION TECHNOLOGY P1 (2)
DATABASE INFORMATION QUESTION 2:

The design of the database tables is as follows:
Table: tblClubs
The table contains the information of hiking clubs in different provinces.

Field name

Data type

Description

ClubID (PK)

Number

A unique number assigned to the club

ClubName

Text (20)

The name of the hiking club

ClubTown

Text (25)

The town where the club is situated

Province

Text (20)

The province where the club is situated

SA_Affiliated

Boolean

Boolean field indicating whether the hiking club

is affiliated with the SA hiking club or not

MemFee

Currency

Annual membership fee

Example of the first ten records in the tblClubs table:
pg 23 aidada
Table: tblMembers
This table contains the information of members in different hiking clubs.

Field name

Data type

Description

MemberCode (PK)

Text (7)

A unique code assigned to each member

MemberSurname

Text (20)

The surname of the member

MemberName

Text (20)

The name of the member

BirthDate

Date/Time

The birthday of the member

HikesCompleted

Number

The total number of hikes completed by the member

AmountPaid

Currency

The amount paid by the member towards the membership fee

ClubID (FK)

Number

A number that connects the member to the club where the member is registered

Example of the first ten records in the tblMembers table:
pg 24a dauhda
NOTE: Connection code has been provided.

The following one-to-many relationship with referential integrity exists between the two tables in the database:
pg 24 b aiuugdad

Last modified on Thursday, 01 December 2022 12:53