1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Vesna [10]
3 years ago
13

Consider the class Money declared below. Write the member functions declared below and the definition of the overloaded +. Modif

y the class declaration and write the definitions that overload the stream extraction and stream insertion operators >> and << to handle Money objects like $250.99
Write a short driver main() program to test the overloaded operators +, << and >> class Money { public: friend Money operator +(const Money& amountl, const Money& amount2) Money(); // constructors Money( int dollars, int cents); // set dollars, cents double get_value() const; void printamount();// print dollars and cents like $12.25 private: int all_cents; // all amount in cents };

Computers and Technology
1 answer:
disa [49]3 years ago
5 0

Answer: Provided in the explanation section

Explanation:

#include<iostream>

using namespace std;

class Money{

  private:

      int all_cents;

  public:

      Money();

      double get_value() const;

      Money(int,int);

      void printamount();

      friend Money operator+(const Money&, const Money&);

      friend ostream& operator<<(ostream&, const Money&);

      friend istream& operator>>(istream&, Money&);

};

Money::Money(){all_cents=0;}

double Money::get_value() const{return all_cents/100.0;}

Money::Money(int dollar ,int cents){

  all_cents = dollar*100+cents;

}

void Money::printamount(){

  cout<<"$"<<get_value()<<endl;

}

Money operator+(const Money& m1, const Money& m2){

  int total_cents = m1.all_cents + m2.all_cents;

  int dollars = total_cents/100;

  total_cents %=100;

  return Money(dollars,total_cents);

}

ostream& operator<<(ostream& out, const Money& m1){

  out<<"$"<<m1.get_value()<<endl;

  return out;

}

istream& operator>>(istream& input, Money& m1){

  input>>m1.all_cents;

  return input;

}

int main(){

 

  Money m1;

  cout<<"Enter total cents: ";

  cin>>m1;

  cout<<"Total Amount: "<<m1;

 

  Money m2 = Money(5,60);

  Money m3 = Money(4,60);

  cout<<"m2 = ";m2.printamount();

  cout<<"m3 = ";m3.printamount();

  Money sum = m2+m3;

  cout<<"sum = "<<sum;

 

}

cheers i hope this helped !!

You might be interested in
C++
Sonbull [250]

Answer:

#include <iostream>

#include<iomanip>

using namespace std;

double DrivingCost(double drivenMiles, double milesPerGallon, double dollarsPerGallon)

{

  double dollarCost = 0;

  dollarCost = (dollarsPerGallon * drivenMiles) / milesPerGallon;

  return dollarCost;

}

int main()

{

  double miles = 0;

  double dollars = 0;

  cout << "Enter miles per Gallon   : ";

  cin >> miles;

  cout << "Enter dollars per Gallon: ";

  cin >> dollars;

  cout << fixed << setprecision(2);

  cout << endl;

  cout << "Gas cost for 10 miles : " << DrivingCost(10, miles, dollars) << endl;

  cout << "Gas cost for 50 miles : " <<DrivingCost(50, miles, dollars) << endl;

  cout << "Gas cost for 400 miles: "<<DrivingCost(400, miles, dollars) << endl;

  return 0;

}

Explanation:

  • Create a method definition of DrivingCost that accepts  three input double data type parameters drivenMiles,  milesPerGallon, and dollarsPerGallon and returns  the dollar cost to drive those miles .
  • Calculate total dollar cost and store in the variable, dollarCost .
  • Prompt and read the miles and dollars per gallon  as input from the user .
  • Call the DrivingCost function three times  for the output to the gas cost for 10 miles,  50 miles, and 400 miles.

 

8 0
3 years ago
Read 2 more answers
What does an effect allow you to do in<br> EarSketch?
Gnoma [55]

Answer:usbebdos did did I’d did d

Explanation:

Bash six ska over five. I did a sis a and

7 0
3 years ago
What does a mother board in a computer do?
IRINA_888 [86]

The motherboard is the central component of a computer. Without it, the computer would not work. The mother board is sometimes called "the heart of the computer" because it allows thinks to function properly.

The motherboard of the computer is the part that holds the system memory and audio. It's a printed circuit board.

4 0
3 years ago
When should you close the socket python tcp server client.
Aleksandr-060686 [28]
F socket refers to an open TCP connection, the connection is closed. If a stream socket is closed when there is input data queued, the TCP connection is reset rather than being cleanly closed. The descriptor of the socket to be closed

To close the socket you need to call shutdown() first and then close(), and shutdown takes an argument
4 0
3 years ago
Which of the following statements is true of satellite internet access?
MA_775_DIABLO [31]

Answer:

So, to get a more simplified version of the question, we will now assemble all the statements and one by one describe them.

Explanation:

  1. Satellite internet is obviously not the slowest forms of access, And its more expensive to connect to.
  2. Yes, satellite access do provide access to remote rural areas.And they require a system of antennas in order to connect from the earth to the satellite which is providing the services.
  3. Yes satellites internet works by sending and receiving messages or data required via a transmitter and receiver antenna, which connects the users device to the satellite providing the services.
  4. The satellite internet do cover a very large portion of Earths surface as there are now many number of satellites sent to the space which has made the communication system more fast and convenient to use.
3 0
3 years ago
Other questions:
  • Which statement about word processing software is true? A)You can use it to perform mathematical calculations.B) You can use it
    6·2 answers
  • Obtain the 10’s complement of the following six-digit decimal numbers:<br><br> 123900<br><br> 980657
    10·1 answer
  • SP 800-14, Generally Accepted Principles and Practices for Securing Information Technology Systems, provides best practices and
    12·1 answer
  • Match each of the following terms to its function:_________
    13·1 answer
  • Operational feasibility, which refers to user acceptance and support, as well as management acceptance and support, is also know
    9·1 answer
  • Consider a system running 10 I/O-bound processes and 2 CPU-bound process. Assume that the I/O-bound processes issue an I/O opera
    9·1 answer
  • ​open-source software is​ ________.
    11·1 answer
  • A host device needs to send a large video file across the network while providing data communication to other users. Which featu
    8·1 answer
  • What technique is used when setup times at a workstation are sequence dependent?
    15·1 answer
  • Which of the following screen elements is a horizontal bar that displays at the
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!