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 "<= 100) { totdollars++; totcents = totcents % 100; } result.dollars = totdollars; result.cents = totcents; return result; } ostream& operator <<(ostream& outs, const Treasury& thevalue) { outs<<"$"<>(istream& ins,…

The code provided is an implementation of a Treasury class in C++. The Treasury class represents a monetary value, with dollars and cents as its members. The code includes several constructors, operators, and friend functions for performing various operations on instances of the Treasury class.

The first constructor, Treasury(), is the default constructor. It initializes the Treasury object to 10 dollars and 0 cents. The second constructor, Treasury(int wholedollars), initializes the dollar part of the Treasury object and sets the cents part to 0. The third constructor, Treasury(int dollaramt, int centsamt), initializes both the dollar and cents parts of the Treasury object.

There is an overloaded operator + that allows adding two Treasury objects together. It takes two const references to Treasury objects as parameters and returns a new Treasury object that represents the sum of the two input objects. The operator + function adds the dollars and cents of the two input objects, taking care of carrying any excess cents to the dollars part if needed.

There are also overloaded operators << and >> for outputting and inputting Treasury objects, respectively. The operator << function takes an ostream object and a const reference to a Treasury object as parameters. It outputs the Treasury object in the format "$dollars.cents" to the ostream object. The operator >> function takes an istream object and a reference to a Treasury object as parameters. It reads the input from the istream object in the format “$dollars.cents” and assigns the values to the Treasury object.

Lastly, there is an overloaded operator == for comparing two Treasury objects for equality. It takes two const references to Treasury objects as parameters and returns a boolean value indicating whether the two objects are equal. The operator == function compares the dollars and cents of the two input objects and returns true if they are equal, and false otherwise.

In the main function, several instances of the Treasury class are created, and operations are performed on them. The total amount in the billfold and pocket Treasury objects is calculated using the operator + and stored in the total Treasury object. Then, the total amount is compared with the check Treasury object using the operator ==. If they are equal, a message is printed to the console. If not, a different message is printed.

In conclusion, the code provided implements a Treasury class in C++ with several constructors, operators, and friend functions for performing calculations and comparisons on monetary values.

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.


Click Here to Make an Order Click Here to Hire a Writer