//1. Area of different shapes using Abstract class in VB.
NET
Module Module1
MustInherit Class shape
Public MustOverride Function area()
End Class
Class square : Inherits shape
Public Overrides Function area()
Dim s As Integer
Dim area_sq As Integer
Console.WriteLine("Enter the value of s(side)")
s = Convert.ToInt32(Console.ReadLine)
area_sq = s * s
Console.WriteLine("Area of square withe side value={0} is {1}", s,
area_sq)
End Function
End Class
Class rectangle : Inherits shape
Public Overrides Function area()
Dim l, b As Integer
Dim area_rect As Integer
Console.WriteLine("Enter the value of length and breadth")
l = Convert.ToInt32(Console.ReadLine)
b = Convert.ToInt32(Console.ReadLine)
area_rect = l * b
Console.WriteLine("Area of rectange with length= {0} and breadth={1}
is{2}", l, b, area_rect)
End Function
End Class
Sub Main()
Dim s As shape
s = New square
s.area()
s = New rectangle
s.area()
Console.ReadKey()
End Sub
End Module
Output
Enter the value of s(side)
12
Area of square withe side value=12 is 144
Enter the value of length and breadth
22
3
Area of rectange with length= 22 and breadth=3 is 66
//2. Simple and Compound Interest using Abstract Class
Module Module1
MustInherit Class interest
Protected p, n, r As Single
Public MustOverride Function intr()
End Class
Class Simpleinterest : Inherits interest
Dim si As Single
Public Overrides Function intr()
Console.WriteLine("Enter the values of p,n r")
p = Convert.ToSingle(Console.ReadLine)
n = Convert.ToSingle(Console.ReadLine)
r = Convert.ToSingle(Console.ReadLine)
si = (p * n * r) / 100
Console.WriteLine("Simple Interest={0}", si)
End Function
End Class
Class compoundinterest : Inherits interest
Dim ci As Single
Public Overrides Function intr()
Console.WriteLine("Enter the values of p,n r")
p = Convert.ToSingle(Console.ReadLine)
n = Convert.ToSingle(Console.ReadLine)
r = Convert.ToSingle(Console.ReadLine)
ci = p * (1 + (r / 100) ^ n)
Console.WriteLine("Compound Interest={0}", ci)
End Function
End Class
Sub Main()
Dim s As interest
s = New Simpleinterest
s.intr()
s = New compoundinterest
s.intr()
Console.ReadKey()
End Sub
End Module
Output
Enter the values of p,n r
1000
2
3
Simple Interest=60
Enter the values of p,n r
1000
2
5
Compound Interest=1002.5