Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part Two: Event Handling Instructions Create a new branch from your existing main branch. Give the branch a name that will be recognizable to you

Part Two: Event Handling Instructions
Create a new branch from your existing main branch. Give the branch a name that will be recognizable to you later as events works.
On your newly created branch, implement an event table that handles click events for every button. Do not use bind for this lab.
Button Functionality
When the following buttons are pressed, their button label or corresponding symbol will be added to the text control.
Numbers 0-9
Binary Operation Buttons (+,-,*,/,%)
Decimal Button
Negative Button
Unary Operation Buttons (Sin, Cos, Tan)
-Clear Button
The clear button should fully clear the text box and the backspace button should remove the last character in the textbox. The backspace button should repeat this behavior until there's nothing left in the textbox.
-Backspace/Delete Button
The backspace button should delete the last character in the text control. Repeatedly pressing the backspace button should continue deleting each character until the text control is empty. The program should not crash if the text control is empty.
-Equals Button
The = button will attempt to calculate whatever string is contained within the text control, clear it, and display the result in the text control.
The program should not crash if the text box is empty or if the text control contains an invalid expression.
-Calculations
Implement simple calculations (+,-,*,/,%(mod)). At the very least, you should be able to perform each of these math operations on two numbers. (2+2 should work, but 2+2+2 does not need to just yet).
Review string parsing concepts to tokenize the string in your textbox into separate tokens. If "5.5*-20" is in your textbox, pressing = should parse "5.5" and "-20" as floating point values and "*" as the operation to occur between those two values. There are several ways to accomplish this. Also note that unary negation should be supported and expression such as, for example, "1--3" should evaluate to 4.
wxWidgets comes with it's own wxStringTokenizer that you may use. You also have the option to make your own tokenizer, but this is not recommended for this assignment.
-Simple unary operations (Sin, Cos, Tan) should also be implemented. Pressing Sin and 5 should add "Sin 5" to your textbox, and pressing = should result in the Sine of 5.
-Unary operations should still be added as a string to your text box. Do not immediately evaluate numbers in your textbox. The equals button should still be pressed in order to evaluate any expressions, including unary operations.
Try to find a way to implement the event table without having everything hardcoded. You should be able to handle all events in a single event function (a portion of this is shown in Lecture 3)
-Exception Handling
Basic exception handling is required. It's your responsibility to ensure that any thrown exceptions are handled gracefully and do not crash the program. Any program you write should be thoroughly tested to the best of your abilities. Common exceptions include but may not be limited to:
Pressing backspace on an empty text box
Dividing and modding by 0
Evaluating an empty textbox
Evaluating an invalid expression (5=,5++=,5++2=,5..0+2=,5++++=, etc

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions