Use single inheritance to provide inventory tracking for a book object. Create a
ID: 3621579 • Letter: U
Question
Use single inheritance to provide inventory tracking for a book object. Create a subclass BookInventory that holds an int value representing the inventory for the book. In addition to a constructor this class should overload the + and - operators to increase and decrease the inventory and and the displayValues()function. I need help with the addition to constructor overloading the + and - operators to increase and decreasing the inventory and and the displayValues()function.#include<iostream>
using namespace std;
class BookInventory
{
private:
int bookInv;
public:
BookInventory(int invent = 0);
void showInv();
};
BookInventory::BookInventory(int invent)
{
cout << "Inventory has been expanded." << endl;
bookInv = invent;
}
void BookInventory::showInv()
{
cout << "Inventory:" << bookInv << " ";
}
int main()
{
BookInventory book(1);
book.showInv();
system("pause");
return 0;
}
Explanation / Answer
Dear, Not clear of what you specified but still tried maximum to help you As specified for increase or decrease (bookInv) ++ ,-- operator are needed Here is the code #include using namespace std; class BookInventory { private: int bookInv; public: BookInventory(int invent = 0); BookInventory operator++() ; BookInventory operator--(); void displayValues(); }; BookInventory BookInventory:: operator++() { bookInv++; return *this; } BookInventory BookInventory:: operator--() { bookInv--; return *this; } BookInventory::BookInventory(int invent) { coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.