HW 2
HW 2
PART – A
Q 1. Design a window based application in vb.net to implement Left(),
type conversion, weekday(), datediff() built in functions on a form?
Ans:-
Using weekday() inbuilt function:-
’Declare variable
Dim dteResults As Date
’Get the current date and time
dteResults = Now
MessageBox.Show("Weekday name: " & dteResults.ToString("dddd"), _
"Date Demo")
MessageBox.Show("Month name: " & dteResults.ToString("MMMM"), _
"Date Demo")
End Sub
End Class
Q 2. Create a console based application in vb.net to generate electricity bill by
reading details of customer like name, meter no, units consumed in a class
as member variables and use functions with object to input, compute and
display the bill?
Ans:-
Module Module1
Class test
Dim name As String
Dim met, units, bill, rate As Integer
Sub input()
Console.WriteLine("enter the name of customer")
name = Console.ReadLine()
Console.WriteLine("enter the meter no.")
met = Console.ReadLine()
Console.WriteLine("enter the units consumed by customer")
units = Console.ReadLine()
Console.WriteLine("enter the Rs. per unit")
rate = Console.ReadLine()
End Sub
Function compute() As Integer
Return units * rate
End Function
Sub display()
Console.WriteLine("the name of customer is{0}", name)
Console.WriteLine("meter no. is{0}", met)
Console.WriteLine("units consumed are{0}", units)
Console.WriteLine("the bill is{0}", units * rate)
End Sub
End Class
Sub Main()
Dim t As test
t = New test()
t.input()
t.compute()
t.display()
Console.ReadKey()
End Sub
End Module
PART – B
Q 1. Create a console based application in vb.net to generate pay slip of an
employee by reading details like name, desig, basicsal, hra, pf in one class
and inherits these to perform operation of calculating netsalary, gross salary
in other class and display the same?
Ans:-
Public Class detail
Public name, desig As String
Public basicsal, netsal, grossal As Integer
Sub input()
Console.WriteLine("enter the name of employee")
name = Console.ReadLine()
Console.WriteLine("enter the designation")
desig = Console.ReadLine()
Console.WriteLine("enter the basic salary of employee")
basicsal = Console.ReadLine()
End Sub
Sub display()
Console.WriteLine("the name of employee is{0}", name)
Console.WriteLine("dsignation is{0}", desig)
Console.WriteLine("basic salary is{0}", basicsal)
Console.WriteLine("net salary is{0}", basicsal / 2)
Console.WriteLine("gross salary is{0}", basicsal / 4)
End Sub
End Class
Public Class detail2
Inherits detail
Public Function netsalary() As Integer
Return basicsal / 2
End Function
Public Function grossalary() As Integer
Return basicsal / 4
End Function
End Class
Module Module1
Sub Main()
Dim obj As detail2
obj = New detail2()
obj.input()
obj.netsalary()
obj.grossalary()
obj.display()
Console.ReadKey()
End Sub
End Module
Ans:-
Global variables:-
Public Class one
'base class
Public I As Integer = 10
Public j As Integer = 20
Public Function add() As Integer
Return i + j
End Function
End Class
Module module1
Sub main()
Dim ss As New two()
Console.WriteLine(ss.sum())
Console.ReadKey()
End Sub
End Module
Local variables:-
Module Module1
Class test
Function disp(ByVal x As Integer, ByVal y As Integer) As Integer
Return x + y
End Function
End Class
Sub Main()
Dim num1, num2, num3 As Integer
num1 = 5
num2 = 10
Dim obj As test
obj = New test()
num3 = obj.disp(num1, num2)
Console.WriteLine("the value of num3 is{0}", num3)
Console.ReadKey()
End Sub
End Module