Question: I need help ASAP , the code doesnt has to be run , Thanks :D (C++) #ifndef CALCULATOR_H_ #define CALCULATOR_H_ class Calculator { public: Calculator();

I need help ASAP , the code doesnt has to be run , Thanks :D (C++)
#ifndef CALCULATOR_H_
#define CALCULATOR_H_
class Calculator {
public:
Calculator();
~Calculator();
void add(double);
void subtract(double);
double getResult();
void undo();
void redo();
void printAllOperations();
private:
double result;
/*****************
* Add any fields you need
*****************/
};
#endif /* CALCULATOR_H_ */
#include
#include "Calculator.h"
using namespace std;
int main(){
try{
Calculator c;
c.add(1);
c.add(14);
c.subtract(6);
c.add(4);
// Result is 13
cout
c.undo(); // Expects 9
cout
c.undo(); // Expects 15
cout
c.redo(); // Expects 9
cout
c.redo(); // Expects 13
cout
// c.redo(); // Uncommenting this statement should throw an error
that no more redoes are possible
// cout
c.undo(); // Expects 9
cout
c.printAllOperations(); //Prints all the operations from
the beginning
// Expects Add 1. Add 14. Subtract 6. Add 4. Undo. Undo.
Redo. Redo. Undo.
}
catch(const char* c){
cout
}
Problem 2 In this problem, you will implement undo and redo functionality for a calculator that performs only add or subtract operations. A user's actions may perform add or subtract operation on the last output of the calculator. After each action, the user may perform an undo or redo operation until such an operation is possible. Undo operation invalidates the last operation performed, and redo performs the last undone operation. E.g., the user has already performed the actions as follows (calculator starts with a value 0) i. Add1 ii Add 14 iii. Subtract 6 iv. Add 4 At this point, the result of the calculation is 13. Now, an undo operation undoes the most recent operation i.e., "Add 4" is undone, and the calculator output becomes 9. Another undo operation undoes the operation before it, and the calculator output becomes 15. A redo operation redoes the last operation that was undone, i.e., calculator output becomes 9. Another redo operation makes the output go back to 13. At this point no more undo operations are possible You are provided two files Calculator.h and main.cpp. Calculator.h consists of the declaration of the calculator class. main.cpp consists of test cases and expected behavior of the program. An important operation you will need to support is the ability to print all the operations performed (the history of all operations). You may choose to store this information in an array or a linked list. You may not use any STL data structures or other libraries. You will need to create a file called Calculator.cpp, in which you will implement the functions declared in Calculator.h that supports the operations provided in main.cpp. Implement undo and redo operations using stacks. You may use the STL stack, or your own implementation of stacks. Include multiply and divide functionalities for bonus points. In a file called Calculator.pdf, include your ideas on the algorithm and implementation. Also include all your sources in this file Problem 2 In this problem, you will implement undo and redo functionality for a calculator that performs only add or subtract operations. A user's actions may perform add or subtract operation on the last output of the calculator. After each action, the user may perform an undo or redo operation until such an operation is possible. Undo operation invalidates the last operation performed, and redo performs the last undone operation. E.g., the user has already performed the actions as follows (calculator starts with a value 0) i. Add1 ii Add 14 iii. Subtract 6 iv. Add 4 At this point, the result of the calculation is 13. Now, an undo operation undoes the most recent operation i.e., "Add 4" is undone, and the calculator output becomes 9. Another undo operation undoes the operation before it, and the calculator output becomes 15. A redo operation redoes the last operation that was undone, i.e., calculator output becomes 9. Another redo operation makes the output go back to 13. At this point no more undo operations are possible You are provided two files Calculator.h and main.cpp. Calculator.h consists of the declaration of the calculator class. main.cpp consists of test cases and expected behavior of the program. An important operation you will need to support is the ability to print all the operations performed (the history of all operations). You may choose to store this information in an array or a linked list. You may not use any STL data structures or other libraries. You will need to create a file called Calculator.cpp, in which you will implement the functions declared in Calculator.h that supports the operations provided in main.cpp. Implement undo and redo operations using stacks. You may use the STL stack, or your own implementation of stacks. Include multiply and divide functionalities for bonus points. In a file called Calculator.pdf, include your ideas on the algorithm and implementation. Also include all your sources in this file
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
