[Solved] CIST2341 Create a simple calculator

$25

File Name: CIST2341_Create_a_simple_calculator.zip
File Size: 329.7 KB

SKU: [Solved] CIST2341 Create a simple calculator Category: Tag:
5/5 - (1 vote)

In this exercise, you will create a form that accepts two numbers and an operator from the user and then performs the requested operation.

  1. Start a new project named SimpleCalculator
  2. Add labels, text boxes, and buttons to the default form and set the properties of the form and its controls so they appear as shown above. Controls are to have meaningful names.
  3. When the user presses the Enter key, the Click event of the Calculate button fire. When the user presses the Esc key, the Click event of the Exit button fire.
  4. Rename the form to frmSimpleCalculator. When ask to modify any references to the form, click the Yes button.
  5. Code a private method named Calculate that performs the requested operation and returns a decimal value. This method should accept the following arguments:

Argument Description

decimal num1 The value entered for the first operand.

string operator1 One of these four operators: +, -, *, or /.

decimal num2 The value entered for the second operand.

  1. Create an event handler for the Click event of the Calculate button. This event handler should get the two numbers and operator the user enters, call the Calculate method to get the result of the calculation, display the result rounded to four decimal places, and move the focus to the Number 1 text box.
  2. Create an event handler for the Click event of the Exit button closes the form.
  3. Create an event handler that clears the Result text box if the user changes the text in any of the other text boxes.
  4. Add a try-catch statement in the btnCalculate_Click event handler that will catch any exceptions that occur when the statements in that event handler executed. If an exception occurs, display a dialog box with the error message, the type of error, and a stack trace. Test the application by entering a nonnumeric value for one of the operands.
  5. Add three additional catch blocks to the try-catch statement that will catch a FormatException, an OverflowException, and a DivideByZeroException. These catch blocks display a dialog box with an appropriate error message.
  6. Test the application again by entering a nonnumeric value for one of the numbers. Then, enter 0 for the second operand number to see what happens.
  7. Code methods named IsPresent, IsDecimal, and IsWithinRange work like the methods described in chapter 7 of the book.
  8. Code a method named IsOperator to check the text box passed to it contains a value of +, -, *, or /.
  9. Code a method named IsValidData checks the Number1 and Number 2 text boxes contain a decimal value between 0 and 1,000,000 (non-inclusive) and tOperator text box contains a valid operator.
  10. Use block or single comments to comment out (do not delete the code) all of the catch blocks from the try-catch statement in the btnCalculate_Click event handler except for the one that catches any exception. Then, add code to this event handler that performs the calculation and displays the result only if the values of the text boxes are valid.
  11. Test the application to be sure it works correctly.
  12. Include a header with your name, date, and purpose of the program and meaningful comments throughout the program.
  13. Zip the entire project folder before submitting to the drop box. Do not go inside the folder created when the project created. To zip right click on the folder -> Click Sent to -> Click Compressed (zipped) folder. Do not go inside the zipped folder to run the program the program compressed. To run the program again, go back to the original folder not zipped.

[Project must be completed using Visual Studio using C# .Net language using create a new windows form option in visual studio.]

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CIST2341 Create a simple calculator
$25