Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

mycalc.add(4.52); mycalc.add(3.789); cout << mycalc.display() << endl; // prints

ID: 3619963 • Letter: M

Question

mycalc.add(4.52);
mycalc.add(3.789);
cout << mycalc.display() << endl;       // prints out "8.309"
mycalc.divide(2.6);
mycalc.multiply(3.12);
mycalc.subtract(2.678);

mycalc.squareRoot();
cout << mycalc.display() << endl;       // prints out "2.7005"
mycalc.clear();
mycalc.add(5.0);
cout << mycalc.display() << endl;       // prints out "5"

mycalc.multiply(7.3);

mycalc.undo();

cout << mycalc.display() << endl;       // prints out "5" again

mycalc.add(2.4);

mycalc.multiply(3.4);
mycalc.subtract(1.0);

mycalc.undo();

mycalc.undo();
mycalc.undo();

Explanation / Answer

#include #include #include using namespace std; class Calculator { public: double sum; double un[10]; int opr[10]; int index; void clear() { sum=0; index=-1; system("cls"); } double add(double x) { index++;un[index]=x;opr[index]=1; if(x == 0) return 0; else sum = sum + x; return sum; } void squareRoot() { index++;opr[index]=2; sum = sqrt(sum); } double multiply(double x) { index++;un[index]=x;opr[index]=3; sum *=x; return sum; } double subtract(double x) { index++;un[index]=x;opr[index]=4; sum -=x; return sum; } double divide(double x) { index++;un[index]=x;opr[index]=5; sum /=x; return sum; } double display() { return sum; } void undo(){ if(index