Monday, June 6, 2011

Arithmetic Statement

Arithmetic Statement

Unknown 3 (three) pieces of numbers A, B and C. Make a visual basic program to solve the following arithmetic equation:
P = A + B
Q = B-A
X = A + BC
R = (A + B) * C
S = (A + B) * (A-C)
M = A Mod 2
N = B-A + C ^ 2

- user interface program

- Implementation

Dim A, B, C As Single 'Global Declaration

Private Sub cmdHitungM_Click ()
Dim B As Single
A = Val (txtA.Text)
B = Val (txtB.Text)
M = A Mod 2
txtM.Text = Str (M)
End Sub

Private Sub cmdHitungN_Click ()
Dim N As Single
A = Val (txtA.Text)
B = Val (txtB.Text)
C = Val (txtC.Text)
N = B - A + C ^ 2
txtN.Text = Str (N)
End Sub

Private Sub cmdHitungP_Click ()
Dim P As Single
A = Val (txtA.Text)
B = Val (txtB.Text)
P = A + B
txtP.Text = Str (P)

End Sub

Private Sub cmdHitungQ_Click ()
Dim Q As Single
A = Val (txtA.Text)
B = Val (txtB.Text)
Q = B - A
txtQ.Text = Str (Q)
End Sub

Private Sub cmdHitungR_Click ()
Dim R As Single
A = Val (txtA.Text)
B = Val (txtB.Text)
C = Val (txtC.Text)
R = (A + B) * C
txtR.Text = Str (R)
End Sub

Private Sub cmdHitungS_Click ()
Dim S As Single
A = Val (txtA.Text)
B = Val (txtB.Text)
C = Val (txtC.Text)
S = (A + B) * (A - C)
txtS.Text = Str (S)
End Sub

Private Sub cmdHitungX_Click ()
Dim X As Single
A = Val (txtA.Text)
B = Val (txtB.Text)
X = A + B * C
txtX.Text = Str (X)
End Sub

Private Sub cmdTutup_Click ()
End
End Sub

- Running

Analysis
 Statement P = A + B, can be understood by Visual Basic because the procedure of writing (syntax) is correct. This expression can be described also as follows:
 P is the operand
 = Is the operator
 A is the operand
 + Is an operator
 B is the operand
 So from the above statement there are 3 pieces of operands.

Operands in Visual Basic can be identifiers, functions or constants. The statement Z = 5 + 5 also can be recognized by visual basic. Number 5 in the statement is an operand whose value is 5. Statement
 Z = rank (5) + A also can be understood by Visual Basic when the definition of rank function with the parameters already defined.

Each statement of Visual Basic can be divided into 2 (two) groups:
 -Groups of the left (left operand) and
 Right-group (right) operand)
 between groups separated by an equal sign (=)

On the left of the group must be identification, whether variable or constant identifier and not the value of variables, constants. Visual Basic does not recognize this writing the following statement:
 5 = A + B 'false statement
 5 + 5 = A 'statement wrong
 "Santi" = A 'statement wrong
 Rank (5) = 10 'false statement

The statement will be true when written like this:
 Z = A + B
 A = 5 + 5
 A = "santi" 'set of characters (string) given to the identification A
 Z = rank (5) 'statement called the rank function with 5 parameters

The order of execution in both groups will start from the second group. Further progress in the second group will be tailored to the degree of the operator (see note below for details). Suppose there is a statement:
 Z = A + C - B
 then the process will begin the process of:
 1. A + B, ie X
 2. X - B, ie R
 3. R was given to Z

Notes
 -Of particular interest in the formation of an arithmetic expression is a sequence of execution of each operator.
 -The order processing service will start from the left.
 -If found, the bracketed expressions in parentheses will be done the first time
 Rank-Operator (^) is the operator that has the highest degree of workmanship. The execution of the operator ^ more precedence than the operator /, *, Mod, + or -.
 -Operator for (/), times (*) and Mod (remainder of) have the same degree of craftsmanship and workmanship higher priority than the operator plus (+) and minus (-).
 -The operator plus (+) and minus (-) have the same degree of workmanship.

No comments:

Post a Comment

 
THANK YOU FOR VISITING