Question
Make a basic hotdog stand simuation in C++. The Hotdog and Money classes are in their own header files. I've done the Money class, I'm
Make a basic hotdog stand simuation in C++. The Hotdog and Money classes are in their own header files. I've done the Money class, I'm just having trouble on implementing the Hotdog class and the rest. The input should be taken from console. Thanks and I'll give a thumbs up.
General Requirements Create two classes and name their types HotdogStand and Money All relevant classes, functions, and data shall be placed in a namespace called MyAwesomeBusiness Use initialization sections where possible for all constructors With the sole exceptions being the print() function(s), no other functions should be printing to the screen unless an error message must be displayed
Money Class Requirements Negative amounts of Money shall be stored by making both the dollars and cents negative The Money class shall have four (4) constructors A default constructor that initializes your Money object to $0.00 A constructor that takes two integers, the first for the dollars and the second for the cents A constructor that takes one integer, for an clean dollar amount A constructor that takes one double, and can assign dollars and cents accordingly int getPennies() const Returns the equivalent amount of money as a number of pennies bool isNegative() const Returns true if your amount of money is negative void add(const Money &m) The sum shall be stored in the calling object void subtract(const Money &m) The difference shall be stored in the calling object bool isEqual(const Money &m) const
void print() const
This function prints the amount of Money you have; it must print a $, and always show two decimal places
Negative amounts of Money shall be represented in the following manner: ($X.XX) The Money class shall have two private data members An integer that represents how many dollars you have. An integer that represents how many cents you have.
HotdogStand Class Requirements The HotdogStand class shall have two (2) constructors A default constructor that initializes your HotdogStand object with no cash, a price of $3.50, and no hotdogs sold A constructor that takes a double, and initializes your HotdogStand object with no cash, the provided hotdog price, and no hotdogs sold const Money getCash() const This returns the total cash the HotdogStand has const Money getPrice() const int getDogsSold() const This returns the number of hotdogs sold by the stand const Money getStandRevenue() const This calculates the total money made by selling hotdogs void setPrice(double price) void sellHotdog() Increments all appropriate data members accordingly static int getNumStands() static int getTotalHotdogsSold() static const Money getTotalRevenue() The HotdogStand class shall have six (6) private data members A Money object that will represent how much money the stand has made A Money object that will represent the price of a hotdog An integer that will describe how many hotdogs a stand has sold A static integer that represents the total number of HotdogStand objects A static integer that represents the total number of hotdogs sold A static Money object that represents total revenue for all HotdogStand objects
Non-Member Requirements Define the following non-member function: void printRundown(const vector &franchises, int num) * This function will print the summary that is shown in the sample run below
main() Requirements Declare a vector of HotdogStand objects in your main function The end-user shall be prompted for how many hotdog stands they own The end-user will then be prompted for how many of those hotdog stands sell fancy hotdogs If the above input is greater than zero (0), the end-user shall be prompted for the price of the fancy hotdogs The end-user may type the price with or without the $ The simulation is then run and the output is printed to the screen
Simulation Requirements The simulation only runs through a single day The last n stands are always fancy, where n is the number of stands designated as fancy by the end-user Regular hotdog stands can sell a random number in the range 20 - 60 (inclusive) hotdogs a day Fancy hotdog stands can sell a random number in the range 1 - 30 (inclusive) hotdogs a day
A sample run of your program shall look like this (Your numbers will not match): NOTE: The input file contained the following inputs: 3 1 $8.00 (Enter pressed after last input)
$ ./hw02 < inputs Welcome! How many hotdog stands do you own? 3 How many of those sell classy hotdogs? 1 How much does a classy hotdog cost? $8 Stand Sales Price Revenue ===== ===== ===== ======= 1 47 $3.50 $164.50 2 24 $3.50 $84.00 3 21 $8.00 $168.00 TOTALS 92 $416.50 # of Stands: 3 $
Here is the Money class:
class Money { int dollars; int cents; public: Money(); Money(int dol, int cen); Money(int dol); Money(double amt); int getPennies() const; void setMoney(int d, int c); bool isNegative() const; void add(const Money &m); void subtract(const Money &m); bool isEqual(const Money &m) const; void print() const; };
The Money source file:
#include "Money.hpp"
Money::Money() { dollars = 0; cents = 0; }
Money::Money(int dol, int cen) { dollars = dol; cents = cen; if(dollars < 0 && cents > 0) { cents = -cents; } if(cents < 0 && dollars > 0) { dollars = -dollars; } if(cents > 100) { dollars += cents / 100; cents %= 100; } }
Money::Money(int dol) { dollars = dol; cents = 0; }
Money::Money(double amt) { dollars = amt; cents = (amt * 100 - dollars * 100); }
void Money::setMoney(int d, int c) { dollars = d; cents = c; }
int Money::getPennies() const { return dollars * 100 + cents; }
bool Money::isNegative() const { if(dollars < 0 || cents < 0) { return true; } else return false; }
void Money::add(const Money &m) { int pennies = getPennies() + m.getPennies(); dollars = pennies / 100; cents = pennies % 100; }
void Money::subtract(const Money &m) { int pennies = getPennies() - m.getPennies(); dollars = pennies / 100; cents = pennies % 100; }
bool Money::isEqual(const Money &m) const { if(getPennies() == m.getPennies()) { return true; } else return false; }
void Money::print() const { int total = (dollars * 100) + cents; double temp = double(total); std::cout.setf(std::ios::fixed); std::cout.setf(std::ios::showpoint); std::cout.precision(2); temp /= 100; if (temp < 0) { temp = std::abs(temp); std::cout << "($" << temp << ")"; } else std::cout << "$" << temp; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started