Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This means the app needs to remember the x value and the pending operator until you click the = sign. Use the following

This means the app needs to remember the x value and the pending operator until you click the "=" sign. Use the following steps to implement a basic calculator app...
Steps:
Disable the textbox so that the number keys are the only way to enter operands.
You need 3 private Form variables:
x, which is the first operand
pendingOperation, the operator to be applied between x and the next number
isNewNumber, which is true when = has put a result into the textbox, and false as soon as a digit is clicked.
When a digit or decimal point is clicked (note: these can all use the same event handler):
If isNewNumber is true, clear the textbox & equation label, set isNewNumber to false
Cast sender to a Button so you can append its Text to the textbox: i.e.((Button)sender).Text
Ignore a second decimal place if the textbox already has one.
The operator buttons move the textboxs value to x, clears the textbox, and sets pendingOperation to the operator displayed on the button. Again, these can all use the same event handler.
The = buttons event handler has a switch (or a compound if-elseif), applying the pendingOperation between x (stored) and y (in the textbox).
The result is placed in the textbox & appended to the label, x is set to zero, pendingOperation is cleared, and isNewNumber is set to true.
The 12/5=2.4 label above the textbox is obvious, right? The main question is not how... its when... i.e. when are operands and operators appended to it? And when is it cleared?
C and CE (which is short for clear entry) both clear the textbox, while C also clears the label above the textbox, then sets x to zero, pendingOperation to , and isNewNumber to true.
Here is a screenshot of the completed app

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

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

More Books

Students also viewed these Databases questions

Question

On Fig. 10.5, what is feature B? Explain its origin.

Answered: 1 week ago