Exam OOP 2021
Exam OOP 2021
Practice Test
Course: Object Oriented Programming - C++
Duration: 100 minutes
Submit your code (.cpp files and .png file) to the classroom.
You could discuss it with your friends, but please do not copy.
1. (25pts) Define a class called Employee. Declare the following private data
members:
• Employee Id;
• Employee name;
• Gender;
• Department ID.
Also declare the following member functions for your class:
• A constructor to initialize private data members;
• Member functions to set and get employee info;
• A member function to print an employee’s info on the screen.
Define a new class called Manager. Assume that a manager is also an
employee. Create employee and manager objects in the main function.
1
3. (50pts) Assume that a set of two-dimensional (2D) shapes consists of
Rectangles, Squares, and Circles. A shape contains a center point in the x-y
coordinate pair.
Rectangles, Squares, and Circles have their own attributes. Specifically, a
circle has radius as data member, a rectangle has width and height, and a
square has side.
Write a program to:
a. Design and draw a class diagram. Hint: use inheritance and the name of
a parent class could be TwoDShape. Three sub-classes Circle,
Rectangle, and Square inherited from the TwoDShape class. We need a
class Point and the TwoDShape class contains a Point.
b. Implement the class diagram using C++. Create necessary
constructor(s). Inside the class, defines the print() method that prints out
the information of a shape (center point and its own attribute).
c. Write a method to compute a distance between two shapes. The distance
between two shapes is the distance between their two center points
P1=(x1,y1) and P2=(x2,y2) in the xy-plane, is defined as
d( P1, P2 ) = ( x 1 − x2 )2 + ( y1 − y2 )2