Escolar Documentos
Profissional Documentos
Cultura Documentos
VB.NET
Submitted in partial fulfillment of the requirement for the
award of degree
Bachelor in Computer
Applications
Submitted To
MS. ALPANA SHARMA
ahlawat
Submitted By
nitish
VIVEKANANDA INSTITUTE OF
PROFESSIONAL STUDIES
NITISH AHLAWAT
BCA-(III-B)
08617702015
INDEX
Sno
1
PROGRAM
TEACHERS
SIGNATURE
10
11
Write a program to
implement jagged array
NITISH AHLAWAT
BCA-(III-B)
08617702015
12
13
Write a program to
demonstrate polymorphism
in vbnet through method
overloading and constructor
overloading
Write a program to
demonstrate constructors
and destructors in vb .net
14
15
16
17
Write a program to
demonstrate single and
multilevel inheritance in
vb.net
write a program for :
1. structured exception
handling
2. for unstructured
exception handling
Write a program to
demonstrate overriding in
vb .net
18
Write a program to
demonstrate abstract class
and abstract methods
19
20
Demonstrate use of
overridable and overrides
keywords in vb.net with a
simple program
Create a program that allows
the user to specify two
numbers and then
adds,subtracts, multiplies
and divides them. An
interface as shown below;
Containing label , textbox
and command button
Create a program that allows
to fill up a list box with items,
retrieve the total number of
items in the list box,sort the
list box, remove some items
and clear the entire list box
Create two groups of radio
button and use their
checkedchanged events for
changing the backcolor and
21
22
23
NITISH AHLAWAT
BCA-(III-B)
08617702015
24
25
27
28
29
30
31
26
NITISH AHLAWAT
BCA-(III-B)
08617702015
Q1. Write a program to check divisibility of a number by 2,3 and 5 using nested if
Ans..
Module Module1
Sub Main()
Dim a As Integer
Console.WriteLine("AKSHAT GUPTA 35317702015")
Console.WriteLine("Enter a")
a = Integer.Parse(Console.ReadLine)
If a Mod 2 = 0 Then
If a Mod 3 = 0 Then
If a Mod 5 = 0 Then
Console.WriteLine("Number is divisible by 2,3 and 5")
Else
Console.WriteLine("Number is divisible by 2,3 and not by 5")
End If
ElseIf a Mod 5 = 0 Then
Console.WriteLine("Number is divisible by 2 & 5 and not by 3")
Else
Console.WriteLine("Number is divisible by 2")
End If
ElseIf a Mod 3 = 0 Then
If a Mod 5 = 0 Then
Console.WriteLine("Number is divisible by 3 and 5")
Else
Console.WriteLine("Number is divisible by 3")
End If
ElseIf a Mod 5 = 0 Then
Console.WriteLine("Number is divisible by 5 only")
Else
Console.WriteLine("Number is not divisible by 2,3 and 5")
End If
NITISH AHLAWAT
BCA-(III-B)
08617702015
End Sub
End Module
OUTPUT
Sub Main()
Console.WriteLine("AKSHAT GUPTA
35317702015")
NITISH AHLAWAT
BCA-(III-B)
08617702015
Console.WriteLine(" MOD operator : " & num1 & " MOD " & num2 & " = " & num1
Mod num2)
Console.WriteLine("---- COMPARISON OPERATORS ----")
If num1 = num2 Then
Console.WriteLine(" = operator : " & num1 & " = " & num2 & " -> True")
Else
Console.WriteLine(" = operator : " & num1 & " = " & num2 & " -> False")
End If
If num1 <> num2 Then
Console.WriteLine(" <> operator : " & num1 & " <> " & num2 & " -> True")
Else
Console.WriteLine(" <> operator : " & num1 & " <> " & num2 & " -> False")
End If
If num1 > num2 Then
Console.WriteLine(" > operator : " & num1 & " > " & num2 & " -> True")
Else
Console.WriteLine(" > operator : " & num1 & " > " & num2 & " -> False")
End If
If num1 < num2 Then
Console.WriteLine(" < operator : " & num1 & " < " & num2 & " -> True")
Else
Console.WriteLine(" < operator : " & num1 & " < " & num2 & " -> False")
End If
If num1 >= num2 Then
Console.WriteLine(" >= operator : " & num1 & " >= " & num2 & " -> True")
Else
Console.WriteLine(" >= operator : " & num1 & " >= " & num2 & " -> False")
End If
If num1 <= num2 Then
Console.WriteLine(" <= operator : " & num1 & " <= " & num2 & " -> True")
NITISH AHLAWAT
BCA-(III-B)
08617702015
Else
Console.WriteLine(" <= operator : " & num1 & " <= " & num2 & " -> False")
End If
Console.WriteLine("---- LOGICAL OPERATORS ----")
Console.WriteLine("Enter first Boolean value : ")
exp1 = Console.ReadLine()
Console.WriteLine("Enter second Boolean value : ")
exp2 = Console.ReadLine()
exp3 = exp1 And exp2
Console.WriteLine(" AND operator : " & exp1 & " AND " & exp2 & " = " & exp3)
exp3 = exp1 Or exp2
Console.WriteLine(" OR operator : " & exp1 & " OR " & exp2 & " = " & exp3)
exp3 = Not exp1
Console.WriteLine(" NOT operator : NOT " & exp1 & " = " & exp3)
exp3 = exp1 Xor exp2
Console.WriteLine(" XOR operator : " & exp1 & " XOR " & exp2 & " = " & exp3)
exp3 = exp1 AndAlso exp2
Console.WriteLine(" AndAlso operator : " & exp1 & " AndAlso " & exp2 & " = " &
exp3)
exp3 = exp1 OrElse exp2
Console.WriteLine(" OrElse operator : " & exp1 & " OrElse " & exp2 & " = " & exp3)
Console.WriteLine("---- BIT WISE OPERATORS ----")
num3 = num1 And num2
Console.WriteLine(" AND operator : " & num1 & " AND " & num2 & " = " & num3)
num3 = num1 Or num2
Console.WriteLine(" OR operator : " & num1 & " OR " & num2 & " = " & num3)
num3 = Not num1
Console.WriteLine(" NOT operator : NOT " & num1 & " = " & Not num1)
num3 = num1 Xor num2
Console.WriteLine(" XOR operator : " & num1 & " XOR " & num2 & " = " & num3)
NITISH AHLAWAT
BCA-(III-B)
08617702015
End Module
OUTPUT
NITISH AHLAWAT
BCA-(III-B)
08617702015
08617702015
c = Console.ReadLine()
Console.WriteLine(b * c)
Case 3
Console.WriteLine("Enter the digits")
b = Console.ReadLine()
c = Console.ReadLine()
Console.WriteLine(b - c)
Case 4
Console.WriteLine("Enter the divident")
b = Console.ReadLine()
Console.WriteLine("Enter the divisor")
c = Console.ReadLine()
Console.WriteLine(b / c)
End Select
End Sub
End Module
OUTPUT
Q4. Write a program to check whether the number is prime or not using while loop
Ans..
Module Module1
Sub Main()
Dim a, i As Integer
Dim f As Integer
Console.WriteLine("AKSHAT GUPTA 35317702015")
Console.WriteLine("Enter a number")
a = Console.ReadLine()
i=a
While (i > 1)
If a Mod i = 0 Then
f=f+1
End If
If f > 2 Then
Console.WriteLine("Not a prime number")
NITISH AHLAWAT
BCA-(III-B)
08617702015
Exit While
End If
i=i-1
End While
If f < 2 Then
Console.WriteLine("The number " & a & " is prime")
End If
End Sub
End Module
OUTPUT
NITISH AHLAWAT
BCA-(III-B)
08617702015
End Sub
End Module
OUTPUT
Q6. WAP sub procedure to swap two nos by passing Parameters by value and by
reference
Ans..
Module Module1
Sub swapval(ByVal x As Integer, ByVal y As Integer)
Dim temp As Integer
temp = x
x=y
y = temp
Return
End Sub
Sub swapref(ByRef a As Integer, ByRef b As Integer)
Dim temp As Integer
temp = a
a=b
NITISH AHLAWAT
BCA-(III-B)
08617702015
b = temp
End Sub
Sub Main()
Console.WriteLine("AKSHAT GUPTA 35317702015")
Console.WriteLine("enter choice, 1 to swap by value ,2 to swap by reference")
Dim choice As Integer = Integer.Parse(Console.ReadLine())
Select Case choice
Case 1
Console.WriteLine("enter numbers to swap")
Dim num1 As Integer = Integer.Parse(Console.ReadLine())
Dim num2 As Integer = Integer.Parse(Console.ReadLine())
swapval(num1, num2)
Console.WriteLine("swapped values of num1 and num2 are respectively " & num1
& " " & num2)
Case 2
Console.WriteLine("enter numbers to swap")
Dim num1 As Integer = Integer.Parse(Console.ReadLine())
Dim num2 As Integer = Integer.Parse(Console.ReadLine())
swapref(num1, num2)
Console.WriteLine("swapped values of num1 and num2 are respectively " & num1
& " " & num2)
End Select
End Sub
End Module
OUTPUT
BY VALUE
NITISH AHLAWAT
BCA-(III-B)
08617702015
BY REFERENCE
Q7. Write a function procedure to find the greatest no.among three numbers.
Ans..
Module Module1
NITISH AHLAWAT
BCA-(III-B)
08617702015
NITISH AHLAWAT
BCA-(III-B)
08617702015
Module module1
Sub Main()
Console.WriteLine("AKSHAT GUPTA 35317702015")
Dim n, i, s, l As Integer
Console.Write("enter the number of elements : ")
n = Integer.Parse(Console.ReadLine())
Dim arr(n) As Integer
For i = 0 To n - 1
Console.Write("enter the value : ")
arr(i) = Integer.Parse(Console.ReadLine())
Next
Console.WriteLine("Array Contains ..... ")
For i = 0 To n - 1
Console.Write(arr(i) & " ")
Next
s = arr(0)
l = arr(0)
For i = 0 To n - 1
If arr(i) < s Then
s = arr(i)
End If
Next
For i = 0 To n - 1
If arr(i) > l Then
l = arr(i)
End If
Next
Console.WriteLine()
Console.WriteLine("Smallest Number Is = " & s)
Console.WriteLine("Largest Number Is = " & l)
End Sub
End Module
OUTPUT
NITISH AHLAWAT
BCA-(III-B)
08617702015
NITISH AHLAWAT
BCA-(III-B)
08617702015
Ans..
Module Module1
Sub Main()
Console.WriteLine("Simran Kapoor")
Dim arr1(1, 1), arr2(1, 1), arr3(1, 1), i, j As Integer
Console.WriteLine("Enter elements of first matrix : ")
For i = 0 To 1
For j = 0 To 1
arr1(i, j) = Integer.Parse(Console.ReadLine())
Next
Next
Console.WriteLine("Enter elements of second matrix : ")
For i = 0 To 1
For j = 0 To 1
arr2(i, j) = Integer.Parse(Console.ReadLine())
Next
Next
For i = 0 To 1
For j = 0 To 1
arr3(i, j) = arr1(i, j) + arr2(i, j)
Next
Next
Console.WriteLine(" Matrix 1 + Matrix 2 = : ")
For i = 0 To 1
For j = 0 To 1
Console.WriteLine(arr3(i, j))
Next
Next
Console.ReadKey()
End Sub
End Module
NITISH AHLAWAT
BCA-(III-B)
08617702015
OUTPUT
NITISH AHLAWAT
BCA-(III-B)
08617702015
NITISH AHLAWAT
BCA-(III-B)
08617702015
Next
End Sub
End Module
OUTPUT
NITISH AHLAWAT
BCA-(III-B)
08617702015
NITISH AHLAWAT
BCA-(III-B)
08617702015
NITISH AHLAWAT
BCA-(III-B)
08617702015
NITISH AHLAWAT
BCA-(III-B)
08617702015
areas(l)
Case 2
Write("Enter length : ")
l = Integer.Parse(Console.ReadLine())
Write("Enter breadth : ")
b = Integer.Parse(Console.ReadLine())
areas(l, b)
Case 3
Write("Enter radius : ")
r = Integer.Parse(Console.ReadLine())
areas(r)
Case Else
Console.WriteLine("Enter a Valid Choice")
End Select
End Sub
End Module
OUTPUT
NITISH AHLAWAT
BCA-(III-B)
08617702015
NITISH AHLAWAT
BCA-(III-B)
08617702015
NITISH AHLAWAT
BCA-(III-B)
08617702015
OUTPUT
NITISH AHLAWAT
BCA-(III-B)
08617702015
NITISH AHLAWAT
BCA-(III-B)
08617702015
a)Structured exception
Module Module1
Sub Main()
Dim a, b, c As Integer
Console.WriteLine("AKSHAT GUPTA 35317702015")
Console.WriteLine("Enter a and b")
Try
a = Integer.Parse(Console.ReadLine())
b = Integer.Parse(Console.ReadLine())
c=a/b
Console.WriteLine("Division =" & c)
Catch ex As Exception
Console.WriteLine(ex.message)
Finally
Console.WriteLine("Final block executed")
End Try
End Sub
End Module
OUTPUT
NITISH AHLAWAT
BCA-(III-B)
08617702015
NITISH AHLAWAT
BCA-(III-B)
08617702015
NITISH AHLAWAT
BCA-(III-B)
08617702015
NITISH AHLAWAT
BCA-(III-B)
08617702015
NITISH AHLAWAT
BCA-(III-B)
08617702015
OUTPUT
NITISH AHLAWAT
BCA-(III-B)
08617702015
Q20. Write a program to demonstrate the use of Overridable and overrides key.
Ans..
Module Module1
Class add
Protected a As Integer
Protected b As Integer
Public Sub New(ByVal x As Integer, ByVal y As Integer)
a=x
b=y
End Sub
Public Function getsum() As Integer
Return (a + b)
End Function
Public Overridable Sub showdata()
Console.WriteLine("AKSHAT GUPTA
35317702015")
Console.WriteLine("a=" & a)
Console.WriteLine("b=" & b)
Console.WriteLine("sum=" &getsum())
End Sub
End Class
Class sum : Inherits add
Private c As Integer
Public Sub New(ByVal a As Integer, ByVal b As Integer)
MyBase.new(a, b)
End Sub
Public Function getresult() As Integer
Dim c As Integer
c = getsum() + 10
Return c
End Function
Public Overrides Sub showdata()
MyBase.showdata()
Console.WriteLine("After adding 10 sum is")
Console.WriteLine("c:{0}", getresult())
End Sub
End Class
SubMain()
Dim s As New sum(45, 65)
s.showdata()
Console.ReadLine()
End Sub
End Module
NITISH AHLAWAT
BCA-(III-B)
08617702015
OUTPUT
NITISH AHLAWAT
BCA-(III-B)
08617702015
Q21. Create a program that allows the user to add , multiply ,subtract,divide two
numbers.
An interface contatining label,textbox and command button.
Partial Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox2.TextChanged
End Sub
Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox3.TextChanged
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim a, b, r As Double
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
r=a+b
TextBox3.Text = r
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim a, b, r As Double
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
r=a-b
TextBox3.Text = r
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim a, b, r As Double
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
r=a*b
TextBox3.Text = r
End Sub
NITISH AHLAWAT
BCA-(III-B)
08617702015
OUTPUT
NITISH AHLAWAT
BCA-(III-B)
08617702015
NITISH AHLAWAT
BCA-(III-B)
08617702015