sammich.h

/*

Programmer: Jennifer Leopold

Date: April 7, 2016

File: sandwich.h

Purpose: This file contains the definition of the

Sandwich class.

*/

#ifndef SANDWICH_H

#define SANDWICH_H

#include <iostream>

#include <cstdlib>

#include <iomanip>

using namespace std;

class Sandwich

{

private:

// initial maximum values for # ingredients

static const int INIT_MAX_NUM_ANIMALS = 4;

static const int INIT_MAX_NUM_PICKLES = 4;

static const int INIT_MAX_NUM_BACON = 4;

// frequency of pathogen occurrence

static const int PATHOGEN_FREQ = 10;

// frequency of cheese and/or sauce in sandwich

static const int CHEESE_SAUCE_FREQ = 50;

// price for bread and extra ingredients

static const float BREAD_PRICE = 0.5;

static const float SAUCE_PRICE = 0.1;

static const float CHEESE_PRICE = 0.25;

static const float PICKLE_PRICE = 0.25;

static const float BACON_PRICE = 0.5;

static const float ANIMAL_PRICE = 0.75;

int m_numAnimals; // # animal ingredients

int m_numBacon; // # ounces bacon

int m_numPickles; // # pickles

bool m_hasCheese; // whether or not has cheese

bool m_hasSauce; // whether or not has sauce

bool m_hasPathogen; // whether or not has pathogen

float m_price; // price of the sandwich

public:

// Default constructor for Sandwich

// Preconditions: None

// Postconditions: m_numAnimals has been set to random

// value between 0..INIT_MAX_NUM_ANIMALS, m_numBacon has

// been set to random value between 0..INIT_MAX_NUM_BACON,

// m_numPickles has been set to random value between

// 0..INIT_MAX_NUM_PICKLES, m_hasCheese and m_hasSauce have

// been set to true CHEESE_SAUCE_FREQ percent of the time

// m_hasPathogen has been set to true PATHOGEN_FREQ percent

// of the time, and m_price has been set depending on values

// chosen for m_hasCheese, m_hasSauce, and m_numAnimals,

// m_numBacon, and m_numPickles.

Sandwich();

// Parameterized constructor for Sandwich

// Preconditions: numAnimals, numBacon, and numPickles

// are >= 0

// Postconditions: m_numAnimals, m_numBacon, m_numPickles,

// m_hasCheese, m_hasSauce, m_hasPathogen have been set to

// the respective parameter values, and m_price has been

// set, as computed from BREAD_PRICE plus

// the specified values for hasCheese, hasSauce,

// numAnimals, numBacon, and numPickles.

Sandwich(const int numAnimals, const int numBacon,

const int numPickles, const bool hasCheese,

const bool hasSauce, const bool hasPathogen);

// Accessor for m_numAnimals

// Preconditions: None

// Postconditions: Value of m_numAnimals is returned

int getNumAnimals() const { return(m_numAnimals); }

// Accessor for m_numPickles

// Preconditions: None

// Postconditions: Value of m_numPickles is returned

int getNumPickles() const { return(m_numPickles); }

// Accessor for m_numBacon

// Preconditions: None

// Postconditions: Value of m_numBacon is returned

int getNumBacon() const { return(m_numBacon); }

// Accessor for m_hasCheese

// Preconditions: None

// Postconditions: Value of m_hasCheese is returned

bool getHasCheese() const { return(m_hasCheese); }

// Accessor for m_hasSauce

// Preconditions: None

// Postconditions: Value of m_hasSauce is returned

bool getHasSauce() const { return(m_hasSauce); }

// Accessor for m_hasPathogen

// Preconditions: None

// Postconditions: Value of m_hasPathogen is returned

bool getHasPathogen() const { return(m_hasPathogen); }

// Accessor for m_price

// Preconditions: None

// Postconditions: Value of m_price is returned

float getPrice() const { return(m_price); }

// Mutator for m_price

// Preconditions: price must be >= 0

// Postconditions: Value of m_price has been set to price

void setPrice(const float price);

// Mutator for m_numAnimals

// Preconditions: numAnimals must be >= 0

// Postconditions: Value of m_numAnimals has been set

// to numAnimals

void setNumAnimals(const int numAnimals);

// Mutator for m_numPickles

// Preconditions: numPickles must be >= 0

// Postconditions: Value of m_numPickles has been set

// to numPickles

void setNumPickles(const int numPickles);

// Mutator for m_numBacon

// Preconditions: numBacon must be >= 0

// Postconditions: Value of m_numBacon has been set

// to numBacon

void setNumBacon(const int numBacon);

// Overloaded operator for <<

// Preconditions: None

// Postconditions: State of Sandwich will be output to outs,

// thereby modifying ostream outs

friend ostream& operator <<(ostream& outs,

const Sandwich& p);

private:

// Determine price of this sandwich

// Preconditions: None

// Postconditions: Price for sandwich is returned taking into

// consideration BREAD_PRICE plus whether it has cheese

// and/or sauce, # animals, # pickles, and # ounces of

// bacon

float determinePrice();

};

#endif