hw9_functs.cpp

/* Programmer: Jennifer Leopold Date: April 7, 2016

File: hw9_functs.cpp

Purpose: Function definitions used for testing the Sandwich

and Customer class functions.

*/

#include <iostream>

#include "hw9_functs.h"

using namespace std;

void testSandwich()

{

cout << "\nTesting Sandwich functions...\n\n";

Sandwich s1; // default constructor

Sandwich s2(3, 2, 1, true, // parameterized constructor

true, false);

// overloaded operator for <<

cout << "Sandwich created with default constructor is:\n"

<< s1 << endl;

cout << "Sandwich created with parameterized constructor is:\n"

<< s2 << endl;

// accessor functions

cout << "Parameterized sandwich (output using member variable "

<< "accessors):\n";

cout << "# animals = " << s2.getNumAnimals()

<< ", # oz bacon = " << s2.getNumBacon()

<< ", # pickles = " << s2.getNumPickles()

<< ", cheese = " << (s2.getHasCheese()? "y": "n")

<< ", sauce = " << (s2.getHasSauce()? "y": "n")

<< ",\npathogen = " << (s2.getHasPathogen()? "y": "n")

<< ", price = $"

<< std::fixed << std::setprecision(2) << s2.getPrice()

<< endl;

// mutator functions

s2.setPrice(s2.getPrice() + 1);

s2.setNumAnimals(s2.getNumAnimals() + 1);

s2.setNumPickles(s2.getNumPickles() + 1);

s2.setNumBacon(s2.getNumBacon() + 1);

cout << "\nAfter incrementing price, # animals, # pickles,"

<< " and # oz bacon by 1:\n"

<< s2 << endl;

return;

}

void testCustomer()

{

cout << "\nTesting Customer functions...\n\n";

Customer c; // default constructor

// overloaded operator for <<

cout << "Customer created with default constructor is:"

<< endl << c << endl;

// accessor functions

cout << "Customer (output using member variable "

<< "accessors):\n";

cout << c.getName()

<< ": assets = $"

<< std::fixed << std::setprecision(2)

<< c.getCash()

<< " weight = " << std::setprecision(1)

<< c.getWeight()

<< " cholesterol = " << c.getCholesterol()

<< " alive = " << (c.getAlive()? "y": "n")

<< endl << endl;

// setCash function

c.setCash(c.getCash() + 10);

cout << "Customer's cash after adding $10 is $"

<< std::fixed << std::setprecision(2) << c.getCash()

<< endl;

c.setCash(0);

cout << "Customer's cash after setting to $0 is $"

<< std::fixed << std::setprecision(2) << c.getCash()

<< endl;

c.setCash(-1);

cout << "Customer's cash after trying to set to -$1 is $"

<< std::fixed << std::setprecision(2) << c.getCash()

<< endl << endl;

// setWeight function

c.setWeight(c.getWeight() + 10);

cout << "Customer's weight after adding 10 lbs is "

<< c.getWeight() << endl;

c.setWeight(0);

cout << "Customer's weight after changing to 0 lbs is "

<< c.getWeight() << endl;

c.setWeight(-10);

cout << "Customer's weight after changing to -10 lbs is "

<< c.getWeight() << endl << endl;

// setCholesterol function

c.setCholesterol(c.getCholesterol() + 10);

cout << "Customer's cholesterol after adding 10 is "

<< c.getCholesterol() << endl;

c.setCholesterol(0);

cout << "Customer's cholesterol after changing to 0 is "

<< c.getCholesterol() << endl << endl;

// accessor for m_name and selection of names in

// constructor

cout << "\nTesting selection of customer names:\n";

for (int i = 1; i <= NUM_CUST_NAMES+1; i++)

{

Customer c;

cout << " Customer name chosen is: "

<< c.getName() << endl;

}

// Note: eat function will be tested in

// testCustomerWithSandwich()

return;

}

void testCustomerWithSandwich()

{

cout << "\nTesting Customer with Sandwich functions...\n";

for (int i = 1; i <= NUM_CUST_NAMES; i++)

{

Sandwich s;

Customer c;

cout << "\nCreated the following Sandwich:\n"

<< s << endl;

cout << "Created the following Customer:\n"

<< c << endl;

c.eat(s);

cout << "Customer after sandwich eaten is:\n" << c << endl;

}

return;

}