Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use two files Money.h and Money.cpp which contain a Money class. You should download these files and add to them as specified below. //Money.h #include

Use two files Money.h and Money.cpp which contain a Money class. You should download these files and add to them as specified below.

//Money.h

#include  using namespace std; class Money { private: int dollars; int cents; public: Money(); void setDollars(int d) { dollars = d; } void setCents(int c) { cents = c; } int getDollars() const { return dollars; } int getCents() const { return cents; } int dollarsToCents() const { return dollars * 100 + cents; } };

//Money.cpp

#include  #include "Money.h" using namespace std; Money::Money() { dollars = 0; cents = 0; }

Add the following operator functions to the class. You will need to add the prototypes to the header file (Money.h) and the corresponding functions to the implementation file (Money.cpp).

operator== function returns true if two money objects are the same, false otherwise. Two money objects are the same if the dollars are the same and the cents are the same.

operator!= function returns true if two money objects are not the same, false otherwise. Two money objects are not the same if either the dollars or the cents are not the same.

operator<< should display a Money object in the form $5.06. To do this you need to display a $, dollars, . and cents.

Note if you have 5 dollars and 25 cents, the logic above will display $5.25, but if you have 6 dollars and 7 cents the logic above will display $6.7. So this function will require an if statement that displays a 0 if cents is < 10.

operator>> prompts the user to enter the dollars and cents and store it in the Money object

operator+ will add together the dollars and add together the cents of the two money objects

Example:

$5.25 + $6.30 = 11 dollars and 55 cents ($11.55) $5.25 + $6.90 = 11 dollars and 115 cents ($11.115), should be ($12.15)

This function will require an if statement, if cents becomes >= 100 you will need to add 1 to dollars (dollars++) and subtract 100 from cents (cents = cents 100)

Create a driver program lastname6.cpp that tests all the operators you added to the class. You can create as many Money objects as you need to test your class. Your driver program should contain documentation that shows what functions / operators you are testing. Use the final version of the Length class, as a guide on how to document your program.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions

Question

22. Explain superscalar, superpipelining, and VLIW architectures.

Answered: 1 week ago

Question

a. What aspects of the situation are under your control?

Answered: 1 week ago

Question

3 How the market system answers four fundamental questions.

Answered: 1 week ago

Question

5 The mechanics of the circular flow model.

Answered: 1 week ago

Question

1 The difference between a command system and a market system.

Answered: 1 week ago