Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

- Be sure to split your code among the Eles appropriately The name of your execu

ID: 3905198 • Letter: #

Question

- Be sure to split your code among the Eles appropriately The name of your executable shail be hw03 Create two classes and name their types Hot dogStand and Money All selevant classes, functions, and data shall Use initialization sections wheee possible for all constructors With the sole exceptions being the print) function(s) ne 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 frst for the dollars and the second for the cents -A constructor that takes one iteger, for an even 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 isNegativeC) const -Returns true if your amount of money is negative void add(const Money m - The sum shall be stoeed in the calling object void subtract(const Money 6m) The difference shall be stored in the calling object - bool isEqual(const Money 6m) const void print) const - This function prints the amount of Money you have it must printa3 and always show to decimal places -Negative amounts of Money shall be represened inthe folwng manr(Am) 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 Hotdog Stand class shail 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 hondog price, and no hotdogs sold Money getcash) const This retuns the total cash the HotdogStand has const const Money getPrice) const int getDogsSold) const This retumns the number of hotdogs sold by the stand const Money getStandRevenue) const -This calculates the total money made by selling hotdogs

Explanation / Answer

*********************************************

Money.h

#include <iostream>

using namespace std;

class Money {

private:

                int dollars, cents;

                int getPennies();

public:

                Money();

                Money(int d, int c);

                Money(int d);

                Money(double amount);

                bool isNegative() const;

                void add(const Money &m);

                void subtract(const Money &m);

                bool isEqual(const Money &m) const;

                void print() const;

};

*********************************************

Money.cpp

#include "Money.h"

#include <iomanip>

Money::Money() {

                dollars = 0.00;

                cents = 0.00;

}

Money::Money(int d, int c) {

                dollars = d;

                cents = c;

}

Money::Money(int d) {

                dollars = d;

}

Money::Money(double amount) {

                dollars = amount;

                cents = amount;

}

bool Money::isNegative() const {

                if(dollars < 0 || cents < 0)

                                return true;

                return false;

}

void Money::add(const Money &m) {

                dollars += m.dollars;

                cents += m.cents;

}

void Money::subtract(const Money &m) {

                dollars -= m.dollars;

                cents -= m.cents;

}

bool Money::isEqual(const Money &m) const {

                if(dollars == m.dollars && cents == m.cents)

                                return true;

                return false;

}

void Money::print() const {

                if(dollars < 0) {

                                cout << endl << "Dollars : $X.XX";

                } else {

                                cout << endl << "Dollars : $" << setprecision(2) << fixed << dollars;

                }

                if(cents < 0) {

                                cout << endl << "Cents : ¢X.XX";

                } else {

                                cout << endl << "Cents : ¢" << setprecision(2) << fixed << cents;

                }

}

*********************************************

HotdogStand.h

#include "Money.h"

#include <iostream>

using namespace std;

class HotdogStand {

private:

                Money stand_money;

                Money htd_price;

                int no_of_hotdogs;

                static int no_of_htd_objs;

                static int no_of_htd_sold;

                static Money total_htd_revenue;

public:

                HotdogStand();

                HotdogStand(double htd_rate);

                const Money getCash() const;

                const Money getPrice() const;

                int getDogsSold() const;

                const Money getStandRevenue() const;

                void setPrice(double price);

                void sellHotdog();

                static int getNumStands();

                static int getTotalHotdogsSold();

                static const Money getTotalRevenue();

};

*********************************************

HotdogStand.cpp

#include "HotdogStand.h"

#include <iostream>

using namespace std;

int HotdogStand::no_of_htd_objs = 0;

int HotdogStand::no_of_htd_sold = 0;

Money HotdogStand::total_htd_revenue = Money();

HotdogStand::HotdogStand() {

                no_of_hotdogs = 0;

                stand_money = Money();

                htd_price = Money(3.50);

}

HotdogStand::HotdogStand(double htd_rate) {

                no_of_hotdogs = 0;

                stand_money = Money();

                htd_price = Money(htd_rate);

}

const Money HotdogStand::getCash() const {

                return stand_money;

}

const Money HotdogStand::getPrice() const {

                return htd_price;

}

int HotdogStand::getDogsSold() const {

                return no_of_hotdogs;

}

const Money HotdogStand::getStandRevenue() const {

                return stand_money;

}

void HotdogStand::setPrice(double price) {

                htd_price = Money(price);

}

void HotdogStand::sellHotdog() {

                no_of_hotdogs++;

                no_of_htd_sold++;

                stand_money.add(htd_price);

                total_htd_revenue.add(htd_price);

}

int HotdogStand::getNumStands() {

                return no_of_htd_objs;

}

int HotdogStand::getTotalHotdogsSold() {

                return no_of_htd_sold;

}

const Money HotdogStand::getTotalRevenue() {

                return total_htd_revenue;

}