Question: Objective The objective of this lab is to refactor your code to a more optimized state. You will be creating a button factory to handle

Objective
The objective of this lab is to refactor your code to a more optimized state. You will be creating a button factory to handle the initialization of the buttons and a processor singleton to handle all calculation operations.
Part One: Button Factory Instructions
1. Create a new branch from your existing main branch. Give the branch a name that will be recognizable to you later as button factory works.
2. On your newly created branch, create a new class called ButtonFactory. The methods may be static.
3. Inside the ButtonFactory, you will create functions that facilitate creating each button. Your Button Factory should have one method for generically creating buttons based off of parameters and multiple methods for creating each specific button.
4. Change the logic in your main calculator app to use the button factory.
In your main window code:
//Creating Addition Button
button = new wxButton(...
will become somthing like
//Creating Addition Button
button = ButtonFactory::CreateAddButton();
or
//Creating Addition Button
button = factory.CreateAddButton();
5. What will you need to do to the event table to make this new factory functional? Will you need to use the bind functionality?
6. Try to move as much code over to the ButtonFactory as you can. Inside the ButtonFactory, you may have functions that call other functions in order to make your code more efficient.
7. Once you are done, merge your changes back to your main branch.
Part Two: Processor Singleton Instructions
Create a new branch from your existing main branch. Give the branch a name that will be recognizable to you later as calculator processor work.
On your newly created branch, create a new class called CalculatorProcessor.
Implement this object as a Singleton following the example from Lecture 6.
All string parsing and calculations will be performed inside the ProcessorSingleton.
You should be able to pass your text control string into your ProcessorSingleton's Calculate method, which will return the correct result of the calculation. Something like:
ProcessorSingleton::GetInstance()->Calculate("2+2.5/Sin5");
Should return -0.60708803192
Your calculator should be able to handle more complex calculations that are processed in the correct order of operations. One way to accomplish this is through the Shunting Yard Algorithm.
Treat Sin/Cos/Tan with the highest precedence. You should also be able to perform multiple Sin/Cos/Tan operations in a single expression. Next in the order of priority are modulo (%), multiplication (*) and division (/). The lowest priority operators are addition (+) and subtraction (-).
Unary negation can be treated as part of a number (e.g., expression "1--4" would be tokenized - if using spaces as tokens - to 1,-,-4). Hint: you can inject spaces where appropriate during expression entry. Keyboard entry is not required to be supported.
Bracket support is not required to be implemented for this lab.
Exception Handling
Be sure to fully error test every button. Points will be deducted for every unhandled exception encountered. Double check that exceptions that were handled previously are still being handled gracefully.
Part Two Complete
Once Part Two is complete, merge your changes back to your main branch in, create and push a "Lab 3 Ready for Grading" tag and submit a link to your GitHub commit. Verify your submission, as always.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!