0% found this document useful (0 votes)
7 views

vb.net assignments Oct 2018

The document contains multiple assignments for a VB.NET course at L.K.Dr.P.R.Ghogrey Science College, detailing various programming tasks such as sorting arrays, finding maximum numbers, calculating factorials, checking for Armstrong numbers, demonstrating exception handling, single inheritance, interfaces, and polymorphism. Each assignment includes code snippets and expected outputs. The assignments aim to enhance students' understanding of VB.NET programming concepts.

Uploaded by

laita nikam
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

vb.net assignments Oct 2018

The document contains multiple assignments for a VB.NET course at L.K.Dr.P.R.Ghogrey Science College, detailing various programming tasks such as sorting arrays, finding maximum numbers, calculating factorials, checking for Armstrong numbers, demonstrating exception handling, single inheritance, interfaces, and polymorphism. Each assignment includes code snippets and expected outputs. The assignments aim to enhance students' understanding of VB.NET programming concepts.

Uploaded by

laita nikam
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

S.S.V.P.

Sanstha’s
L.K.Dr.P.R.Ghogrey Science College, Dhule
Department of Computer Science
Sub:- VB.NET
Roll No : Date:
Name :-
Assignment No- 1)Sorting of Array in descending order –console applicaton

Module Module1
Sub Main()
Dim a(10), i, j, temp As Integer
temp = 0
Console.WriteLine("enter Array")
For i = 1 To 10
a(i) = Val(Console.ReadLine())
Next
For i = 1 To 10
For j = 1 To 10
If a(i) > a(j) Then
temp = a(i)
a(i) = a(j)
a(j) = temp

End If
Next
Next
Console.WriteLine("sorted desending order of array")
For i = 1 To 10
Console.WriteLine("{0}", a(i))
Next
Console.ReadKey()

End Sub

End Module

enter Array
100
101
80
105
70
104
85
110
66
77
sorted desending order of array
110
105
104
101
100
85
80
77
70
66
S.S.V.P. Sanstha’s
L.K.Dr.P.R.Ghogrey Science College, Dhule
Department of Computer Science
Sub:- VB.NET
Roll No : Date:
Name :-
Assignment No- 2)Write a Window based application to find the maximum of 3 numbers

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles Button1.Click
Dim str, str1, str2 As String
Dim a, b, c As Integer
str = InputBox("enter value of a")
a = CInt(str)
str1 = InputBox("enter value of b")
b = CInt(str1)
str2 = InputBox("enter value of c")
c = CInt(str2)
If (a > b) Then
If (a > c) Then
MsgBox("a is greater")
Else
MsgBox("c is greater")

End If
Else
If (b > c) Then
MsgBox("b is greater")
Else
MsgBox("c is greater")

End If
End If
End Sub
End Class
S.S.V.P. Sanstha’s
L.K.Dr.P.R.Ghogrey Science College, Dhule
Department of Computer Science
Sub:- VB.NET
Roll No : Date:
Name :-
Assignment No- 3)Write a Window based application to find Factorial of given no.

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


As System.EventArgs) Handles Button1.Click
Dim str As String
Dim num, fact, cnt As Integer
fact = 1
str = InputBox("Enter number for factorial")
num = CInt(str)
For cnt = 1 To num
fact = fact * cnt
Next
MsgBox("Factorial = " & fact)
End Sub
S.S.V.P. Sanstha’s
L.K.Dr.P.R.Ghogrey Science College, Dhule
Department of Computer Science
Sub:- VB.NET
Roll No : Date:
Name :-
Assignment No- 4)Write a Window based application to check given no. is Armstrong no?

Public Class Form1


Dim str As String
Dim num As Integer
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
'Dim str As String
'Dim num As Integer
str = InputBox("Enter No")
num = CInt(str)
Call Armstrong(num)
End Sub
Public Sub Armstrong(ByVal no As Integer)
Dim rem1 As Integer
Dim res As Integer
Dim temp As Integer
res = 0
temp = no
While (no > 0)
rem1 = no Mod 10
res = res + (rem1 ^ 3)
no = no \ 10
End While
If (temp = res) Then
MsgBox("No is Armstrong")
Else
MsgBox("No is not Armstrong")
End If
End Sub
End Class
S.S.V.P. Sanstha’s
L.K.Dr.P.R.Ghogrey Science College, Dhule
Department of Computer Science
Sub:- VB.NET
Roll No : Date:
Name :- :-
Assignment No- 5)Write a VB.Net Program to demonstrate exception Handling

Module Module1
sub division(byval num1 as integer,byval num2 as integer)
dim result as integer
try
result=num1\num2
catch e as dividebyzeroexception
console.writeline("exception caught:{0}",e)
finally
console.writeline("result:{0}",result)
end try
end sub

Sub Main()
division(25, 0)
console.readkey()
End Sub

End Module

‘output

exception caught:System.DivideByZeroException: Attempted to divide by zero.

at ConsoleApplication4.Module1.division(Int32 num1, Int32 num2) in C:\Documen

ts and Settings\SSVPS\My Documents\Visual Studio 2005\Projects\ConsoleApplicatio

n4\ConsoleApplication4\exe1.vb:line 5

result:0
S.S.V.P. Sanstha’s
L.K.Dr.P.R.Ghogrey Science College, Dhule
Department of Computer Science
Sub:- VB.NET
Roll No : Date:
Name :- :-
Assignment No- 7)Write a VB.Net Program to demonstrate Single Inheritance(GCD)

Module Module1
Class base
Public a, b As Integer
Public Sub getno()
Console.WriteLine("enter any two no")
a = CInt(Console.ReadLine())
b = CInt(Console.ReadLine())
End Sub
End Class
Class derived
Inherits base
Public Sub calgcd()
While a <> b
If a > b Then
a = a - b
Else
b = b - a
End If
End While
Console.WriteLine("gcd=" & a)
End Sub
End Class

Sub Main()
Dim c As New derived()
c.getno()
c.calgcd()
Console.ReadKey()

End Sub

End Module

‘Output

enter any two no

15

gcd=3
S.S.V.P. Sanstha’s
L.K.Dr.P.R.Ghogrey Science College, Dhule
Department of Computer Science
Sub:- VB.NET
Roll No : Date:
Name :-
Assignment No- 8) VB.Net Program to demonstrate Interface

Module Module1
'create interface
Public Interface i1
Sub print1()

End Interface
Public Interface i2
Sub print2()

End Interface
'create derived class
Public Class class1
Implements i1, i2
Public Sub print1() Implements i1.print1
console.writeline("Interface 1 is calling")

End Sub
Public Sub print2() Implements i2.print2
console.writeline("Interface 2 is calling")

End Sub
Public Sub print3()
console.writeline("class 1 is calling")

End Sub
End Class

Sub Main()
Dim c1 As New class1()

c1.print1()
c1.print2()
c1.print3()
Console.ReadKey()

End Sub

End Module

‘Output

Interface 1 is calling

Interface 2 is calling

class 1 is calling
S.S.V.P. Sanstha’s
L.K.Dr.P.R.Ghogrey Science College, Dhule
Department of Computer Science
Sub:- VB.NET
Roll No : Date:
Name :-
Assignment No- 9) VB.Net Program to demonstrate Polymorphism

Module Module1

Class employ

Public Overridable Sub work()

Console.WriteLine("I am an employee")

End Sub

End Class

Class manager

Inherits employ

Public Overrides Sub work()

Console.WriteLine("I am a manager")

End Sub

End Class

Sub Main()

Dim e1 As New employ()

e1.work()

e1 = New manager()

e1.work()

Console.ReadKey()

End Sub

End Module

'output

I am an employee

I am a manager

S.S.V.P. Sanstha’s
L.K.Dr.P.R.Ghogrey Science College, Dhule
Department of Computer Science
Sub:- VB.NET
Module Module1
Public Class sample
Private a As Integer
Public Sub New(ByVal setval As Integer)
a = setval
End Sub
Public Function display()
Return a
End Function
End Class
Sub Main()
Dim test As New sample(5)
Console.WriteLine("Value of a is initialized to:")
Console.WriteLine(test.display())
Console.ReadLine()
End Sub
End Module

Output :-

Value of a is initialized to:

You might also like