Programming Questions and Annswers
Programming Questions and Annswers
DESIGNED BY P. MAKAMBA
LANGUAGE:
V.B Studio 2010 Ultimate
WINDOWS FORM APP
CONSOLE APP
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
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.
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
End Sub
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
End Sub
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
End Sub
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
End Sub
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
End Sub
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
End Sub
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
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
End Sub
9
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
End Sub
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
CODE
End Sub
11
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
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
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
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
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.
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
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
End Sub
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
End If
End Sub
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
End Sub
End Module
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
19
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer
End Sub
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.
20
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer
TextBox2.Text = Nothing
TextBox3.Text = Nothing
End Sub
20.
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
21
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer
TextBox1.Text = Nothing
TextBox2.Text = Nothing
TextBox3.Text = Nothing
End Sub
21.
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
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
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
CODE
NB. Selection construct/control structure is applied in this case.
24
Compiled by MAKAMBA .P O78 331 6631 [email protected] Programmers live longer
End Sub
End Class
25