0% found this document useful (0 votes)
21 views6 pages

Arithmetic Calculator Program Guide

Uploaded by

madhavvisani10
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views6 pages

Arithmetic Calculator Program Guide

Uploaded by

madhavvisani10
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Prac cal :-1

Aim :- Write a program for Arithme c Calculator using Windows Applica on.

Steps:-

=> Define the Form1 class and declare variables.


=> Each number bu on (0-9) has an event handler that appends the bu on's text to the text
box. Clarity updates the display with the clicked number.
=> Each operator bu on (+, -, x, /) stores the first operand (a) and the operator (op), then
clears the display for the second operand (b) and Each Operand enter then clears the display.
=> Retrieve the second operand, calculate based on the operator, and display the result.
=> The result (ans) is stored and displayed.
=> Clear the display when the clear bu on is clicked.

[Link] Code:-

Public Class Form1


Dim a As Integer
Dim b As Integer
Dim ans As Integer
Dim op As Char

/*All number 0 to 9 Events */


Private Sub btn1_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
[Link] += [Link]
End Sub

1
Private Sub btn2_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
[Link] += [Link]()
End Sub
Private Sub btn3_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
[Link] += [Link]()
End Sub

Private Sub btn4_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]
[Link] += [Link]()
End Sub

Private Sub btn5_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]
[Link] += [Link]()
End Sub

Private Sub btn6_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]
[Link] += [Link]()
End Sub

2
Private Sub btn7_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
[Link] += [Link]()
End Sub
Private Sub btn8_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
[Link] += [Link]()
End Sub
Private Sub btn9_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
[Link] += [Link]()
End Sub
Private Sub btn0_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
[Link] += [Link]()
End Sub
/*For Addi on*/
Private Sub btnAdd_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
op = [Link]
a = Convert.ToInt16([Link])
[Link]()
End Sub
/*For Answer (=) of the number */
Private Sub btnAns_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]

3
b = Convert.ToInt16([Link])
If op = "+" Then
ans = a + b
End If
If op = "-" Then
ans = a - b
End If
If op = "x" Then
ans = a * b
End If
If op = "/" Then
ans = a / b
End If
[Link]()
[Link] = [Link]()

End Sub
/*For Clear the Screen*/
Private Sub btnClear_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
[Link]()
End Sub

/*For Subtarc on*/

4
Private Sub btnSub_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
op = [Link]
a = Convert.ToInt16([Link])
[Link]()
End Sub

/*For Mul pica on*/


Private Sub btnMul_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
op = [Link]
a = Convert.ToInt16([Link])
[Link]()
End Sub

/*For Division*/
Private Sub btnDiv_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
op = [Link]
a = Convert.ToInt16([Link])
[Link]()
End Sub
End Class

5
Form1 OutPut:

Common questions

Powered by AI

Manually clearing the display after operations may lead to a cumbersome user experience, especially if forgotten, leading to unintended input errors. Automatic clearing or automatically switching the display context after pressing '=' would enhance fluidity and reduce user errors .

Clearing the display is necessary to distinguish between input phases: after selecting an operation, clearing allows the user to enter the second operand without confusion or unintentional inputs overlapping with the first operand .

The program uses the 'txtDisplay.Clear()' method to clear the text display area. This is triggered by clicking the clear button or after displaying the result of an operation .

Not handling division by zero could result in a runtime error or incorrect results as dividing by zero is undefined. To mitigate this, the program should include a conditional check before performing division, displaying an error message if division by zero is attempted .

The program follows a sequence where it first stores the first operand and the operation when an arithmetic operator is clicked. It then clears the display to accept the second operand. After the second operand is entered and the '=' button is pressed, an event handler executes conditional logic based on the operator to perform the operation (e.g., addition, subtraction), calculates the result, and displays it .

The program assumes operands are of integer data type, using `Convert.ToInt16`. This limits computations to integer values only, which could lead to loss of precision when dealing with decimal numbers or division operations where a non-integer result is intended .

The program uses a character variable `op` to store the operation selected by the user. In the answer event handler, if-else conditions determine which arithmetic operation to perform based on the stored operator ('+', '-', 'x', '/').

The program handles displaying numbers by defining event handlers for each number button (0-9). When clicked, these handlers append the button's text to the text display box, updating it with the clicked number .

Event handlers are associated with button clicks through the `Handles` clause in the method signature of the click event handler. Each number or operation button has a specific event handler that appends the button's label to the display or sets an operation, respectively .

An enhancement could include adding functionalities for handling floating-point numbers to accommodate a wider range of mathematical calculations, along with providing error messages for invalid operations like division by zero. This would greatly increase the utility and robustness of the calculator .

You might also like