Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
23 views25 pages

Programming Questions and Annswers

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

Programming Questions and Annswers

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

Compiled by MAKAMBA .P O78 331 6631 makamba5050@gmail.

com Programmers live longer

PROGRAMMING QUESTIONS AND ANNSWERS

DESIGNED BY P. MAKAMBA

LANGUAGE:
V.B Studio 2010 Ultimate
 WINDOWS FORM APP
 CONSOLE APP

Programmers live longer.

1. Write a program to calculate the area of a circle.


WINDOWS FORM APP
 INTERFACE DESIGN

 CODE
NB. -Simple sequence or sequence construct/simple sequence control
structure is applied in this case.
-a code is written after double clicking the intended button eg
calculate, compute, determine, display, decide, clear, exit, login,
compare etc

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim r, area As Decimal
r = TextBox1.Text
area = (22 * r ^ 2) / 7
TextBox2.Text = area
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
TextBox1.Text = Nothing
TextBox2.Text = Nothing
TextBox3.Text = Nothing

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Application.Exit()
End Sub

1
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

End Class

2.

NB. Click the textbox and rename it under (Name) on properties. Apply the
same concept to other textboxes or buttons.

WINDOWS FORM APP


 INTERFACE DESIGN

2
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

 CODE
NB. Simple sequence or sequence construct/simple sequence control
structure is applied in this case.
-a code is written after double clicking the intended button eg
calculate, compute, determine, display, decide, clear, exit, login,
compare etc

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnAverage.Click
Dim test1, test2, sum, average As Integer
test1 = txtTest1.Text
test2 = txtTest2.Text
sum = test1 + test2
average = sum / 2
txtShowAverage.Text = average
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
TextBox1.Text = Nothing
TextBox2.Text = Nothing
TextBox3.Text = Nothing

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Application.Exit()
End Sub
End Class

3. Write a program to calculate the area of a rectangle.


WINDOWS FORM APP
 INTERFACE DESIGN

3
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

 CODE
NB. Simple sequence or sequence construct/simple sequence control
structure is applied in this case.
-a code is written after double clicking the intended button eg
calculate, compute, determine, display, decide, clear, exit, login,
compare etc

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim l, w, area As Integer
l = TextBox1.Text
w = TextBox2.Text
area = l * w
TextBox3.Text = area
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
TextBox1.Text = Nothing
TextBox2.Text = Nothing
TextBox3.Text = Nothing

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Application.Exit()
End Sub
End Class

4. Write a program to calculate the area of a square.


WINDOWS FORM APP
 INTERFACE DESIGN

4
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

 CODE
NB. Simple sequence or sequence construct/simple sequence control
structure is applied in this case.
-a code is written after double clicking the intended button eg
calculate, compute, determine, display, decide, clear, exit, login,
compare etc

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim s, area As Integer
s = TextBox1.Text
area = s ^ 2
TextBox2.Text = area
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
TextBox1.Text = Nothing
TextBox2.Text = Nothing
TextBox3.Text = Nothing

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Application.Exit()
End Sub
End Class

5. Write a program to calculate the area of a trapezium.


WINDOWS FORM APP
 INTERFACE DESIGN

5
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

 CODE
NB. Simple sequence or sequence construct/simple sequence control
structure is applied in this case.
-a code is written after double clicking the intended button eg
calculate, compute, determine, display, decide, clear, exit, login,
compare etc

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim a, b, h, area As Integer
a = TextBox1.Text
b = TextBox2.Text
h = TextBox3.Text
area = ((a + b) * h) / 2
TextBox4.Text = area
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
TextBox1.Text = Nothing
TextBox2.Text = Nothing
TextBox3.Text = Nothing

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Application.Exit()
End Sub
End Class

6. Write a program to accept a username and password, and determine if they


are correct or wrong.
WINDOWS FORM APP
 INTERFACE DESIGN

6
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

 CODE
NB. Selection construct/control structure is applied in this case.
-a code is written after double clicking the intended button eg
calculate, compute, determine, display, decide, clear, exit, login,
compare etc

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim U, P As String
U = TextBox1.Text
P = TextBox1.Text
If U = "PRO" And P = "#MAKAMBA" Then
MsgBox("CORRECT USERNAME AND PASSWORD")
Else
MsgBox("WRONG USERNAME OR PASSWORD")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
TextBox1.Text = Nothing
TextBox2.Text = Nothing
TextBox3.Text = Nothing

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Application.Exit()
End Sub
End Class

7. Write a program to calculate user`s Body Mass Index and decide if the user
is underweight or has normal weight or is overweight in terms of weight.
WINDOWS FORM APP
 INTERFACE DESIGN

7
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

 CODE
NB. Selection construct/control structure is applied in this case.
-a code is written after double clicking the intended button eg
calculate, compute, determine, display, decide, clear, exit, login,
compare etc

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim weight, height, bmi As Decimal
weight = TextBox1.Text
height = TextBox2.Text
bmi = weight / (height) ^ 2
TextBox3.Text = bmi
If weight < 30 Then
MsgBox("under weight")
ElseIf weight >= 30 And weight <= 40 Then
MsgBox("normal weight")
Else
MsgBox("overweight")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
TextBox1.Text = Nothing
TextBox2.Text = Nothing
TextBox3.Text = Nothing

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Application.Exit()
End Sub
End Class

8. Write a program that will accept a mark and decide if it is a fail or pass
or distinction

8
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

WINDOWS FORM APP


 INTERFACE DESIGN

 CODE
NB. Selection construct/control structure is applied in this case.
-a code is written after double clicking the intended button eg
calculate, compute, determine, display, decide, clear, exit, login,
compare etc

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim mark As Integer
mark = TextBox1.Text
If mark >= 0 And Mark < 50 Then
MsgBox("fail")
ElseIf mark >= 50 And mark <= 74 Then
MsgBox("pass")
ElseIf mark >= 75 And mark <= 100 Then
MsgBox("distinction")
Else
MsgBox("INVALID MARK")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
TextBox1.Text = Nothing
TextBox2.Text = Nothing
TextBox3.Text = Nothing

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Application.Exit()
End Sub
End Class

9
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

9. Write a program that will accept a number and decide if it is an even or


odd number.
WINDOWS FORM APP
 INTERFACE DESIGN

 CODE
NB. Selection construct/control structure is applied in this case.
-a code is written after double clicking the intended button eg
calculate, compute, determine, display, decide, clear, exit, login,
compare etc

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim num As Decimal
num = TextBox1.Text
If num Mod 2 = 0 Then
MsgBox("even number")
Else
MsgBox("odd number")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
TextBox1.Text = Nothing
TextBox2.Text = Nothing
TextBox3.Text = Nothing

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Application.Exit()
End Sub
End Class

10.Write a program that will accept a year and determine if it is a leap year
or not.

10
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

WINDOWS FORM APP


 INTERFACE DESIGN

 CODE

NB. Selection construct/control structure is applied in this case.


-a code is written after double clicking the intended button eg
calculate, compute, determine, display, decide, clear, exit, login,
compare etc

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim year As Integer
year = TextBox1.Text
If year Mod 4 = 0 Then
MsgBox("leap year")
Else
MsgBox("not leap year")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
TextBox1.Text = Nothing
TextBox2.Text = Nothing
TextBox3.Text = Nothing

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Application.Exit()
End Sub
End Class

11
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

11.Write a program that will accept a mark of a learner, calculate the


percentage, determine the grade eg A or B etc and pass a comment eg PASS,
FAIL etc.

WINDOWS FORM APP


 INTERFACE DESIGN

 CODE
NB. Selection construct/control structure is applied in this case.
-a code is written after double clicking the intended button eg
calculate, compute, determine, display, decide, clear, exit, login,
compare etc

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim mark, percentage As Integer
mark = TextBox1.Text
percentage = (mark / 100) * 100
TextBox2.Text = percentage
If mark >= 0 And mark <= 29 Then
MsgBox("O, UNGRADED")
ElseIf mark > 29 And mark <= 44 Then
MsgBox("E, PASS ")
ElseIf mark > 44 And mark <= 49 Then
MsgBox("D, PASS ")
ElseIf mark > 49 And mark <= 59 Then
MsgBox("C, CREDIT")
ElseIf mark > 60 And mark <= 74 Then
MsgBox("B, PASS")
ElseIf mark > 75 And mark <= 100 Then
MsgBox("A, DISTINCTION")
Else
MsgBox("INVALID MARK")
End If

End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
TextBox1.Text = Nothing
TextBox2.Text = Nothing

12
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

TextBox3.Text = Nothing

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Application.Exit()
End Sub
End Class

12.Write a program that will calculate the Simple interest.


WINDOWS FORM APP
 INTERFACE DESIGN

 CODE
NB. Simple sequence or sequence construct/simple sequence control
structure is applied in this case.
-a code is written after double clicking the intended button eg
calculate, compute, determine, display, decide, clear, exit, login,
compare etc

Public Class Form1

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
Dim p, r, t, l As Decimal
p = TextBox1.Text
r = TextBox2.Text
t = TextBox3.Text
l = p * r * t / 100
TextBox4.Text = l

End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
TextBox1.Text = Nothing
TextBox2.Text = Nothing
TextBox3.Text = Nothing

13
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Application.Exit()
End Sub
End Class

13.Write a program that will accept a name and mark of a learner, determine if
it is a pass or fail or distinction or invalid mark.
 CONSOLE APP
NB. No interface design
 CODE
NB. Selection construct/control structure is applied in this case.

Module Module1

Sub Main()
Console.WriteLine("ENTER YOUR NAME AND MARK:")
Dim name As String
Dim mark As Integer
Console.WriteLine("ENTER YOUR NAME:")
name = Console.ReadLine()
Console.WriteLine("ENTER YOUR MARK:")
mark = Console.ReadLine()
Select Case mark
Case 75 To 100
Console.WriteLine(name & vbTab & mark & vbTab & "DISTINCTION !!")
Case 50 To 75
Console.WriteLine(name & vbTab & mark & vbTab & "PASS !!")
Case 0 To 49
Console.WriteLine(name & vbTab & mark & vbTab & "FAIL !!")
Case Else
Console.WriteLine("INVALID MARK ???????")
End Select
Console.ReadKey()
End Sub

End Module

14.Write a program that will add 5 set of numbers, find and display their
average.
 CONSOLE APP
NB. No interface design
 CODE
NB. Iteration or looping or repetition construct/control structure is
applied in this case.

Module Module1

Sub Main()
Dim num, x, total, average As Integer
x = 0
average = 0
total = 0

14
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

For x = 0 To 4 Step 0
Console.WriteLine("ENTER NUMBER:")
num = Console.ReadLine()
total = total + num
x = x + 1
Next x
average = total / x
Console.WriteLine("TOTAL:" & total)
Console.WriteLine("AVERAGE:" & average)
Console.ReadKey()
End Sub

End Module

15.Write a program that will accept a set of numbers and determine the largest
and smallest positive number or largest and smallest negative number among
the very set of numbers.

 CONSOLE APP
NB. No interface design
 CODE
NB. A combination of iteration or looping or repetition
construct/control structure and Selection construct/control structure
is applied in this case.

FOR NEXT LOOP

Module Module1

Sub Main()
Dim x, num, lp, sp, ln, sn As Integer
x = 0
lp = 0
sp = 4
ln = 0
sn = 4
For x = 0 To 4 Step 0
Console.WriteLine("ENTER NUMBER:")
num = Console.ReadLine()
x = x + 1
If num < 0 Then
ln = num
End If
If num <= ln Then ln = num
If num >= lp Then lp = num
Next x
Console.WriteLine("LARGEST POSITIVE NUMBER" & lp)
Console.WriteLine("LARGEST NEGATIVE NUMBER:" & ln)
Console.ReadKey()

End Sub
End Module

16.Write a program that will accept a learners name, school and candidate
number.

15
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

WINDOWS FORM APP


 INTERFACE DESIGN

 CODE
NB. Simple sequence or sequence construct/simple sequence control
structure is applied in this case.
-a code is written after double clicking the intended button eg
calculate, compute, determine, display, decide, clear, exit, login,
compare etc

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim N, S As String
Dim C As Integer
N = TextBox1.Text
C = TextBox2.Text
S = TextBox3.Text
MsgBox("NAME:" & N & vbTab & "CANDIDATE NUMBER:" & C & vbTab & "SCHOOL:"
& S)
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
TextBox1.Text = Nothing
TextBox2.Text = Nothing
TextBox3.Text = Nothing

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Application.Exit()
End Sub
End Class

17.Write a program that will accept and compare 2 numbers.


WINDOWS FORM APP
 INTERFACE DESIGN

16
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

 CODE
NB. Selection construct/control structure is applied in this case.
-a code is written after double clicking the intended button eg
calculate, compute, determine, display, decide, clear, exit, login,
compare etc

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim NUM1, NUM2 As Double
NUM1 = TextBox1.Text
NUM2 = TextBox2.Text
If NUM1 < NUM2 Then
MsgBox(NUM1 & vbTab & "IS SMALLER")
ElseIf NUM1 > NUM2 Then
MsgBox(NUM1 & vbTab & "IS BIGGER")
Else
MsgBox("NUMBERS ARE EQUAL")

End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
TextBox1.Text = Nothing
TextBox2.Text = Nothing
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Application.Exit()
End Sub
End Class

18.Write a program that will accept a set of 5 numbers, determine the positive
or negative and calculate the average of set of the numbers entered.

 CONSOLE APP
NB. No interface design
 CODE

17
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

NB. A combination of iteration or looping or repetition


construct/control structure and Selection construct/control structure
is applied in this case.
REPEAT UNTIL CONSTRUCT
Module Module1
Sub Main()
Dim num, count, sumpos, sumneg, overalsum, average As Integer
count = 0
sumpos = 0
sumneg = 0
overalsum = 0
average = 0
Do Until (count > 4)
Console.WriteLine("ENTER ANY NUMBER:")
num = Console.ReadLine()
count = count + 1
If num >= 0 Then
sumpos = sumpos + num
Console.WriteLine("POSITIVE NUMBER")
Else
sumneg = sumneg + num
Console.WriteLine("NEGATIVE NUMBER")
End If
overalsum = sumpos + sumneg
Loop
average = overalsum / count
Console.WriteLine("TOTAL:" & overalsum & vbTab & "AVERAGE:" & average)
Console.ReadKey()

End Sub
End Module

WHILE ENDWHILE CONSTRUCT

Module Module1
Sub Main()
Dim num, count, sumpos, sumneg, overalsum, average As Integer
count = 0
sumpos = 0
sumneg = 0
overalsum = 0
average = 0
While count < 4:
Console.WriteLine("ENTER ANY NUMBER:")
num = Console.ReadLine()
count = count + 1
If num >= 0 Then
sumpos = sumpos + num
Console.WriteLine("POSITIVE NUMBER")
Else
sumneg = sumneg + num
Console.WriteLine("NEGATIVE NUMBER")
End If
overalsum = sumpos + sumneg
EndWhile
average = overalsum / count
Console.WriteLine("TOTAL:" & overalsum & vbTab & "AVERAGE:" & average)

18
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

Console.ReadKey()

End Sub
End Module

17. Write a program that will accept the sales and calculate the bonus of a sales
person. Given that bonus is %3 of more than 500 sales and 0.08% for less than 500
sales.
WINDOWS FORM APP
 INTERFACE DESIGN

 CODE
NB. Selection construct/control structure is applied in this case.
-a code is written after double clicking the intended button eg
calculate, compute, determine, display, decide, clear, exit, login,
compare etc

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim sales, bonus As Double
sales = TextBox1.Text
If sales > 500 Then
bonus = sales * 0.3
TextBox2.Text = bonus
Else
bonus = sales * 0.08
TextBox2.Text = bonus
End If
End Sub
End Class
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
TextBox1.Text = Nothing
TextBox2.Text = Nothing
TextBox3.Text = Nothing

19
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Application.Exit()
End Sub
End Class

19.An educator at VUMBAVIEW ACADEMY is being paid $5 for working 40 hours per
week. Write a program that will calculate his or her monthly gross pay, tax
pay and net pay. Given that tax is %3 of gross pay.

 INTERFACE DESIGN

 CODE
NB. Simple sequence or sequence construct/simple sequence control
structure is applied in this case.
-a code is written after double clicking the intended button eg
calculate, compute, determine, display, decide, clear, exit, login,
compare etc
NB. The results can be displayed on a label.

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim grosspay, tax, netpay As Double
grosspay = 4 * 200
Label4.Text = grosspay
tax = grosspay * 0.1
Label5.Text = taxpay
netpay = grosspay - tax
Label6.Text = netpay
End Sub
End Class
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
TextBox1.Text = Nothing

20
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

TextBox2.Text = Nothing
TextBox3.Text = Nothing

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Application.Exit()
End Sub
End Class

20.

WINDOWS FORM APP


 INTERFACE DESIGN

 CODE
NB. Simple sequence or sequence construct/simple sequence control
structure is applied in this case.
-a code is written after double clicking the intended button eg
calculate, compute, determine, display, decide, clear, exit, login,
compare etc

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnAverage.Click
Dim num As Integer
num = TextBox1.Text
MsgBox("You entered" & vbTab & num)
End Sub
End Class
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

21
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

TextBox1.Text = Nothing
TextBox2.Text = Nothing
TextBox3.Text = Nothing

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Application.Exit()
End Sub
End Class

21.

WINDOWS FORM APP


 INTERFACE DESIGN

 CODE
NB. Simple sequence or sequence construct/simple sequence control
structure is applied in this case.
-a code is written after double clicking the intended button eg
calculate, compute, determine, display, decide, clear, exit, login,
compare etc

Public Class Form1


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAverage.Click
Dim COST, VAT As Integer
COST = TextBox1.Text
VAT = 0.15 * COST

22
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

Label3.Text = VAT
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
TextBox1.Text = Nothing
TextBox2.Text = Nothing
TextBox3.Text = Nothing

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Application.Exit()
End Sub
End Class

NB. The results can be displayed on a label.

22.Write a program that accepts three numbers and determine the minimum value.
WINDOWS FORM APP
 INTERFACE DESIGN

 CODE
NB. Selection construct/control structure is applied in this case.

23
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

-a code is written after double clicking the intended button eg


calculate, compute, determine, display, decide, clear, exit, login,
compare etc

23.Write a program that add or divide or subtract or multiply 2 numbers.


WINDOWS FORM APP
 INTERFACE DESIGN

 CODE
NB. Selection construct/control structure is applied in this case.

24
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer

-a code is written after double clicking the intended button eg


calculate, compute, determine, display, decide, clear, exit, login,
compare etc
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim firstnum, secondnum, op, Result As String
firstnum = TextBox1.Text
secondnum = TextBox2.Text
op = TextBox4.Text
If op = "+" Then
Result = firstnum + secondnum
ElseIf op = "*" Then
Result = firstnum * secondnum
ElseIf op = "/" Then
Result = "firstnum / secondnum"
ElseIf op = "-" Then
Result = firstnum - secondnum
Else
MsgBox("Invalid operator entered")
Result = TextBox5.Text
End If

End Sub
End Class

25

You might also like