0% found this document useful (0 votes)
28 views4 pages

Oop Activity 4 April 2024

Uploaded by

lindiwe lindiwe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views4 pages

Oop Activity 4 April 2024

Uploaded by

lindiwe lindiwe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

OOP

Object Oriented Programming

Mock Test
Grade 12
Information Technology

Download the data files at


https://drive.google.com/drive/folders/1jkdd74OYmfas2dlsD9xxGebo9Q27AAgH?usp=sharing
You are required to complete the code for the relevant event handlers to create a functional
program that will allow a user to book students and their partners at different tables at the matric
dance.

1.1 Open the unit named clsMDTable_u from the OOP Test folder. An incomplete object
class (TMDTable) is provided which contains the declaration of four attributes which
describe an ‘TMDTable’ object.

The attributes for the TMDTable object have been declared as follows:
• fTableNum – table number (integer)
• fStudents – total number of students at the table (integer)
• fPartners – total number of partners at the table (integer)
• fNamesList – list of names of the students at the table, separated by commas
(string)

All fields are private and all methods are public. The methods that you need to create,
and code are described below:

1.1.1 Write a parameterised constructor accepting ONE parameter for the table’s number. All
the other (integer) fields must be set to 0 by default and the fNamesList must be set to
the null (empty) string. (3)

1.1.2 Write a method named GetTableSize that returns the SUM of the total number of
students and the total number of partners at the table. (2)

1.1.3 Write a method named TableCost that returns the total cost to be paid for the table.
The
cost is calculated as R500 for each student and R700 for each partner. (3)

1.1.4 Write a method named AddSingle that accepts a student’s name (string) as a
parameter. This method must:
• Increase the number of students by 1.
• Add the student’s name to the fNameList followed by a comma. (3)

1.1.5 Write a method named AddCouple that accepts a student’s name (string) as a
parameter. This method must:
• Increase the number of students by 1.
• Increase the number of partners by 1.
• Add the student’s name to the fNameList followed by the text “+Partner”
followed
by a comma. (4)

1.1.6 Write a method named GetStats that returns a string in the following format:
Students:<tab><value for number of students at a table>
Partners:<tab><value for number of partners at a table>

A possible example of a string that is returned could look like:


Students: 6
Partners: 4 (3)
1.1.7 A toString method has been created for you that creates and returns a string called
sLine. The sLine string currently contains all the details for a specific table number.
Add code to the method that will add a list of the names of the students at the table to
the sLine string before it is returned.

The name of the students will be contained in the fNamesList string separated by
commas. If the student is attending the Matric Dance with a partner, then their name
will appear in the fNamesList with a “+Partner” text afterwards.

An example of a possible fNamesList:


Bruce Kent,Diana Banner+Partner,James Gold+Partner,Susan Field,

If the student is attending the dance with a partner (text “+Partner” appears at the end
of their name) then their name must appear in the sLine string with the text “with
partner” after it. If the student is attending the dance WITHOUT a partner (no text after
their name), then just their name must appear in the sLine string.

Each name must appear on a new line.

HINT: Each student’s name ends with a comma character (“,”) and the number of names that
need to be extracted is the same as the value in the fStudents variable.

If the fNameList example given above was used and the table number was a 1, then
the returned string would be:
Table Number: 1
Bruce Kent
Diana Banner with partner
James Gold with partner
Susan Field
(8)
[26]

1.2 You are going to use your class to complete the following code for the event handlers
for the remaining components on the form. Open the Project1 file from the OOP Test
folder.

1.2.1 Complete the code for the onClick event handler for btnQ121 that takes as input the
table number name from the spnTablenumber spin edit control and instantiate an
object for the table using this value.
(2)
1.2.2 Complete the code for the btnQ122 button that takes as input the name of the student
via the edtName edit control and will add this student to the table.
A suitable message must be displayed if there is no space available at the table:
• A student can only be added if there is space at the table.
• A table can take a maximum of 10 people.
• A student can’t be added if a table already has 10 people OR a couple can’t be
added (couples will be indicated via the cbxPartner checkbox control) if there
are more than 9 people at the table.
If there is space available, then:
• the student must be added to the table using the appropriate “Add” method.
• if the student has a partner (indicated via the cbxPartner checkbox control)
then the AddCouple method must be used
• if the student is going alone, then the AddSingle method must be used.

Details of the table (toString method) must be displayed in the redDisplay rich edit
control.

If the table is full (has 10 people) after a student


is added, then the text “Table is FULL” AND the
table cost and the statistics of the table must be
displayed in the redDisplay rich edit control as
shown in the diagram below.

(17)
[19]

TOTAL = 45

Video answers to the above questions can be found on our channel at

youtube.com/user/MrLongEducation

facebook.com/MrLongEducation

@MrLongEdu

Part 1: https://youtu.be/NqMYKNsC93o
Part 2: https://youtu.be/oEqM3xxi9J0

You might also like