Important
- Do you own work
- No late assignments accepted
- Only turn in .cpp and .h files, no ZIP files or anything else (50% penalty if not)
You will be constructing a series of elecrtonic devices and integrating them in a short program.
You will draw heavily from our discussions of classes and abstract classes.
What you need to do
You will need to implement the following classes, obeying the instructions below (but there may be more you need to do, based on ComputerLand code). Each class must have its own .cpp and .h file.
- PowerSource (a concrete class), which supports the following:
- Holds up to 6 ElectronicDevice objects (in an array)
- An attach() method, per use in ComputerLand
- Has a printInventory() method that calls getSummary() on all its devices
- ElectronicDevice (an abstract class), with the following
- A pure virtual method called getSummary() that returns a String
- Computer (an abstract class that is a type of ElectronicDevice), with the following:
- Constructor that takes name (String) and storage (int) as parameters. The storage parameter is just a number, there are no units (like GB or MB).
- Can be associated with a Printer, as shown in ComputerLand code
- Must support a save() method that takes an amount of storage needed and decrements the storage available (no filenames required).
- Provides print() and scan() functions, which leverage the Printer. When scanning, should call local save() (each page requires 5 units of storage)
- Has an abatract method called getOperatingSystem() that returns a String
- Implements getSummary()
- Printer (an abstract class that is a type of ElectronicDevice)
- Supports pure virtual method print() method that takes a jobName (String) and number of pages (int). It returns nothing.
- Supports pure virtual methods scan() method that takes a jobName, number of pages to scan. It returns nothing.
- AppleMacbook (a concrete type of Computer)
- Must call superclass constructor. Has “OS X” operating system
- DellDesktop (a concrete type of Computer)
- Must call superclass constructor. Has “Windows” operating system
- EpsonPrinter (a concrete type of Computer that also can act as a Printer)
- Must call superclass constructor
- Logs each virtual scan to output (see below)
- Logs each page virtually printed (as it is printed) to output (see below)
- Has “Linux” operating system
- ComputerLand (included, see below)
You must combine your work with the following ComputerLand.cpp file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
int main() #123; Computer* mac = new AppleMacbook("MyMac", 1000); Computer* dell = new DellDesktop("MyDell", 500); EpsonPrinter* epson = new EpsonPrinter("MyEpson", 2);
PowerSource* source = new PowerSource();
source-gt;attach(mac); source-gt;attach(dell); source-gt;attach(epson);
mac-gt;addPrinter(epson); dell-gt;addPrinter(epson);
mac-gt;scan("Passport application", 10); mac-gt;print("Story", 5);
dell-gt;scan("Taxes", 25); dell-gt;print("License areement", 2);
source-gt;printInventory(); #125;
|
so that the following is produced (exactly) when ComputerLand is run:
Scanning 10 pages of Passport application
Printing page 5 of Story
Printing page 5 of Story
Printing page 5 of Story
Printing page 5 of Story
Printing page 5 of Story
Scanning 25 pages of Taxes
Printing page 2 of License areement
Printing page 2 of License areement
=== INVENTORY ===
MyMac, running OS X with storage = 950
MyDell, running Windows with storage = 375
MyEpson, running Linux with storage = 2