Final Oop
Final Oop
Page 1 of 2
Finally, write a main program that creates a time object and initializes it with current time, and
creates another time object and reads its data from the keyboard, then
• Copy the first object to the second and display the result.
• Add the two objects and display the result.
• Compares these two times and displays them with a message indicating the result of the
comparison.
Question 3: [20 Marks]
A) Define a class productspec, which has three data members: description (type string) , price
(type double), and itemid (type int). that represents the descriptions, price, and id of a product.
It has a constructor and 2 member functions: set_data(), which accept all data of a product and
store it in the data member ; get_price(), which return the price of product object; and an
insertion operator << that displays the description of product object.
B) Define a class SalesLineItem, which has two data members: quantity (type int), spec (object
from class productspec), it has 4 member functions: set_data(), which accept all data of item
and store it in the data member; get_subtotal(), which return the result of price × quantity,
get_quantity(), which return the quantity, and show_data(), that displays the data of
saleslineitem object.
C) Define a class Sale, which has 4 data members:sale_id (type int), date (type string), salelist (
array of object from class saleslineitem), and no_items (an int represent the no of items). it has
a constructor, and three member functions enteritem(), that accept a saleslineitem object and
enter it in the array salelist, get_total(), that calculate and return the total of all salelslineitems
record for this sale, display(), that display all items of the sale in 4 columns discerption, price,
quantity, and subtotal, then at the end display the total of the sale.
D) Write main program that reads a sales’s date and id, and creates a sale object for that sale. Then,
the program reads a series of items descriptions, prices, ids, and quantity, until the descriptions
XXX is entered. For each item, a saleslineitem object is created and entered to the array salelist
of the sale object by registering that item with the sale. After all items have been entered, the
data of the sale are displayed, then the total of sale calculated and displayed.
Question 4: [15 Marks]
A) Declare and implement the following class hierarchy:
(i) An abstract base class Shape that has one data member Perim that represents the perimeter
of the shape, and 3 pure virtual member functions: getdata(), showdata(), and getPerim().
(ii) A derived class Triangle that has 3 additional data members, representing the 3 sides of the
triangle, and implements the 3 member functions: getdata(), to read the 3 sides of the
triangle; showdata(), to display the triangle data; and getPerim(), to calculate the perimeter
of the triangle.
(iii) A derived class Rectangle that has additional 2 data members, representing the length and
width of the rectangle, and implements the 3 member functions: getdata(), to read the length
and width of the rectangle; showdata(), to display the rectangle data; and getPerim(), to
calculate the perimeter of the rectangle.
B) Write a main program that creates an array of 10 pointers to Shape. In a loop, ask the user for
data about a shape and its type (triangle or rectangle), and use new to create a suitable object
(Triangle or Rectangle) to hold the data, then put the pointer to the object in the array. When
the user finishes entering the data for all shapes, display the data of all the shapes entered.
With My Best Wishes
Dr. Alaa Zaki
Page 2 of 2