Sie sind auf Seite 1von 7

LPU

ASSIGNMENT
NO2 OF
MODERN
PROGRAMMING
TOOLS &
TECHNIQUES III
SUBMITTED TO SUBMITTED BY

DEEPAK MEHTA VARUN KATOCH

E3801B53
BCA-MCA

Q1. Create a program to sort the elements in ascending and descending order
that is entered by the user.

Ans 1

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


System.EventArgs) Handles Button1.Click

Dim num1, num2, num3 As Integer

num1 = TextBox1.Text

num2 = TextBox2.Text

num3 = TextBox3.Text

Q2 Create a program that displays factorial of a number which is entered by the


user using user defined function.
ANS:- Module Module1

Sub Main()
Dim fact As Integer
Dim num As Integer
Dim i As Integer
fact = 1
num = 5
For i = 1 To 5
fact = fact * i
Next
Console.WriteLine("the factorial is:"& fact)
Console.ReadLine()
End Sub

End Module

Q3 Create a program that implements the following operation:


(i)To find the length of a string
Ans:- Module Module1
Sub main()
Dim abc As String
Console.WriteLine("enter a string")
abc = Console.ReadLine
Dim a As Integer
a = abc.Length
Console.WriteLine("length of string entered=" & a)
Console.ReadLine()

End Sub

End Module

(ii)To find the indexof of the nth position of the string


Ans:- Module Module1
Sub main()
Dim str As String
str = "VB.NET TOP 10 BOOKS"
MsgBox(str.IndexOf("BOOKS"))
End Sub

End Module
(iii) To split the string using a character.
Ans:- Module Module1
Sub main()
Dim str As String
Dim strArr() As String
Dim count As Integer
str = "vb.net split test"
strArr = str.Split(" ")
For count = 0 To strArr.Length - 1
MsgBox(strArr(count))
Next

End Sub

End Module
(iv) To use the endswith for a string
Ans:- Module Module1
Sub main()
Dim str As String
str = "VB.NET TOP 10 BOOKS"
If str.EndsWith("BOOKS") = True Then
MsgBox("The String EndsWith 'BOOKS' ")
Else
MsgBox("The String does not EndsWith 'BOOKS'")
End If

End Sub

End Module

Q4 Write a Program that implements Date and Time Functions, string &
mathematical functions
Ans:- Module tester

Public Sub Main()


Dim sDate As String = "8/1/86"
Dim dtDate As Date = CDate(sDate)
sDate = "Tuesday,September16,18456:45pm"
dtDate = CDate(sDate)
Console.WriteLine("Datenowholds{0}", dtDate)
End Sub

End Module

Q5. Create a program using class room with following:


Height, length, breadth data field as integer type
area( ) and volume( ) function are used to calculate the area and volume of the
room
ans:- area of the room
Module area_of_room
Function room(ByVal l As Integer, ByVal b As Integer)
Dim area As Single
area = l * b
Return area
End Function
Sub Main()
Dim a, l, b As Single
Console.WriteLine("enter the length:")
l = Console.ReadLine
Console.WriteLine("enter the breadth:")
b = Console.ReadLine
a=l*b
Console.WriteLine("area_of_room=" & a)
Console.ReadLine()
End Sub

End Module
Volume of the room
Module volume_of_room
Function room(ByVal l As Integer, ByVal b As Integer, ByVal h As Integer)
Dim volume As Single
volume = l * b * h
Return volume
End Function
Sub Main()
Dim v, l, b, h As Single
Console.WriteLine("enter the length:")
l = Console.ReadLine
Console.WriteLine("enter the breadth:")
b = Console.ReadLine
Console.WriteLine("enter the height:")
h = Console.ReadLine
v=l*b*h
Console.WriteLine("volume_of_room=" & v)
Console.ReadLine()
End Sub

End Module

Q6. Create a program that implements inheritance using an employee base


class and manager derived class. You can use any data and methods for
compilation of the inheritance.
Module Module1

Public Class Employee


Private pName As String
Private pID As String
Private pDept As String
Private pSalary As Decimal
Private pPay As Decimal = 0D
Public Sub New(ByVal initName As String, ByVal initID As String,
ByVal initDept As String, ByVal initSalary As Decimal)
pName = initName
pID = initID
pDept = initDept
pSalary = initSalary
End Sub
Public Property Name() As String
Get
Return pName
End Get
Set(ByVal Value As String)
pName = Value
End Set
End Property
Public Property ID() As String
Get
Return pID
End Get
Set(ByVal Value As String)
pID = Value
End Set
End Property
Public Property Dept() As String
Get
Return pDept
End Get
Set(ByVal Value As String)
pDept = Value
End Set
End Property
Public Property Salary() As Decimal
Get
Return pSalary
End Get
Set(ByVal Value As Decimal)
pSalary = Value
End Set
End Property
Public Property Pay() As Decimal
Get
Return pPay
End Get
Set(ByVal Value As Decimal)
pPay = Value
End Set
End Property
Public Overridable Function calcPay(ByVal hours As Integer) _
As Decimal
Return pSalary * hours
End Function
Public Overridable Sub Display()
Console.WriteLine("Name: " & pName)
Console.WriteLine("ID: " & pID)
Console.WriteLine("Dept: " & pDept)
Console.WriteLine("Salary: " & FormatNumber(pSalary, 2))
Console.WriteLine("Pay: " & FormatNumber(pPay, 2))
End Sub
End Class

End Module

Das könnte Ihnen auch gefallen