We have at least two options on how to proceed. The new functions
can be placed directly
into the class currency or
we can place the new functions in a class
enhancedCurrency which is
derived from
currency.
We shall take the former approach.
The code for the new functions is given below as well as in the file
enhancedCurrencyNew.h.
void input()
{
// input the amount as a double
cout << "Enter the currency amount as a real number" << endl;
double theValue;
cin >> theValue;
// set the value
setValue(theValue);
}
currency subtract(const currency& x)
{// Return *this - x.
currency result;
result.amount = amount - x.amount;
return result;
}
currency percent(float x)
{// Return x percent of *this.
currency result;
result.amount = (long) (amount * x / 100);
return result;
}
currency multiply(float x)
{// Return this * x.
currency result;
result.amount = (long) (amount * x);
return result;
}
currency divide(float x)
{// Return this / x.
currency result;
result.amount = (long) (amount / x);
return result;
}