Prog Tutorial1 PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

KIE1008 (Programming Tutorial) Session 2016/2017 (Semester 2)

Tutorial 1: Object-Oriented Programming (Composition and Inheritance)

1. Define a class called Text that contains a member variable of type string named text that
stores any textual content for the document. Create the appropriate accessor and mutator
functions.

Class Person that contains member name. Create three constructor functions: Person() and
Person(name). Also create the getName() and setName() functions.

Next, define a class for File that is derived from Text and includes member variables for the
pathname (type String) and author (type Person). Implement appropriate accessor and
mutator.

Next, define a class for Email that includes member variables for the sender, recipient,
title and Text of an email message. Implement appropriate accessor and mutator functions.

Finally, create several sample objects of type Email and File in your main function, and
demonstrate their applications.

Also, use the following function to search for a specific keyword in the object:
bool containKeyword(const Text& obj, string keyword) {
if (obj.getText().find(keyword)!= string::npos)
return true;
return false;
}

[Google to understand this function]

2. Give the definition of two classes: Patient and Billing, whose objects are records for a clinic.
Patient will be derived from the class Person. Patient records the patient’s name and primary
physician, of type Doctor.

Class Person that contains member name. Create three constructor functions: Person(),
Person (name) and Person(const Person&). Also create the getName() and
setName() functions.

The Doctor class is derived from class Person as well, and also record the doctor’s specialty
(“Pediatrician”, “Obstetrician”, “General Practitioner” etc), and office visit fee.
A Billing object contains a Patient object and a Doctor object, and an amount due.

Be sure all your classes have a reasonable complement of constructors and accessor functions,
and an overloaded assignment operator, and a copy constructor.

Write a main function that contains several objects of each class to demonstrate every functions.

--END--

You might also like