Printer Deletes Its Own Cartridge
mediumQuestion 700Write TWO classes. Printer owns a Cartridge that it creates on the heap in its constructor.
Cartridge (write it first):
Cartridge(int ink); // private member: int inkLevel
int getInk() const;
void use(int amount); // subtract amount from inkLevelPrinter private members: Cartridge* cartridge; and int pagesPrinted;. Public interface:
Printer(int startingInk); // cartridge = new Cartridge(startingInk); pagesPrinted = 0
~Printer(); // the cartridge is owned here - release it
void printPages(int pages);
int inkLeft() const; // the ink still in the cartridge
int pages() const; // pages actually printed, over all callsprintPages(int pages) prints up to that many pages at 2 ink each. If the cartridge has less than 2 ink left, printing STOPS and the remaining pages are skipped. Every page printed adds 1 to pagesPrinted.
The driver reads startingInk firstRequest secondRequest. For the input:
10 3 4the exact output is what is shown in Expected Output.
Free the memory you allocate — this question checks for memory leaks.
Do NOT write a main function.
Expected output
pages=5 ink=0
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
Pointers
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.