All pastes #252948 Raw Edit

Anonymous

public text v1 · immutable
#252948 ·published 2006-11-20 03:21 UTC
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);
            void displayValues();
}; // Class BookInventory


BookInventory::BookInventory(string title, string publicationYear, string author, int inventory) :
                                    Book(title, publicationYear, author)
{

             
} // Constructor BookInventory

int BookInventory::operator+(int amount)
{
    cout << inventory;
    inventory = inventory + amount;
    cout << inventory;
}

void BookInventory::displayValues()
{
cout<<"Title: "<<title<<" Year: "<<publicationYear<<" Author: "<<author<< " Inventory: " << inventory << endl;
}


int main()
{
    BookInventory book1 = BookInventory("C++ Programming Guide", "2006", "Milton Jones", 2);
    book1.Book::displayValues();
    cout<<"Adding 10 to inventory."<<endl;
    book1.operator+(10);
    //book1 = book1 + 10;
    book1.displayValues();
   
    cout<<"Subtracting 10 from inventory."<<endl;
    //book1 = book1 - 10;
    book1.displayValues();
    system("PAUSE");
    
    return 0;
}