Question: CSCI/CMPE 2380 Assignment 4 (100 pts) Create a new class called Calculator, which should be implemented in two files: Calculator.h and Calculator.cpp. All of the
CSCI/CMPE 2380 Assignment 4 (100 pts) Create a new class called Calculator, which should be implemented in two files: Calculator.h and Calculator.cpp. All of the implementation should be in the cpp file and only the declarations in the header. A calculator should be able to add, subtract, multiply, divide and clear. Test your calculator by writing a main program incorporating the test code below: Calculator mycalc; mycalc.clear(); mycalc.add(4.52); mycalc.add(3.789); mycalc.divide(2.6); mycalc.multiply(3.12); mycalc.subtract(2.678); cout << mycalc.display() << endl; // prints out "7.2928" mycalc.clear(); mycalc.add(5.0); cout << mycalc.display() << endl; // prints out "5" //advanced stuff #1: add a constructor Calculator calc1; cout << calc1.display() << endl; //prints out 0 //advanced stuff #2: add a parameterized constructor Calculator calc2(5); cout << calc2.display() << endl; //prints out 5 //advanced stuff #3: Define calculator addition (overload the '+' operator) Calculator calc3(7); calc1 = calc2 + calc3; cout << calc1.display() << endl; //prints out 12 //advanced stuff #4 (Bonus 10): Create an 'undo' method for the calculator mycalc.undo(); mycalc.undo(); cout << mycalc.display()<< endl; //prints out 7.2928
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
