Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Write a class called Money with overloaded operator < < to print a Money object to an ostream in standard format ($0.00). Include a

C++

Write a class called Money with overloaded operator<< to print a Money object to an ostream in standard format ($0.00).

Include a default constructor that makes a Money object have value $0.00, also a constructor that takes two integers (dollars and cents), and also a constructor that takes a double (in dollars, you should round appropriately if it is not an integral number of cents, so 45.678 should become $45.68, and 45.671 should become $45.67. Be careful to make this work properly for negative amounts too). Also include a copy constructor. Also include an operator= to be able to assign Money objects.

A main function should be able to print the following:

const Money con0;

cout << con0 << endl; //$0.00

cout << Money (2, 2) << endl; //$2.02

cout << Money(2.02) << endl; //$2.02

cout << Money(-3.03) << endl; //-$3.03

cout << Money(7.072) << endl; //$7.07

cout << Money(7.077) << endl; //$7.08

cout << Money(-7.072) << endl; //-$7.07

cout << Money(-7.077) << endl; //-$7.08

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

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions