In this program, you will implement a simple inheritance relation between office items. We have the parent class “Item” and three child classes: “Pen”, “Folder”, and “Paper”. You will implement these 4 classes. Details of each class is given below: Class: Item Int ID Int Type Int Price String Name Item(…) virtual void print() float discount Price(float rate) Class: Pen String inkColor float pointSize Class: Folder String color bool expanding Class: Paper String size int quantity Pen…) void print() Folder(…) void print() Paper(…) void print() Item is the base class and it contains all common attributes and functions for all items. Each child class has two extra attributes and one print() function to print that item.

Please note that print() function in the Item class is a virtual function. Your responsibility is to create these four classes. To make your work easier, this time I do not expect you to separate each class into a different file. You will fill the “item.h” file that is provided with homework | description. And this time, I am not expecting an “item.cpp” file. You will write everything in the header file. The main program (main.cpp) will also be provided to you. In the main program, all items are loaded into an item array by reading the file, and each item is printed with its discounted price. You do not need to make any changes on the main.cpp file. Each class has a constructor function and a print function. Print functions should print all features of the item. Please see the next figure for a reference. The discountPricel) function in the item class will calculate a discounted price of that item using the “rate” input. For example if the rate is 0.15, then the function will calculate price*(1-rate) and return result from the function.


0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *