Please add these operations to my cpp code. I need it quick please
HERE IS MY CODE:
Cash.h
#ifndef CASH_H #define CASH_H #include //class Cash definition class Cash { //private data members private: int dollars,cents; public: //constructors Cash(int dollars,int cents); Cash(int dollars); Cash(); //other function declarations int getDollar() const; int getCent() const; double getCash(); void setCash(int,int); void setCash(double); //operator overloading function declarations bool operator==(Cash); bool operator(Cash); Cash operator+(Cash); Cash operator-(Cash); Cash operator*(int); //overloading insertion and extraction operator friend std::istream& operator>>(std::istream& in,Cash&); friend std::ostream& operator Cash.cpp
#include "Cash.h"
#include
#include //this constructor assigns the received parameters d and c to dollars and cents Cash::Cash(int d, int c) { dollars = d; cents = c; } //this constructor assigns the received parameters d to dollars Cash::Cash(int dol) { dollars = dol; } //this default constructor assigns the dollars and cents to 0 Cash::Cash() { dollars = 0; cents = 0; } //this method returns the value of dollars int Cash::getDollar() const { return dollars; } //this method returns the value of cents int Cash::getCent() const { return cents; } //this method returns the cash as double by combining dollars and cents double Cash::getCash() { double amount; amount = dollars + (double) cents / 100; return amount; } //this method sets the dollars and cents with received parameters d and c void Cash::setCash(int d, int c) { dollars = d; cents = c; } //this method sets teh dollars with the received parameter d void Cash::setCash(double a) { //split the parameter a with decimal part and fractional part in num1 and num2 double num1, num2; num2 = modf(a, & num1); //convert that num1 and num2 into dollars and cents dollars = (int) num1; cents = num2 * 100; } //this method checks two cash objects are equal or not bool Cash::operator == (Cash two) { if (this -> getCash() == two.getCash()) return true; else return false; } //this method checks first (current) cash object is less than cash object two bool Cash::operator getCash() (Cash two) { if (this -> getCash() > two.getCash()) return true; else return false; } //this method adds two cash objects and returns a added cash object Cash Cash::operator + (Cash two) { Cash temp; temp.setCash((this -> getDollar() + two.dollars) + (double)(this -> getCent() + two.cents) / 100); return temp; } //this method subtracts two cash objects (current and two) and returns a added cash object Cash Cash::operator - (Cash two) { Cash temp; temp.dollars = this -> getDollar() - two.dollars; temp.cents = this -> getCent() - two.cents; return temp; } //this method performs the scalar multiplication of current cash object by m times Cash Cash::operator * (int m) { Cash temp; // std::coutgetCash()*m; temp.setCash(this -> getCash() * m); return temp; } //this method reads the input for cash object std::istream & operator >> (std::istream & in , Cash & cash) { std::cout > cash.dollars; std::cout > cash.cents; return in; } //this method displays the details of cash object std::ostream & operator
THANK you!
1) - unary operator minus for a negative Cash amount binary operator for division where the first operand is a Cash object the second operand is an integer n : the result is a Cash object this operation can be interpreted as divide the Cash amount by n people assume that n is NOT zero explain the division / operator: how does it relate to multiplication? How did you divide $1 Cash by 3 people? This type of comment needs to be in the interface file. 3) \% binary operator to determine the number of coins (second operand) that would cover the cash amount (first operand): an integer is returned. the first operand is a Cash object the second operand is a Ca.sh coin object precondition: neither the Cash object nor the Cash coin object have no cash Example Cash a (1,22); a : NICKEL returns 25 because 25 NICKELS will cover the bill of Cash of $1.22 and not 24