rendered paste body#include <iostream>
#include <string>
using namespace std;
class Book
{
protected:
string title;
string publicationYear;
string author;
public:
Book(const string title, const string pubYear, const string author);
void displayValues();
};
Book::Book(const string title, const string pubYear, const string author)
{
this->title = title;
publicationYear = pubYear;
this->author = author;
}
void Book::displayValues()
{
cout<<"Title: "<<title<<" Year: "<<publicationYear<<" Author: "<<author<<endl;
}
// All below is student code
class BookInventory : public Book
{
private:
int inventory;
public:
BookInventory(string, string, string, int);
int operator+(int);
int operator-(int);
void displayValues();
}; // Class BookInventory
BookInventory::BookInventory(string title, string publicationYear, string author, int inventory) :
Book(title, publicationYear, author)
{
title = title;
publicationYear = publicationYear;
author = author;
inventory = inventory;
} // Constructor BookInventory
int BookInventory::operator+(int amount)
{
inventory = inventory + amount;
}// + operator
int BookInventory::operator-(int amount)
{
inventory = inventory - amount;
}//- operator
void BookInventory::displayValues()
{
cout<<"Title: "<<title<<" Year: "<<publicationYear<<" Author: "<<author<< " Inventory: " << inventory << endl;
}//DisplayValues with inventory
int main()
{
BookInventory book1 = BookInventory("C++ Programming Guide", "2006", "Milton Jones", 10);
book1.Book::displayValues();
cout<<"Adding 10 to inventory."<<endl;
book1.operator+(10);
//book1 = book1 + 10;
book1.displayValues();
cout<<"Subtracting 10 from inventory."<<endl;
book1.operator-(10);
//book1 = book1 - 10;
book1.displayValues();
system("PAUSE");
return 0;
}