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 attributes:
Inventory GenericDevice: an array of pointers of GenericDevice type. The size of the array is fixed const MAXSIZE
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 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:
Inventoryi new ComputerComputer &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 CIntel ISSD"DELL","Desktop Computer","; Computer CIntel ISSD"DELL","Laptop Computer","; Computer CIntel ISSD"DELL","Laptop Computer","; Printer P"YES","BROTHER","Laser Printer","; Printer PNOHP"Inject Printer","; ElectronicStoreInventory myStore; myStore.addDeviceC; myStore.addDeviceP; myStore.addDeviceC; myStore.addDeviceC; myStore.addDeviceP; myStore.removeDevice; myStore.print; myStore.summary; return ;
OUTPUT:
Computer: CPU Intel I Disk type SSD Disk size GB Manufacturer DELL, Description Desktop Computer, SN Printer: PPM Color Printer YES, Manufacturer BROTHER, Description Laser Printer, SN Computer: CPU Intel I Disk type SSD Disk size GB Manufacturer DELL, Description Laptop Computer, SN Printer: PPM Color Printer NO Manufacturer HP Description Inject Printer, SN Total number of computers in the store Total number of printers in the store
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
