//----------------------------------------------------------------------
//  IMPLEMENTATION FILE (supply.cpp)
//  This module exports an ADT for stationery store objects.
//----------------------------------------------------------------------
#include "supply.h"
#include <iostream.h>
#include <iomanip.h>
#include <string.h>     // For strlen() and strcpy()

// Private members of class:
//    char* descrip;
//    long  stockNo;
//    int   quant;
//    float price;

Supply::Supply( /* in */ const char* description,
                /* in */ int         stockNumber,
                /* in */ int         initQuantity,
                /* in */ float       initPrice    )
    //..................................................................
    // PRE:  All parameters assigned
    // POST: Duplicate of description string created on free store
    //    && stockNo == stockNumber
    //    && quant == initQuantity
    //    && price == initPrice
    //..................................................................
{
    descrip = new char[strlen(description) + 1];
    strcpy(descrip, description);
    stockNo = stockNumber;
    quant = initQuantity;
    price = initPrice;
}

Supply::Supply( const Supply& otherSupply )
    //..................................................................
    // POST: Duplicate of otherSupply's descrip string created on
    //       free store
    //    && stockNo == otherSupply.stockNo
    //    && quant == otherSupply.quant
    //    && price == otherSupply.price
    //..................................................................
{
    descrip = new char[strlen(otherSupply.descrip) + 1];
    strcpy(descrip, otherSupply.descrip);
    stockNo = otherSupply.stockNo;
    quant = otherSupply.quant;
    price = otherSupply.price;
}

Supply::~Supply()
    //..................................................................
    // POST: descrip string deleted from free store
    //..................................................................
{
    delete descrip;
}

void Supply::Increase( /* in */ int amt )
    //..................................................................
    // PRE:  Assigned(amt)
    // POST: quant == quant<entry> + amt
    //..................................................................
{
    quant += amt;
}

void Supply::Decrease( /* in */ int amt )
    //..................................................................
    // PRE:  Assigned(amt)
    // POST: quant == quant<entry> - amt
    //..................................................................
{
    quant -= amt;
}

void Supply::Reprice( /* in */ float newPrice )
    //..................................................................
    // PRE:  Assigned(newPrice)
    // POST: price == newPrice
    //..................................................................
{
    price = newPrice;
}

void Supply::Display() const
    //..................................................................
    // POST: descrip, stockNo, quant, and price
    //       have been written to standard output
    //..................................................................
{
    cout << descrip << '\n';
    cout << setw(10) << stockNo << setw(7) << quant;

    long temp = int(100.0*price + 0.5);
    int  fracPart = temp % 100;
    cout << setw(6) << temp/100 << '.';
    if (fracPart < 10)
        cout << 0;
    cout << fracPart << '\n';
}

