/*
Programmer: Jennifer Leopold
Date: April 7, 2016
File: customer.h
Purpose: This file contains the definition of the
Customer class.
*/
#ifndef CUSTOMER_H
#define CUSTOMER_H
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <fstream>
#include "sandwich.h"
using namespace std;
// File of NUM_CUST_NAMES many possible customer names
const char CUST_NAMES_FILE[20] = "customerNames.dat";
const short NUM_CUST_NAMES = 15;
class Customer
{
private:
// limits on initial cash amount
static const int MIN_INIT_CASH = 25;
static const int MAX_INIT_CASH = 75;
// limits on weight
static const int MIN_INIT_WEIGHT = 90;
static const int MAX_INIT_WEIGHT = 250;
static const int MIN_WEIGHT = 0;
// limits on cholesterol amount
static const int MIN_INIT_CHOLESTEROL = 30;
static const int MAX_INIT_CHOLESTEROL = 300;
static const int MIN_CHOLESTEROL = 30;
// constants used in calculation of weight gain when
// sandwich eaten
static const float WT_GAIN_ANIMALS_MULTIPLIER = 0.5;
static const int WT_GAIN_BACON_DIVISOR = 8;
static const int WT_GAIN_PICKLES_DIVISOR = 4;
static const float WT_GAIN_FROM_CHEESE = 1.2;
static const float WT_GAIN_FROM_SAUCE = 2.1;
// constants used in calculation of cholesterol gain when
// sandwich eaten
static const float CHOL_GAIN_BACON_MULTIPLIER = 2.5;
static const int CHOL_GAIN_WEIGHT_MULTIPLIER = 10;
static const float PI = 3.14;
string m_name; // customer's name
float m_cash; // amount of money to spend
float m_weight; // weight (in lbs)
float m_cholesterol; // cholesterol level
bool m_isAlive; // true if alive
public:
// Default constructor for Customer
// Preconditions: None
// Postconditions: m_name has been set to a string chosen
// from the CUST_NAMES_FILE file, m_cash has been set
// to a value between MIN_INIT_CASH..MAX_INIT_CASH, m_weight
// has been set to a value between MIN_INIT_WEIGHT..
// MAX_INIT_WEIGHT, m_cholesterol has been set
// to a value between MIN_INIT_CHOLESTEROL..
// MAX_INIT_CHOLESTEROL, and m_isAlive has been set to true.
Customer();
// Accessor for m_name
// Preconditions: None
// Postconditions: Value of m_name is returned
string getName() const { return(m_name); }
// Accessor for m_cash
// Preconditions: None
// Postconditions: Value of m_cash is returned
float getCash() const { return(m_cash); }
// Accessor for m_weight
// Preconditions: None
// Postconditions: Value of m_weight is returned
float getWeight() const { return(m_weight); }
// Accessor for m_cholesterol
// Preconditions: None
// Postconditions: Value of m_cholesterol is returned
float getCholesterol() const { return(m_cholesterol); }
// Accessor for m_alive
// Preconditions: None
// Postconditions: Value of m_alive is returned
bool getAlive() const { return(m_isAlive); }
// Mutator for m_cash
// Preconditions: cash must be >= 0
// Postconditions: Value of m_cash has been set to cash
void setCash(const float cash)
{
if (cash >= 0)
m_cash = cash;
return;
}
// Mutator for m_weight
// Preconditions: weight must be >= MIN_WEIGHT
// Postconditions: Value of m_weight has been set to weight
void setWeight(const float weight)
{
if (weight >= MIN_WEIGHT)
m_weight = weight;
return;
}
// Mutator for m_cholesterol
// Preconditions: cholesterol must be >= MIN_CHOLESTEROL
// Postconditions: Value of m_cholesterol has been set to
// cholesterol
void setCholesterol(const float cholesterol)
{
if (cholesterol >= MIN_CHOLESTEROL)
m_cholesterol = cholesterol;
return;
}
// Have customer eat a sandwich, thereby changing his/her
// cash amount, cholesterol level, weight, and possibly
// 'alive' status
// Preconditions: None
// Postconditions: Values of m_cash, m_weight, m_cholesterol,
// and (possibly) m_alive will be changed.
void eat(const Sandwich p);
// Overloaded operator for <<
// Preconditions: None
// Postconditions: State of Customer will be output to outs,
// thereby modifying ostream outs
friend ostream& operator <<(ostream& outs,
const Customer& c);
private:
// Choose a name from file CUST_NAMES_FILE
// Preconditions: None
// Postconditions: Returns a string read from
// CUST_NAMES_FILE
string chooseName();
};
#endif