Script started on Thu Mar 20 21:00:20 2003
[root@Fizzgig /root]# cd C
[root@Fizzgig C]# cat makefile

inventory: main.o item.o book.o software.o
	g++ -g main.o item.o book.o software.o -o inventory

main2.o: main.cpp inventory.h
	g++ -c main2.cpp

item.o: item.cpp inventory.h
	g++ -c item.cpp

book.o: book.cpp inventory.h
	g++ -c book.cpp

software.o: software.cpp inventory.h
	g++ -c software.cpp

[root@Fizzgig C]# cat inventory.h
/*  inventory.h  */
/* All the classes are declared here */
#include <stdio.h>
#include <string.h>
char *strdup(char *s);

class Item {
private:
    char *stockNo;
    char *name;
    double price;
    int inStock;
    static double totalValue;
public:
    Item(char *sNo, char *n, double p, int q);
    Item(char *sNo, char *n);
    char *getStockNo() {return stockNo;};
    char *getName() {return name;};
    double getPrice() {return price;};
    int getInStock() {return inStock;};
    void addStock(int n);
    void removeStock(int n);
    void setPrice(double p);
    virtual void print();
    static double getTotalValue(){return totalValue;};
};

class Book: public Item {
private:
    char *publisher;
    char *author;
    static double totalValue;
public:
    Book(char *stockNo, char *name, char *publisher,
        char *author, double price, int count);
    Book(char *stockNo, char *name, char *publisher,
        char *author);
    char *getPublisher(){return publisher;};
    char *getAuthor(){return publisher;};
    void addStock(int n);
    void removeStock(int n);
    void setPrice(double p);
    void print();
   static double getTotalValue() {return totalValue;};
};

class Software: public Item {
private:
    char *publisher;
    char *version;
    static double totalValue;
public:
    Software(char *stockNo, char *name, char *publisher,
        char *version, double price, int count);
    Software(char *stockNo, char *name, char *publisher,
        char *version);
    char *getPublisher(){return publisher;};
    char *getVersion(){return version;};
    void addStock(int n);
    void removeStock(int n);
    void setPrice(double p);
    void print();
    static double getTotalValue() {return totalValue;};
};

[root@Fizzgig C]# cat item.cpp

/* item.cpp */
/* The item super class used in an inventory-tracking program */

/* Author: Zach Tomaszewski */
/* Date: 19 Mar 2003 */


#include "inventory.h"
#include <iostream>

double Item::totalValue;  //total value of all Items.


// -------- Constructors -----------

/*
 Item constructor.
 Takes a stock number, a string name, a price, 
   and a quanity in stock.
*/
Item::Item(char *sNo, char *n, double p, int q){
    stockNo = sNo;
    name = n;
    price = p;
    inStock = q;
    totalValue += price * inStock;
}

/*
 Item constructor.
 Takes only a stock number and a string name.
*/
Item::Item(char *sNo, char *n){
    stockNo = sNo;
    name = n;
}


// --------- Methods -------

/*
 Takes the number of this Item to add to stock.
 Updates total price.
*/
void Item::addStock(int n){
  inStock += n;
  totalValue += (n * price);
}

/*
 Takes the number of this Item to remove from stock.
 Updates total price.
*/
void Item::removeStock(int n){
  inStock -= n;
  totalValue -= (n * getPrice());
}


/*
 Takes the new price for this Item.
 Updates the price as well as totalValue for all Items.
*/
void Item::setPrice(double p){
  //before starting, remove the old price from totalValue
  totalValue -= (getInStock() * getPrice());
  price = p;
  totalValue += (getInStock() * getPrice());
}


/*
 Prints the Item to the screen
*/
void Item::print(){
  cout << getStockNo() << "  " << getName();
  cout << "  \tPrice: $" << getPrice();
  cout << "\t" << getInStock() << " in stock\n";
}

[root@Fizzgig C]# cat book.cpp
/* book.cpp */
/* The Book class used in an inventory-tracking program */

/* Author: Zach Tomaszewski */
/* Date: 19 Mar 2003 */


#include "inventory.h"
#include <iostream>

double Book::totalValue;  //total value of all Books.


// -------- Constructors -----------

/*
 Book constructor.
 Takes a stock number, a string name, a publisher, an author,
   a price, and a quanity in stock.
*/
Book::Book(char *stockNo, char *name, char *publisher,
           char *author, double price, int count)

          :Item(stockNo, name, price, count) {

  this->publisher = publisher;
  this->author = author;
  totalValue += price * count;
}

/*
 Item constructor.
 Takes only a stock number and a string name.
*/
Book::Book(char *stockNo, char *name, char *publisher, char *author) 
         :Item(stockNo, name){
  this->publisher = publisher;
  this->author = author;
}


// --------- Methods -------

/*
 Takes the number of this Book to add to stock.
 Updates total price for Items and Books.
*/
void Book::addStock(int n){
  //casting this to an Item to call Item's addStock.
  Item* b = (static_cast<Item*> (this));
  b->addStock(n);
  *this = *(static_cast<Book*>(b));
  totalValue += (n * getPrice());
}

/*
 Takes the number of this Book to remove from stock.
 Updates total price for Items and Books.
*/
void Book::removeStock(int n){
  //casting this to an Item to call Item's addStock.
  Item* b = (static_cast<Item*> (this));
  b->removeStock(n);
  *this = *(static_cast<Book*>(b));
  totalValue -= (n * getPrice());
}


/*
 Takes the new price for this Book.
 Updates the price as well as totalValue for all Items and all Books.
*/
void Book::setPrice(double p){
  totalValue -= (getInStock() * getPrice());
  Item* b = (static_cast<Item*> (this));
  b->setPrice(p);
  *this = *(static_cast<Book*>(b));
  totalValue += (getInStock() * getPrice());
}


/*
 Prints the Book to the screen
*/
void Book::print(){
  cout << getStockNo() << "  " << getName();
  cout << "  \tPrice: $" << getPrice();
  cout << "\t" << getInStock() << " in stock\n";
  cout << "  Author: " << getAuthor();
  cout << "  \t\tPublisher: " << getPublisher() << endl;
}
[root@Fizzgig C]# cat software.cpp
/* software.cpp */
/* The Software class used in an inventory-tracking program */

/* Author: Zach Tomaszewski */
/* Date: 19 Mar 2003 */


#include "inventory.h"
#include <iostream>

double Software::totalValue;  //total value of all Software.


// -------- Constructors -----------

/*
 Software constructor.
 Takes a stock number, a string name, a publisher, a version,
   a price, and a quanity in stock.
*/
Software::Software(char *stockNo, char *name, char *publisher,
           char *version, double price, int count)

          :Item(stockNo, name, price, count) {

  this->publisher = publisher;
  this->version = version;
  totalValue += price * count;
}

/*
 Software constructor.
 Takes only a stock number and a string name.
*/
Software::Software(char *stockNo, char *name, 
                   char *publisher, char *version) 
         :Item(stockNo, name){
  this->publisher = publisher;
  this->version = version;
}


// --------- Methods -------

/*
 Takes the number of this Software to add to stock.
 Updates total price for Items and Software.
*/
void Software::addStock(int n){
  //casting this to an Item to call Item's addStock.
  Item* b = (static_cast<Item*> (this));
  b->addStock(n);
  *this = *(static_cast<Software*>(b));
  totalValue += (n * getPrice());
}

/*
 Takes the number of this Software to remove from stock.
 Updates total price for Items and Softwares.
*/
void Software::removeStock(int n){
  //casting this to an Item to call Item's addStock.
  Item* b = (static_cast<Item*> (this));
  b->removeStock(n);
  *this = *(static_cast<Software*>(b));
  totalValue -= (n * getPrice());
}


/*
 Takes the new price for this Software.
 Updates the price as well as totalValue for all Items and all Software.
*/
void Software::setPrice(double p){
  totalValue -= (getInStock() * getPrice());
  Item* b = (static_cast<Item*> (this));
  b->setPrice(p);
  *this = *(static_cast<Software*>(b));
  totalValue += (getInStock() * getPrice());
}


/*
 Prints the Software to the screen
*/
void Software::print(){
  cout << getStockNo() << "  " << getName();
  cout << "  \tPrice: $" << getPrice();
  cout << "\t" << getInStock() << " in stock" << endl;
  cout << "  Publisher: " << getPublisher();
  cout << "  \tVersion: " << getVersion(); 
  cout << endl;
}

[root@Fizzgig C]# make
g++    -c -o main.o main.cpp
g++ -c item.cpp
g++ -c book.cpp
g++ -c software.cpp
g++ -g main.o item.o book.o software.o -o inventory
[root@Fizzgig C]# inventory
abc123  Learn C++ in Two Hours  	Price: $79.98	25 in stock
  Author: Prentice-Hall  		Publisher: Prentice-Hall
cde321  C++ for Dummies  	Price: $25.5	17 in stock
  Author: Osborne  		Publisher: Osborne
ax5645  Unix in a Nutshell  	Price: $22.85	30 in stock
  Author: O'Reilly  		Publisher: O'Reilly
ax7831  WindowsNT in a Nutshell  	Price: $27.95	15 in stock
  Author: O'Reilly  		Publisher: O'Reilly
xyz321  Visual Cafe  	Price: $110	7 in stock
  Publisher: Symantec  	Version: 3.5
zyx434  Visual C++  	Price: $120	11 in stock
  Publisher: Microsoft  	Version: 6.0
uvw444  Visual Basic  	Price: $125	10 in stock
  Publisher: Microsoft  	Version: 7.14
wvu678  J-Builder  	Price: $99.95	6 in stock
  Publisher: Borland  	Version: 4.5
Total Value of Books: $3537.75
Total Value of Software: $3939.70
Total Value of Everything: $7477.45

There are 25 of pi[0]
abc123  Learn C++ in Two Hours  	Price: $79.98	25 in stock
  Author: Prentice-Hall  		Publisher: Prentice-Hall
There are 17 of pi[1]
cde321  C++ for Dummies  	Price: $25.5	17 in stock
  Author: Osborne  		Publisher: Osborne
There are 30 of pi[2]
ax5645  Unix in a Nutshell  	Price: $22.85	30 in stock
  Author: O'Reilly  		Publisher: O'Reilly
There are 15 of pi[3]
ax7831  WindowsNT in a Nutshell  	Price: $27.95	15 in stock
  Author: O'Reilly  		Publisher: O'Reilly
There are 7 of pi[4]
xyz321  Visual Cafe  	Price: $110	7 in stock
  Publisher: Symantec  	Version: 3.5
There are 11 of pi[5]
zyx434  Visual C++  	Price: $120	11 in stock
  Publisher: Microsoft  	Version: 6.0
There are 10 of pi[6]
uvw444  Visual Basic  	Price: $125	10 in stock
  Publisher: Microsoft  	Version: 7.14
There are 6 of pi[7]
wvu678  J-Builder  	Price: $99.95	6 in stock
  Publisher: Borland  	Version: 4.5

After adding 10 b1 and 10 s1 and removing 10 b3 and 10 s3
Total Value of Books: $4508.95
Total Value of Software: $3789.70
Total Value of Everything: $8298.65

After changing price b2 to 27.50 and s4 to 89.95
Total Value of Books: $4542.95
Total Value of Software: $3729.70
Total Value of Everything: $8272.65
[root@Fizzgig C]# exit

Script done on Thu Mar 20 21:01:13 2003
