Imports Sub Dim As New: Using Classes and Procedures

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

USING CLASSES AND PROCEDURES

Imports System.Console
Module Module1

Sub Main()
Dim obj As New student()
obj.getentry()
obj.calculate()
obj.display()
Read()
End Sub
Public Class student
Dim r As Integer
Dim n As String
Dim m1,m2 As Integer
Dim tot As Integer
Dim avg As Double
Sub getentry()
Write("enter the regno")
r = Val(ReadLine())
Write("enter the name")
n = ReadLine()
Write("enter the mark1")
m1 = Val(ReadLine())
Write("enter the mark2")
m2 = Val(ReadLine())
End Sub
Sub calculate()
tot = m1 + m2
avg = tot / 2
End Sub
Sub display()
WriteLine("NAME:" & n)
WriteLine("REGNO:" & r)
WriteLine("MARK1:" & m1)
WriteLine("MARK2:" & m2)
WriteLine("TOTAL:" & tot)
WriteLine("AVERAGE:" & avg)
End Sub
End Class
End Module

USING ARRAYS

Imports System.Console
Module Module1

Sub Main()
Dim obj As New student()
Dim num As Integer
WriteLine("enter number of students")
num = Val(ReadLine())
obj.getentry(num)
obj.calculate()
obj.display()
Read()
End Sub
Public Class student
Dim r(10) As Integer
Dim n(10) As String
Dim m1(10), m2(10) As Integer
Dim tot(10) As Integer
Dim avg(10) As Double
Dim i As Integer
Dim nn As Integer
Sub getentry(ByVal nnn As Integer)
nn = nnn
For i = 0 To nn
WriteLine("enter the regno")
r(i) = Val(ReadLine())
WriteLine("enter the name")
n(i) = ReadLine()
WriteLine("enter the mark1")
m1(i) = Val(ReadLine())
WriteLine("enter the mark2")
m2(i) = Val(ReadLine())
Next i
End Sub
Sub calculate()
For i = 0 To nn

tot(i) = m1(i) + m2(i)


avg(i) = tot(i) / 2
Next i
End Sub
Sub display()
For i = 0 To nn
WriteLine("STUDENT" & (i + 1) & "MARK
DETAILS")
WriteLine("NAME:" & n(i))
WriteLine("REGNO:" & r(i))
WriteLine("MARK1:" & m1(i))
WriteLine("MARK2:" & m2(i))
WriteLine("TOTAL:" & tot(i))
WriteLine("AVERAGE:" & avg(i))
Next i
End Sub
End Class

End Module
USING STRUCTURES AND FUNCTIONS

Imports System.Console
Module Module1

Structure product
Dim pno As Integer
Dim pname As String
Dim qty As Integer
Dim cost As Integer
Public Function calculate(ByVal pno, ByVal
pname, ByVal qty) As Integer
If (pname = "soap") Then
Return (26 * qty)
Else
Return (0)
End If
End Function
End Structure
Sub Main()
Dim p As New product()
Dim n As Integer
WriteLine("enter the product no:")
p.pno = Val(ReadLine())
WriteLine("enter the product name:")
p.pname = ReadLine()
WriteLine("enter the product quantity:")
p.qty = Val(ReadLine())
n = p.calculate(p.pno, p.pname, p.qty)
WriteLine("Amount" & n)
Read()
End Sub

End Module
USING STRUCTURE, FUNCTION AND ARRAYS

Imports System.Console
Module Module1
Public pno(,) As Integer
Public pname() As String
Structure product

Dim i As Integer
Dim j As Integer

Dim cost As Integer


Dim amt As Integer
End Structure
Public Function calculate(ByVal n As Integer)
Dim u As New product()
Dim id(10), qty(10) As Integer
u.amt = 0
u.j = 0
For i = 0 To n - 1
WriteLine("enter the" & i + 1 & " product
id")
id(i) = Val(ReadLine())
WriteLine("enter the" & i + 1 & "
quantity")
qty(i) = Val(ReadLine())
Next i
For j = 0 To n - 1
For i = 0 To 2

If (id(j) = pno(i, 0)) Then


u.cost = pno(i, 1)
u.amt = u.amt + u.cost * qty(j)
End If

Next i
Next j
Return (u.amt)
End Function

Sub Main()

Dim i, j As Integer
Dim n, tot As Integer
Dim p As New product()
pname = New String() {"soap", "horlicks",
"biscut"}
pno = New Integer(,) {{1, 23}, {2, 90}, {3,
12}}
WriteLine("--------------------------")
WriteLine("KANNAN DEPARTMENTAL STORE")
WriteLine("--------------------------")
WriteLine("PNO COST PNAME")
WriteLine("--------------------------")

For i = 0 To 2
For j = 0 To 1
Write(" " & pno(i, j))
Write(" ")
Next j
WriteLine(" " & pname(i))
Next i
WriteLine("--------------------------")
WriteLine("ENTER THE NO.OF.PRODUCTS")
n = Val(ReadLine())
tot = calculate(n)
MsgBox("u need to pay" & tot)
Read()
End Sub
End Module

ABSTRACT CLASS

Imports System.Console
Module Module1
Public MustInherit Class AbstractClass
Public MustOverride Function Add()
Public MustOverride Function Mul()
End Class

Public Class absone


Inherits AbstractClass
Dim i As Integer = 20
Dim j As Integer = 30
Public Overrides Function Add()
Return i + j
End Function
Public Overrides Function Mul()
Return i * j

End Function
End Class
Sub Main()
Dim abs As New absone
WriteLine("sum is" & abs.Add())
WriteLine("multiplication is" & abs.Mul())
Read()
End Sub
End Module

Calculating area using overloading


Imports System.Console
Module Module1

Sub Main()

Dim a As New area()


WriteLine("AREA OF SQUARE:" & a.compute(6))
WriteLine("AREA OF RECTANGLE:" & a.compute(5,
6))
WriteLine("AREA OF TRAPEZOID:" & a.compute(6,
6, 2.5))
Read()
End Sub
Public Class area
Dim t As Integer
Public Function compute(ByVal sq)
Return (sq * sq)
End Function
Public Function compute(ByVal l, ByVal b)
Return (l * b)
End Function
Public Function compute(ByVal a As Integer,
ByVal b As Integer, ByVal h As Double)
t = 0.5 * (a + b) * h
Return (t)
End Function
End Class
End Module

Inheritance concept for payroll


Imports System.Console
Module Module2
Sub main()
Dim ss As New payroll()
WriteLine("MANAGER SALARY:" & ss.calculate1())
WriteLine("PROGRAMMER SALARY:" & ss.program())
WriteLine("SOFTWARE TESTER SALARY:" &
ss.calculate2())
Read()
End Sub
Public Class employee
Public manager As Integer = 24000
Public prom As Integer = 16000
Dim hra, da, pf, it As Double
Dim np As Double
Public Function program()
hra = 0.02 * prom
da = 0.03 * prom
pf = 0.01 * prom
it = 0.02 * prom
np = (prom + hra + da) - (pf + it)
Return (np)
End Function

End Class
Public Class payroll
Inherits employee
Dim h, d As Double
Dim p, i, gp, np As Double
Public test As Integer = 16000
Public Function calculate1()
h = manager * 0.04
d = manager * 0.03
p = manager * 0.01
i = manager * 0.01
gp = (manager + h + d)
np = gp - (p + i)
Return (np)
End Function
Public Function calculate2()
Return (program())
End Function
End Class
End Module
OVERRIDING CONCEPT

Imports System.Console
Module Module3
Sub main()
Dim abs As New calculate1()
Dim a As Integer
Dim b As Integer
Dim n As Integer
WriteLine("choose ur category to purchase1.gold
2.silver")
n = Val(ReadLine())
If (n = 1) Then
WriteLine("Enter the no.of.grams")
a = Val(ReadLine())
WriteLine("total amount:" &
abs.goldrate(a))
Else
WriteLine("Enter the no.of.grams")
b = Val(ReadLine())
WriteLine("total amount:" & abs.silver(b))
End If
Read()
End Sub
Public MustInherit Class AbstractClass
Public MustOverride Function goldrate(ByVal a)
Public MustOverride Function silver(ByVal b)
Public g As Double = 1502.22
Public s As Double = 45.67
End Class

Public Class calculate1


Inherits AbstractClass
Dim rate As Double
Public Overrides Function goldrate(ByVal a)
rate = a * g
Return (rate)
End Function
Public Overrides Function silver(ByVal b)
rate = b * s
Return (rate)
End Function
End Class

End Module
STUDENT AND EMPLOYEE CALCULATION USING INTERFACE
Imports System.Console
Module Module5
Sub main()
Dim st As New student()
Dim e As New employee()
Dim v As Integer
WriteLine("enter 1.student details
2.employee")
v = Val(ReadLine())
If (v = 1) Then
st.getentry()
st.calculate()
Else
e.getentry()
e.calculate()
End If
Read()
End Sub
Public Interface test
Sub getentry()
Function calculate()
End Interface
Public Class student
Implements test
Dim s1 As String
Dim m1, m2, tot As Integer
Sub getentry() Implements test.getentry
WriteLine("enter the name")
s1 = ReadLine()
WriteLine("enter the mark1")
m1 = Val(ReadLine())
WriteLine("enter the mark2")
m2 = Val(ReadLine())

End Sub
Public Function calculate() Implements
test.calculate
tot = m1 + m2
WriteLine("Total" & tot)
Return (0)
End Function
End Class
Public Class employee
Implements test
Dim nam As String
Dim b, a, amt As Double
Public Function calculate() As Object
Implements test.calculate
amt = b + a
WriteLine("salary" & amt)
Return (0)
End Function

Public Sub getentry() Implements test.getentry


WriteLine("enter the name")
nam = ReadLine()
WriteLine("enter the basicpay")
b = Val(ReadLine())
WriteLine("enter the allowance")
a = Val(ReadLine())
End Sub
End Class
End Module
Delegates:
Module Module1
Public Delegate Sub mydelegate()
Public Delegate Sub mydelegate1(ByVal a As
Integer)
Public Sub msg()
Console.WriteLine("Program using
delegates")
End Sub
Public Sub sqrt(ByVal a As Integer)
Dim b As Integer
b = a * a
Console.WriteLine("Square of the
number:" & b)
End Sub

Sub Main()
Dim dlg As mydelegate
dlg = New mydelegate(AddressOf msg)
dlg.Invoke()
Dim dlg1 As mydelegate1
dlg1 = New mydelegate1(AddressOf sqrt)
dlg1.Invoke(10)
Console.Read()
End Sub

End Module
Threads:

Imports System.Threading
Module Module1

Sub Main()
Dim t As New Thread(AddressOf print)
t.Start()
Console.Read()
End Sub

Sub print()
Console.WriteLine("Program using
thread")
End Sub

End Module

You might also like