Please send questions to
st10@humboldt.edu .
//-----------------------------------------------------------
// File: flavored_item.h
// Name: Sharon M. Tuttle
// last modified: 5-3-04
//
// Class: flavored_item
// Description: a simple class that is a SUBCLASS of stock_item
// except it also has a string flavor (along with a unique integer key,
// its string name, its size_t quant, and its double price.
//
//-----------------------------------------------------------
#ifndef FLAVORED_ITEM_H
#define FLAVORED_ITEM_H
#include <string>
#include "stock_item.h"
using namespace std;
class flavored_item : public stock_item
{
public:
// constructor
// using a member initialization list...
// see Savitch/Main p. 660
flavored_item(int this_key=-1, string this_name = "",
size_t this_quant = 0, double this_price = 0.0,
string this_flavor = "" ) :
stock_item(this_key, this_name, this_quant, this_price),
flavor(this_flavor)
{ }
// note that the automatically-generated copy constructor,
// destructor, and assignment operator are FINE for this
// subclass (no dynamic memory allocation here, no pointers
// here!)
// additional accessors
string get_flavor( ) const
{
return flavor;
}
virtual void display_item( ) const
{
cout << get_key() << " " << get_name() << " "
<< get_quant() << " "
<< get_price() << " " << flavor << endl;
}
// additional modifiers
void set_flavor(string new_flavor)
{
flavor = new_flavor;
}
private:
string flavor;
};
#endif