0% found this document useful (0 votes)
13 views2 pages

Exam OOP 2021

Uploaded by

10422017
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)
13 views2 pages

Exam OOP 2021

Uploaded by

10422017
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/ 2

VIETNAMESE-GERMAN UNIVSREITY

COMPUTER SCIENCE PROGRAM

Practice Test
Course: Object Oriented Programming - C++
Duration: 100 minutes

Break time from 10:20 AM – 12:00 PM


Please self-organize and come back to your seat on time after the break time.

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.

2. (25pts) Write a program to create a class called Complex which is used to


represent complex numbers. The class will have two private float data
members (real part and imaginary part). Add the following member methods:
• a default constructor;
• a constructor with parameters;
• a copy constructor;
• overloaded plus operator (+);
• overloaded comparison operator (==);
• overloaded assignment operator (=).

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

d. Write the double perimeter() method to calculate the perimeter of 2D


shape.
e. Write the double area() method to calculate the area of 2D shape.
f. (Self-learning) Googling and learning how to use vector to store a list of
objects. In addition, learning how to sort a vector of objects.
g. Given a vector of N 2D-shapes in the main function, and each element is
a circle, rectangle, or square. Write a method to compute the total area of
all the shapes.
h. (***) Given a vector of N 2D-shapes in the main function, and each
element is a circle, rectangle, or square. Write a method to print their
perimeters in decreasing order.

You might also like