Please send questions to
st10@humboldt.edu .
//-----------------------------------------------------------
// File: stock_item.h
// Name: Sharon M. Tuttle
// last modified: 4-21-04
//
// Class: stock_item
// Description: a simple class that lets you store information
// about a stock item based on its unique integer key,
// its string name, its size_t quant, and its double price.
//
//-----------------------------------------------------------
#ifndef STOCK_ITEM_H
#define STOCK_ITEM_H
#include <cstdlib> // Provides size_t
#include <string>
using namespace std;
class stock_item
{
public:
/****************************************************/
/* CONSTRUCTOR */
/****************************************************/
// postcondition: creates a stock_item instance
// whose key is this_key (or -1), whose name is
// this_name (or ""), whose quant is this_quant
// (or 0), and whose price is this_price (or 0.0).
//
stock_item(int this_key=-1, string this_name = "",
size_t this_quant = 0, double this_price = 0.0)
{
key = this_key;
name = this_name;
quant = this_quant;
price = this_price;
}
/*************************************************************/
/* ACCESSORS and other constant member functions (observers) */
/*************************************************************/
// these are plain, obvious accessors, that do just what you
// think they do...
int get_key( ) const
{
return key;
}
string get_name( ) const
{
return name;
}
size_t get_quant( ) const
{
return quant;
}
double get_price( ) const
{
return price;
}
/****************************************************/
/* MODIFIERS and other modifying member functions */
/****************************************************/
// these are plain, obvious modifiers, that do just what you
// think they do...
void set_key(int new_key)
{
key = new_key;
}
void set_name(string new_name)
{
name = new_name;
}
void set_quant(size_t new_quant)
{
quant = new_quant;
}
void set_price(double new_price)
{
price = new_price;
}
/*****************************************/
/* overloaded operators */
/*****************************************/
// postcondition: the stock_item that activated
// this will be made to have the same field
// values as source.
//
void operator =(const stock_item& source)
{
key = source.key;
name = source.name;
quant = source.quant;
price = source.price;
}
private:
int key; // unique for each stock item
string name; // stock item's name
size_t quant; // quantity on hand of this stock item
double price; // price of this stock item
};
#endif