Write in c++ another overloaded operator

Assignment Help C/C++ Programming
Reference no: EM13165796

Write in C++ another overloaded operator to go in the program that has Treasury. Overload the forward slash /  so that in the main program, you can declare sale to be of type Treasury, and commission to be of type Treasury, and commispctage to be of type double, writing

Treasury sale, commission;

                  double commisspctage;

                  commisspctage = 6.25;

cin>> sale;

                  cout<<sale<<" is value of sale.\n";

                  commission = sale/commisspctage;

                  cout<<"The commission is "<<commission<<endl;

 

 

Write in C++ another overloaded operator to go in the program that has Treasury. Overload the forward slash /   so that in the main program, you can declare sale to be of type Treasury, and commission to be of type Treasury, and commispctage to be of type double, writing

Treasury sale, commission;

                  double commisspctage;

                  commisspctage = 6.25;

cin>> sale;

                  cout<<sale<<" is value of sale.\n";

                  commission = sale/commisspctage;

                  cout<<"The commission is "<<commission<<endl;

 

to have it calculate the commission at 6.25 percent of the sale. (Notice that 6.25 is the percent as given in the main program. Within your function code of the overloaded operator you will need to convert that to a decimal fraction. Also in the function code, use static_cast to avoid mode-mixing between int and double

variables. Note that you will be returning something of type Treasury.

And while you're working on the program, please improve the << operator function code so it will handle outputting single-digit cents correctly.

NOTE: Test your forward slash calculation using at least these sets of data for the sale

100 dollars 0 cents

987 dollars 89 cents

23 dollars 99 cents

1359 dollars 99 cents

 

And CHECK the output by hand to make sure it gives you the correct results.



//
#include <iostream>
using namespace std;
class Treasury
{
public:
    Treasury(); // default constructor to initialize to 10 dollars and 0 cents
    Treasury(int wholedollars);    // constructor toinitialize the dollar part only
    Treasury(int dollaramt, int centsamt);   // costructor to initialize both parts
    friend Treasury operator + (const Treasury& amt1, const Treasury& amt2);
    friend ostream& operator <<(ostream& outs, const Treasury& thevalue);
    friend istream& operator >>(istream& ins, Treasury& avalue);
    friend bool operator == (const Treasury& oneside, const Treasury& otherside);
private:
    int dollars, cents;
};
int main()
{
    Treasury billfold(25,50), pocket(3,48), total, check(28,98);
    total = billfold + pocket;
    if(total == check)
        cout<<"The total amount is "<<total<<endl;    // where second << is overloaded
    else
        cout<<"Something went wrong.\n";
    // add an overload of / so that sale/commisspctage calculates the commission where commisspctage of the sale is, say, 6.25 percent   
return 0;
}
Treasury::Treasury() // default constructor to initialize to 10 dollars and 0 cents
{
    dollars = 10;
    cents = 0;
}
Treasury::Treasury(int wholedollars)    // constructor toinitialize the dollar part only
{
    dollars = wholedollars;
}
Treasury::Treasury(int dollaramt, int centsamt)   // costructor to initialize both parts
{
    dollars = dollaramt;
    cents = centsamt;
}
Treasury operator + (const Treasury& amt1, const Treasury& amt2)
{
    int totdollars, totcents;
    Treasury result;
    totdollars = amt1.dollars + amt2.dollars;
    totcents = amt1.cents + amt2.cents;
    if(totcents >= 100)
    {
        totdollars++;
        totcents = totcents % 100;
    }
    result.dollars = totdollars;
    result.cents = totcents;
    return result;
}
ostream& operator <<(ostream& outs, const Treasury& thevalue)
{
    outs<<"$"<<thevalue.dollars<<"."<<thevalue.cents;
    return outs;
}
istream& operator >>(istream& ins, Treasury& avalue)   // note: don't use const here
{
    ins>>avalue.dollars>>avalue.cents;
    return ins;
}
bool operator == (const Treasury& oneside, const Treasury& otherside)
{
    if((oneside.dollars == otherside.dollars) && (oneside.cents == otherside.cents))
        return true;
    else
        return false;
}

 

 

Reference no: EM13165796

Questions Cloud

Consider an array of integers : Consider an array of integers as below: int[] a = {5, 2, -4, 3, 0, -5, 7, 11, 6, 13} Complete the method named count(int[] a) in the class Count. The method should return the number of positive numbers in the array
The interest rate per period : The interest rate per period. For example, if your loan's interest is 6.5% per year, and you are paying monthly, this would be 6.5%/12. If you are paying every two weeks, r would be 6.5%/26, because there are 26 two-week periods in a year.
. label the rows that make good power ciphers and explain : a) Make a power table for numbers mod 11. Indicate how the table shows Fermat's theorem, label the primitive roots mod 11. Explain how you can tell they are primitive roots. Label the rows that make good power ciphers and explain
Coinflip to prompt for and input a number : Write a program and name it CoinFlip to prompt for and input a number of times to flip a coin, then to output the number of "heads" and the number of "tails" that were flipped.
Write in c++ another overloaded operator : Write in C++ another overloaded operator to go in the program that has Treasury. Overload the forward slash /  so that in the main program, you can declare sale to be of type Treasury, and commission to be of type Treasury, and commispctage to be of ..
Write a c++ program that prompts the user for a double : Write a C++ program that prompts the user for a double that should be between 0 and 100. If the value entered is outside of the interval the program will print an error message. The program should continue to repeat until the user enters an appropria..
Alphabet of 10 digits, 26 letters, and 3 punctuation marks : the ciphers in the following problem use this alphabet of 10 digits, 26 letters, and 3 punctuation marks - 39 charactters is all 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
Javascript program that asks the use : Design a javascript program that asks the user for a username with at least eight characters, beginning with a letter and including at least one digit. Next, write a validation loop to ensure that these conditions have been met
Design, simulate and verify a 16-bit ripple-carry : Design, simulate and verify a 16-bit ripple-carry adder by performing the following additions/subtractions (the values of a and b are given in decimal): (i) (-10) + (100), (ii) (63) - (-127), (iii) (15) + (95), (iv) (-32) + (79), (v) (-59) + (-16)..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Program to tell you how many months it will take to pay off

write a program to tell you how many months it will take to pay off any loan, as well as the total amount of interest paid over the life of the loan.

  Develop a class airborne location

develop a class AirborneLocation that represents the location of airplanes with respect to a reference radar location. Each AirborneLocation object should include data member for aircraftID (integer),

  Object-oriented systems is the concept of object

At the heart of all object-oriented systems is the concept of an object. Simply stated, an object is a set of related characteristics and their associated actions.

  Compares the number of possible sequences

A c++ program that compares the number of possible sequences of the length L that can be generated uinder the following assumptions. Given an alphabet of size N=9. The program must output a formatted list comparing the number of possible sequences..

  Write two short c programs and solve exam-style problem

Write two short C programs and solve four exam-style problems.

  You will write a program that reads a text file

You will write a program that reads a text file, counts the number of words in the file, and the number of occurrences of each character. It will print to a file the number of words, and the number of occurrences of each character, as well as the ..

  Write a c function that converts a character to upper case.

Write a C function that converts a character to upper case. The function should have the prototype char to_upper(char ch); The characters given as input to the function are assumed to be in the sets {'a', ..., 'z'} and {'A', ... , 'Z' }. Do not use a..

  Cashregister class that can be used with the retailitem clas

Write a CashRegister class that can be used with the RetailItem class that you wrote in Part 1. The CashRegister class should simulate the sale of a retail item. It should have a constructor that accepts a RetailItem object as an argument.

  Ng stands for next guess

Where NG stands for next guess and LG stands for last guess. Write a function that calculates the square root of a number using this method. The initial guess will be the starting value of LG .

  Local diner that allows customers to see the diner''s menu

Design a program to be used for a small local diner that allows customers to see the diner's menu and then make their meal selections using the program.The program will also calculate and print an itemized bill.

  Perform operations on arrays

Perform operations on arrays execute tests and repetitions

  Write a program that takes a positive integer

Write a program that takes a positive integer from the user and prints the rightmost digit of that integer. This is a sample output: Enter an integer: 1247

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd