Você está na página 1de 41

PRACTICAL FILE

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

Assistant Professor VSIT


08617702015

VIVEKANANDA INSTITUTE OF
PROFESSIONAL STUDIES
NITISH AHLAWAT
BCA-(III-B)

08617702015

G.G.S.I.P. University of Professional Studies


(Batch: 2015 - 2018)

INDEX
Sno
1

PROGRAM

WAP for different operators


(comparison,numeric,logical,
bitwise)

WAP to develop a calculator


using selected case

WAP to check whether the


number is prime or not using
while loop

WAP to print the power of a


no. to b using while loop

WAP sub procedure in .net to


swap two numbers by
passing parameters by val
and by ref
Write a function procedure to
find the largest among three
numbers

TEACHERS
SIGNATURE

WAP to check the divisibility


of a no. by 2,3,and 5 using
nested if

Write a program to find


largest and smallest in 1-d
array

Write a program to add


matrixs

10

Write a program to multiply


two matrices

11

Write a program to
implement jagged array

NITISH AHLAWAT
BCA-(III-B)

08617702015

12

Write a program for


structures AND
enumerations in vb.net

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

Write a program to build a


class which implements an
interface

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

forecolour property of the


form
Fill a combo box with various
items, get the selected items
in the combo box and show
them in a list box and sort
the items. Drag and drop a
combo box to store the
items, a list box to display
the selected items, four
button controls to add to the
list box with selected
items,to fill the combo box ,
to sort the items and to clear
the combo box list, resp.
Write a program in vb,net to
show the use of listview
control and tree view control

27

Write a program in vb.net to


show the use of timer
control, picture box and scroll
bars
Write a program in vb.net for
MDI form and menus

28

Wap in vb.net to create a


custom control

29

Wap in vb.net to insert


,delete ,update and select
data using SQLDB

30

WAP in vb.net to insert ,


delete, update and select
data using OLEDB

31

Build a crystal report in


vb.net. modify ,publish and
export it

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

Q2. Write a program for different Operators (Arithmetic, Comparison, Logical,


Bitwise)
Ans..
Module Module1

Sub Main()
Console.WriteLine("AKSHAT GUPTA

35317702015")

Dim num1, num2, num3 As Integer


Dim exp1, exp2, exp3 As Boolean
Console.WriteLine("Enter first operand : ")
num1 = Console.ReadLine()
Console.WriteLine("Enter second operand : ")
num2 = Console.ReadLine()
Console.WriteLine("---- ARITHEMETIC OPERATORS ----")
Console.WriteLine(" ^ operator : " & num1 & " ^ " & num2 & " = " & num1 ^ num2)
Console.WriteLine(" + operator : " & num1 & " + " & num2 & " = " & num1 + num2)
Console.WriteLine(" - operator : " & num1 & " - " & num2 & " = " & num1 - num2)
Console.WriteLine(" * operator : " & num1 & " * " & num2 & " = " & num1 * num2)
Console.WriteLine(" / operator : " & num1 & " / " & num2 & " = " & num1 / num2)
Console.WriteLine(" \ operator : " & num1 & " \ " & num2 & " = " & num1 \ num2)

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

Console.WriteLine("---- BIT SHIFT OPERATORS ----")


num3 = num1 << 2
Console.WriteLine(" << operator : " & num1 & " << 2 = " & num3)
num3 = num1 >> 2
Console.WriteLine(" >> operator : " & num1 & " >> 2 = " & num3)
Console.ReadKey()
End Sub

End Module

OUTPUT

NITISH AHLAWAT
BCA-(III-B)

08617702015

Q3. Write a program to implement calculator using switch.


Ans..
Module Module1
Sub Main()
Dim a, b, c As Integer
Console.WriteLine("AKSHAT GUPTA 35317702015")
Console.WriteLine("1. addition 2.multiplication 3.subtraction 4.division")
Console.WriteLine("Enter your choice")
a = Console.ReadLine()
Select Case a
Case 1
Console.WriteLine("Enter the digits")
b = Console.ReadLine()
c = Console.ReadLine()
Console.WriteLine(b + c)
Case 2
Console.WriteLine("Enter the digits")
b = Console.ReadLine()
NITISH AHLAWAT
BCA-(III-B)

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

Q 5. WAP number a raised to the power b.


Ans..
Module Module1
Sub main()
Console.WriteLine("AKSHAT GUPTA 35317702015")
Dim base As Integer
Dim power As Integer
Dim answer As Integer
Console.WriteLine("enter base and power")
base = Integer.Parse(Console.ReadLine())
power = Integer.Parse(Console.ReadLine())
While base > 0
answer = base ^ power
Console.WriteLine(answer)
base = 0
End While

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

Function greatest(ByVal x As Integer, ByVal y As Integer, ByVal z As Integer) As Integer


If x > y And x > z Then
Return x
ElseIf y > z Then
Return y
Else
Return z
End If
End Function
Sub Main()
Console.WriteLine("AKSHAT GUPTA 35317702015")
Console.WriteLine("enter three numbers")
Dim a As Integer = Integer.Parse(Console.ReadLine())
Dim b As Integer = Integer.Parse(Console.ReadLine())
Dim c As Integer = Integer.Parse(Console.ReadLine())
Console.WriteLine("greatest number is " & greatest(a, b, c))
End Sub
End Module
OUTPUT

Q8.WAP to find smallest and the greatest no. in 1 d array.


Ans..

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

Q9. Write a program to add two matrices.

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

Q10. WAP to Multiply 2 matrices.


Ans..
Module Module1
Sub Main()
Console.WriteLine("AKSHAT GUPTA 35317702015")
Dim matrix1(2, 2) As Integer, matrix2(2, 2) As Integer
Dim i As Integer, j As Integer
Dim k As Integer, temp As Integer = 0
Console.WriteLine("Please Input the values for matrix_1")
For i = 0 To 2
For j = 0 To 2
matrix1(i, j) = Integer.Parse(Console.ReadLine())
Next
Next
Console.WriteLine("Please Input the values for matrix_2")
For i = 0 To 2
For j = 0 To 2
matrix2(i, j) = Integer.Parse(Console.ReadLine())
Next
Next
Console.WriteLine("Matrix 1 ::")
For i = 0 To 2
For j = 0 To 2
Console.WriteLine(matrix1(i, j))
Console.WriteLine(" ")
Next
Next
Console.WriteLine("Matrix 2 ::")
For i = 0 To 2
For j = 0 To 2
Console.WriteLine(matrix2(i, j))
Console.WriteLine(" ")
Next
Next
Console.WriteLine("Product of Matrix_1 & Matrix_2 is ::")
For i = 0 To 2
For j = 0 To 2
For k = 0 To 2
temp = temp + (matrix1(i, k) * matrix2(k, j))
Next
Console.WriteLine(temp)
temp = 0
Next

NITISH AHLAWAT
BCA-(III-B)

08617702015

Next
End Sub
End Module

OUTPUT

NITISH AHLAWAT
BCA-(III-B)

08617702015

NITISH AHLAWAT
BCA-(III-B)

08617702015

Q 11 WAP to implement jagged array.


Ans..
Module Module1
Sub Main()
Dim size As Integer
Dim arr()() As Integer = New Integer(3)() {}
Console.WriteLine("AKSHAT GUPTA 35317702015")
For x As Integer = 0 To 3
Console.WriteLine("Enter columns for " & x & " row")
size = Integer.Parse(Console.ReadLine())
arr(x) = New Integer(size) {}
Next
For i As Integer = 0 To arr.GetUpperBound(0)
Console.WriteLine("Enter " &arr(i).GetUpperBound(0) & " values ")
For j As Integer = 1 To arr(i).GetUpperBound(0)
arr(i)(j) = Integer.Parse(Console.ReadLine())
Next
Next
For i As Integer = 0 To arr.GetUpperBound(0)
For j As Integer = 1 To arr(i).GetUpperBound(0)
Console.Write(arr(i)(j) &vbTab)
Next
Console.WriteLine()
Console.WriteLine()
Next
End Sub
End Module
OUTPUT

NITISH AHLAWAT
BCA-(III-B)

08617702015

Q13. WAP to demonstrate polymorphism in VB.Net through method overloading and


constructor overloading,
Ans..
Module Module1
Sub area(ByVal side As Integer)
Dim area As Integer
area = side * side
Console.WriteLine("Area of Square : " & area)
End Sub Dim area As Integer
area = l * b
Console.WriteLine("Area of Rectangle : " & area)
End Sub
Sub area(ByVal r As Double)
Dim area As Double
area = 4.13 * r * r
Console.WriteLine("Area of Circle : " & area)
End Sub
Sub Main()
Console.WriteLine(vibhor ahuja)
Dim l, b, ch As Integer
Dim r As Double
Console.WriteLine("1. Area of a Square")
Console.WriteLine("2. Area of a Rectange")
Console.WriteLine("3. Area of a Circle")
Console.WriteLine("Enter Your Choice : ")
ch = Integer.Parse(Console.ReadLine())
Select Case ch
Case 1
Write("Enter Size of a side : ")
l = Integer.Parse(Console.ReadLine())

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

Q14. Write a program for constructors in vb.net.


Ans..
Module Module1
Class Employee
Public Empname As String
Public Empid As Integer
Public Basic_sal As Integer
Public DA As Integer
Public TA As Integer
Sub New()
Empname = ""
Empid = "1300"
Basic_sal = "20,000"
DA = (20 * 20000) / 100
TA = (10 * 20000) / 100
End Sub
Protected Overrides Sub finalize()
Console.WriteLine("Object has been destroyed")
End Sub
Public Sub getdata()
Console.WriteLine("AKSHAT GUPTA 35317702015")
Console.WriteLine("Enter Employee Name")
Empname = Console.ReadLine()
Console.WriteLine("Enter Employee id")
Empid = Integer.Parse(Console.ReadLine())
Console.WriteLine("Enter Basic_sal")
Basic_sal = Decimal.Parse(Console.ReadLine())
End Sub

NITISH AHLAWAT
BCA-(III-B)

08617702015

Public Sub showdata()


Console.WriteLine("Employee name = " &Empname)
Console.WriteLine("Employee id = " &Empid)
Console.WriteLine("Basic_sal = " &Basic_sal)
Basic_sal = Basic_sal + DA + TA
Console.WriteLine("Da
= " & DA)
Console.WriteLine("TA
= " & TA)
End Sub
End Class
Sub Main()
Dim emp As New Employee
emp.getdata()
emp.showdata()
End Sub
End Module

NITISH AHLAWAT
BCA-(III-B)

08617702015

OUTPUT

NITISH AHLAWAT
BCA-(III-B)

08617702015

Q15. Write a program to show the concept of inheritance .


Ans..
Module Module1
Class add
Protected a As Integer
Protected b As Integer
Protected c As Integer
Public Sub seta(ByVal x As Integer)
a=x
End Sub
Public Sub setb(ByVal y As Integer)
b=y
End Sub
End Class
Class sum : Inherits add
Public Function getsum() As Integer
Return (a + b)
End Function
End Class
Sub Main()
Dim a As New sum
Console.WriteLine("AKSHAT GUPTA
35317702015")
a.seta(14)
a.setb(12)
Console.WriteLine("Sum is:{0}", a.getsum())
End Sub
End Module
OUTPUT

NITISH AHLAWAT
BCA-(III-B)

08617702015

16. (a)Write a program for Structured exception.


(b)Write a program for unstructured exception.

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

(b) Unstructured exception.


Module Module1
Dim division As Integer
Sub Main()
Dim a, b, c As Integer
Console.WriteLine("AKSHAT GUPTA
35317702015")
Console.WriteLine("Enter a and b")
On Error Resume Next
a = Integer.Parse(Console.ReadLine())
b = Integer.Parse(Console.ReadLine())
c=a/b
Console.WriteLine("Division =" & c)
On Error Resume Next
If c <= 0 Then
Console.WriteLine("exception occured")
End If
End Sub
End Module
OUTPUT

NITISH AHLAWAT
BCA-(III-B)

08617702015

Q17) WAP to demonstrate overriding in vb.Net.


Ans..
Module Module1
Class over
Public Overridable Function add(ByVal x As Integer, ByVal y As Integer)
Console.WriteLine("function inside base class")
Return (x + y)
End Function
End Class
Class Derover
Inherits over
Public Overrides Function add(ByVal X As Integer, ByVal y As Integer)
Console.WriteLine(MyBase.add(120, 100))
Console.WriteLine("function inside derived class")
Console.WriteLine("function overridden")
Return (X + y)
End Function
End Class
Sub Main()
Console.WriteLine(AKSHAT GUPTA 35317702015)
Dim obj As New Derover
Console.WriteLine(obj.add(10, 100))
Console.Read()
End Sub
End Module
OUTPUT

NITISH AHLAWAT
BCA-(III-B)

08617702015

18. Write a program to show the concept of Must inherit.


Ans..
Module Module1
MustInherit Class page
Public Function number() As Integer
Return 10
End Function
MustOverride Sub size()
End Class
Class textpage : Inherits page
Overrides Sub size()
Console.WriteLine("AKSHAT GUPTA 35317702015")
Console.WriteLine("Size of page is a4")
End Sub
End Class
Sub main()
Dim t As textpage = New textpage
t.size()
Console.WriteLine(t.number())
End Sub
End Module
OUTPUT

NITISH AHLAWAT
BCA-(III-B)

08617702015

Q19. Write a program for Procedure overloading.


Ans..
Module Module1
Class student
Dim rollno As Integer
Dim name As String
Dim marks As Integer
Sub sum(ByVal x As Integer, ByVal y As String, ByVal z As Integer)
rollno = x
name = y
marks = z
End Sub
Sub sum(ByVal a As Integer, ByVal b As Integer, ByVal c As String)
rollno = a
marks = b
name = c
End Sub
Sub showdata(ByVal name As String, ByValrollno As Integer, ByVal marks As Integer)
Console.WriteLine("Rollno=" &rollno)
Console.WriteLine("Name=" & name)
Console.WriteLine("Marks=" & marks)
End Sub
End Class
Sub Main()
Dim R, M As Integer
Dim N As String
Dim s1 As New student
Console.WriteLine("AKSHAT GUPTA 35317702015")
Console.WriteLine("Enter Rollno")
R = Integer.Parse(Console.ReadLine())
Console.WriteLine("Enter Name")
N = Console.ReadLine()
Console.WriteLine("Enter Marks")
M = Integer.Parse(Console.ReadLine())
s1.showdata(N, R, M)
End Sub
End Module

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

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


System.EventArgs) Handles Button4.Click
Dim a, b, r As Double
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
r=a/b
TextBox3.Text = r
End Sub
End Class

OUTPUT

NITISH AHLAWAT
BCA-(III-B)

08617702015

NITISH AHLAWAT
BCA-(III-B)

08617702015

Você também pode gostar