โ Back to Polymorphism
Question 574
Money With Operator Plus
Money With Operator Plus
Build aMoneyclass that supports the+operator. It stores wholeDollarsandCents(0-99). Requirements: 1. ConstructorMoney(int dollars, int cents)stores both values. 2. Overloadoperator +so it adds two amounts and CARRIES cents into dollars (100 cents = 1 dollar). 3. OverrideToString()to return$D.CCwith cents ALWAYS two digits (e.g.$5.25,$1.05). Do NOT write aMainmethod. ForMoney(3, 75) + Money(1, 50)the program prints: $5.25
Expected Output:
$5.25
Topics:
Polymorphism
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cw, cr, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.