It1050 Ooc
It1050 Ooc
Final Examination
Year 1, Semester ~ (2018)
Duration: 2 Hours
October 2018
Instructions to Candidates:
a) Explain the difference between a "Structure" and a "Class" in C++by iving examples?
(3 marks)
I A university issues ID cards ( Identity Cards) for its staff and visitors to provide access to
University facilities. Every staff ID will be valid for a year from the dat of issue. It has to be
updated every year. However, the visitors' cards are issued on daily basi .
i) Identify the classes,objects and the attributes in the scenario abov ,and write in a table as
shown below. ( 6 marks)
ii) Briefly explain the terms below by taking examples from the scerario given above.
(6 marks
1. Abstraction
2. Encapsulation
3. Information Hiding
Page1 of 5
d) Consider the UML diagram of a classshown below;
Item
- itemlD : int
- name: char []
- price: double
.
+ ItemO
.. + Item( pid : int, pname : char[])
+ setPrice( pprice : double) : void
+ getPrice( ) : double
+ display () : void
i) Write the coding in C++for the class Item represented above (3 marks)
ii) Write the overloaded constructor of the class Item. (2 marks)
iii) Implement the setPriceO method and the getPriceO method (2 marks)
class A class B
i)
private private
- int numl; int num2;
public : public :
void setNum(int nl ); void set um(int n2 );
void add ( B b); int getN m ();
void display();
. }; } ;
Page2 of 5
iii) Create another object of class A using dynamic Memory allocation nd display the details
appropriately. (You can set numl to 10 and num2 to 20 ) (3.5 marks)
f)
.
Consider the UML diagram given below .
Order OrderDetail
-date: Date
-status : string -quantity: int
-price : c}ouble k> -taxStatus : string
1 1..*
.+calcSubTotaIO : void +calcSubTotalO : void
+caIcTax( ) : float +calcTax( ) : float
+calcTotal( ) : double
i) What is the relationship that exits between these two classes (2 marks)
ii) Write the necessary C++ coding of the two classes. (5 marks)
( You are not required to implement the methods)
Page 3 of 5
Question 02 (15 marks)
a) Consider the following scenario. Do the Noun Verb analysis to identify the classes in the
description. Show clearly how the nouns were rejected using the above rules. (5 marks)
A program isneeded to be implemented to handle the rentals paid by the tenants ( the person
who occupies the room) in a small apartment building. The landlord (owner of the building)
should be able to input the rents paid by individual tenants and also the xpenses incurred in
operating the building. The expenses could be for electricity, water and any repairs done to the
building. The program should be able to display a rent record, which sows t e rents paid by each
tenant for each month, and an expense record, which for each expense rec rds the date, payee,
amount and budget category. The program should also be able to display an annual summary,
which shows total rents paid for the year and total expenses paid in each budget category.
In addition to the above requirements, the landlord wants to keep track of t e basic information
of the tenants such as the name, NIC no, contact details, and details about the rental contract such
as the room number, the joined date and the expected period of stay. The er should be able to
search for details by entering the name or the NIC number of the tenant.
b) Consider the classes identified above and draw the CRC cards for 5 selected classes.
(10 marks)
Read the following .description and identify the classes, attributes, methods a d relationships
between classes; multiplicity specification. Draw a UML class diagram for t e following
scenario using the above features.
Five doctors with three trainee nurses run the "Health First" Medical Center. When a patient
calls for an appointment, he or she usually sees the same doctor, but at bus times, patients may
see any of the doctors or nurses. -:iUnce a patient has been seen by the octor or nurse, the
medical records a e updated and the doctor may also write or a prescri tion for the patient.
Sometimes the doctor considers that the patient needs further tests. Thes may be routine or
intensive. They are carried out at one of the local hospitals.
The Medical also has an emergency unit with four beds that can be u ed by patients with
emergency cases or minor injuries. One doctor is in charge of the emelgency' unit with the
support of a nurse. A patient can be. referred to the local hospital in case of further treatment or
for consultation of a surgeon.
Page 4 of 5
•.
Consider the following class diagram and write the coding for the classes shown in the diagram
considering the relationship among them. You are not required to writ any methods for the
classes.
Hospital
1 1
I
..••..
....••.. -name: String ..•....
",....
-address: String
. -phone: String
*
1..*
Ward
1
*
Doctor
Patient
#Specialty ; String[] *
#Iocation ; String[J -id : String
-gen er: String
* -age: int
-acce ted: Date
-sickness: String[J
-pres ription :String[J
-allergies: String[J
-spec alReq : String[]
",
Consultant Doctor Junior Doctor
- -fee: double -hours : int *
1
Page 5 of 5