Posted Under: C

Ask A Question
Viewed 16
or this project, you’ll create a form that lets the user perform the operations provided by a basic calculator. You’ll also create a class that performs the required operations. The design of the Calculator form Operation To perform an addition, subtraction, multiplication, or division operation, the user clicks the first number, followed by the appropriate operator key (+, -, *, /), followed by the second number and the equals key (=). Each time the equals key is clicked, the operation is repeated. To calculate the square root or the reciprocal of a number or to change the sign of a number, the user clicks the number followed by the appropriate operator key (sqrt, 1/X, +/-). Each time the user clicks the operator key, the operation is repeated. Each time the user clicks a number key, the number is displayed in the text box at the top of the form. This text box also displays the result of an operation when the user clicks the sqrt, 1/X, +/-, or = key. To erase the last digit entered, the user clicks the Back key. To clear all the values entered, the user clicks the Clear key. Specifications Create a class named Calculator that implements the functions of the calculator. Design whatever methods and properties you need for this class. The Calculator class should accept decimal parameters and provide a decimal result for its calculated values. If the user tries to divide a number by zero, the calculator should display an error message in the text box. The form class should use a try-catch statement to catch a divide-by-zero exception. Notes The calculator that’s created in this project is similar to the calculator that comes with Windows. If you want to, you can study the behavior of the Windows calculator so you have a better idea of how it works. One of the differences between the calculator created in this project and the Windows calculator is that you can perform a calculation by clicking an operator key other than the = key with the Windows calculator. In other words, you can add a list of numbers like this using the Windows calculator: 3 + 12 + 14 + 8 =. With the calculator for this project, you have to perform each calculation separately by clicking the = key like this: 3 + 12 = + 14 = + 8 =. Optional: An enhancement would be for the application to provide for entries from the keyboard. For example, if the user presses the 1 key, the number 1 should be displayed in the calculator. Similarly, if the user presses the = key, the current calculation should be performed. Note, however, that not all of the calculator buttons map to keyboard keys. If you need to simplify this project, you can eliminate the square root and reciprocal functions. The Calculator class design: Property Description CurrentValue The result currently displayed by the calculator. Method Description EnterValue Enters a value into the calculator. The calculator retains the two most recently entered values. Add Sets the pending operation to Add. Subtract Sets the pending operation to Subtract. Multiply Sets the pending operation to Multiply. Divide Sets the pending operation to Divide. Equals Calculates the result of the pending operation. Reciprocal Calculates the reciprocal of the current value. SquareRoot Calculates the square root of the current value. Clear Clears the calculator.

This order does not have tags, yet.


No uploads for this question

Explanations and Answers 0

No answers posted

Post your Answer - free or at a fee

Login to your tutor account to post an answer

Posting a free answer earns you +20 points.


NB: Post a homework question for free and get answers - free or paid homework help.

Get answers to: Calculator or similar questions only at Tutlance.

Related Questions