Question: For this question, you will use Polymorphism to simulate the behavior of the inventory of an electronics store. The store will have only two types

For this question, you will use Polymorphism to simulate the behavior of the inventory of an electronics store.
The store will have only two types of devices (Computers and Printers).
Complete the following classes following the instruction to achieve polymorphism for this exercise.
GenericDevice class
This class is an abstract base class of the Computer and Printer classes. You must add the virtual qualifier to the methods of this class when needed.
How to determine that a method needs to be virtual: the method is defined in GenericDevice but overridden in the child classes.
How to determine that a method needs to be pure virtual: this method has not been defined in GenericDevice (not implemented in GenericDevice.cpp).
Computer class
This class is a derived class from GenericDevice. Complete the class so that it inherits from GenericDevice and add the virtual qualifier to the methods of this class when needed. Additionally, add a definition of the getType() function that returns the string "Computer".
Printer class
This class is a derived class from GenericDevice. Complete the class so that it inherits from GenericDevice and add the virtual qualifier to the methods of this class when needed. Additionally, add a definition of the getType() function that returns the string "Printer".
ElectronicStoreInventory class
This class will have the information about the inventory of the store.
ElectronicStoreInventory has 2 attributes:
Inventory (*GenericDevice): an array of pointers of GenericDevice type. The size of the array is fixed (const MAX_SIZE =100).
count (int): the number of items in inventory.
You must implement the following member functions:
Default constructor: By default, the inventory is created empty (count =0) and every element of the array of pointers is set to null.
Add device: receives a reference to a GenericDevice and returns a boolean value (true if the device can be added to the store inventory, false otherwise). A device can not be added if the inventory is full. To add a device, you must first determine if it is a computer or a printer (by using getType), then allocate a new object of that type and save the address in Inventory. You will also need to cast the reference passed as parameter to be the right type. For example, to add a computer to the inventory, you will need a statement like this:
Inventory[i]= new Computer((Computer &)_device);
where _device is the parameter (in the argument list of the function) passed to add Device. You can also check the copy constructor (provided) for a syntax example.
Remove device: receives a string with the serial number of the device to be deleted and returns a boolean value (true if the device is in the store inventory, false otherwise). To remove a device, delete it and set that Inventory element to nullptr.
Print: uses the print functions from the Computer and Printer classes to list the devices in the store inventory.
Summary: prints the information about the number of computers and printers in the store inventory. Use the following cout statements for the summary function:
std::cout << "Total number of computers in the store ="<</* Number of Computers identifier */<< std::endl; std::cout << "Total number of printers in the store ="<</* Number of Printers identifier */<< std::endl;
Destructor. The destructor must delete all items in the inventory.
NOTES:
You can safely assume that the input will always be valid.
EXAMPLE: The following main() function can be used to test your implementation. Please use it only after you complete the above tasks; otherwise, you may encounter compiling errors.
int main(){ Computer C1("Intel I5","SSD",1024,16,"DELL","Desktop Computer","123456"); Computer C2("Intel I5","SSD",1024,16,"DELL","Laptop Computer","123457"); Computer C3("Intel I5","SSD",1024,16,"DELL","Laptop Computer","123458"); Printer P1(10,"YES","BROTHER","Laser Printer","654321"); Printer P2(11,"NO","HP","Inject Printer","654322"); ElectronicStoreInventory myStore; myStore.addDevice(C1); myStore.addDevice(P1); myStore.addDevice(C2); myStore.addDevice(C3); myStore.addDevice(P2); myStore.removeDevice("123458"); myStore.print(); myStore.summary(); return 0; }
OUTPUT:
Computer: CPU = Intel I5, Disk type = SSD, Disk size (GB)=1024, Manufacturer = DELL, Description = Desktop Computer, SN =123456 Printer: PPM =10, Color Printer = YES, Manufacturer = BROTHER, Description = Laser Printer, SN =654321 Computer: CPU = Intel I5, Disk type = SSD, Disk size (GB)=1024, Manufacturer = DELL, Description = Laptop Computer, SN =123457 Printer: PPM =11, Color Printer = NO, Manufacturer = HP, Description = Inject Printer, SN =654322 Total number of computers in the store =2 Total number of printers in the store =2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!