0% found this document useful (0 votes)
5 views27 pages

Lab Maunal Solutions-2

The document contains a series of VB.Net programming activities and exercises, ranging from simple console output to more complex input handling and control structures. It includes examples of variable declarations, data types, loops, conditionals, and user input/output. Each activity is accompanied by code snippets and expected outputs to illustrate the concepts being taught.

Uploaded by

pleasesorry179
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views27 pages

Lab Maunal Solutions-2

The document contains a series of VB.Net programming activities and exercises, ranging from simple console output to more complex input handling and control structures. It includes examples of variable declarations, data types, loops, conditionals, and user input/output. Each activity is accompanied by code snippets and expected outputs to illustrate the concepts being taught.

Uploaded by

pleasesorry179
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 27

Activity 2.

Imports System

Module Program
Sub Main()
Console.WriteLine("Programming is interesting")
End Sub
End Module

-------------------------------------------------------------------

Activity 2.2

Program:

Imports System

Module Program
Sub Main()
Dim message As String
Console.Write("Enter Message: ")
message = Console.ReadLine
Console.WriteLine()
Console.WriteLine("Your message: {0}", message)
Console.ReadLine()
End Sub
End Module

Output:

Enter Message: Learning VB.Net is Interesting.

Your message: Learning VB.Net is Interesting.

--------------------------------------------------------------------

Practice Exercise 2.1

1. Open Visual Studio and create a new VB.Net project by going to File > New >
Project.
2. Select the type of project you want to create (e.g., Console Application,
Windows Forms Application).
3. Write your VB.Net code in the editor window.
4. To compile the program, go to Build > Build Solution or simply press Ctrl +
Shift + B.
5. If there are no errors in your code, the program will be compiled successfully.
6. To execute the program, go to Debug > Start Debugging or press F5.
7. The program will run, and you will see the output in the Output window or the
console window, depending on the type of application you created.

-------------------------------------------------------------------

Practice Exercise 2.2

Imports System

Module Program
Sub Main()
Dim name, matric_no, email, address, hod_name, institution, phone As String
Dim d_o_b As Date

Console.Write("Enter Your Name: ")


name = Console.ReadLine()
Console.Write("Enter Your Date of Birth: ")
d_o_b = Console.ReadLine()
Console.Write("Enter Your Matriculation Number: ")
matric_no = Console.ReadLine()
Console.Write("Enter Your email address: ")
email = Console.ReadLine()
Console.Write("Enter Your Phone number: ")
phone = Console.ReadLine()
Console.Write("Enter Your address: ")
address = Console.ReadLine()
Console.Write("Enter Your HOD name: ")
hod_name = Console.ReadLine()
Console.Write("Enter Your Institution name: ")
institution = Console.ReadLine()
Console.ReadLine()
Console.WriteLine("Name : {0}", name)
Console.WriteLine("Matriculation Number : {0}", matric_no)
Console.WriteLine("Email address : {0}", email)
Console.WriteLine("Phone Number : {0}", phone)
Console.WriteLine("Address : {0}", address)
Console.WriteLine("Date of Birth : {0}", d_o_b)
Console.WriteLine("Head of Department : {0}", hod_name)
Console.WriteLine("Institution : {0}", institution)

End Sub
End Module

----------------------------------------------------------------------

Activity 3.1

Imports System

Module Program
Sub Main()
Dim si As Single
Dim dt As Date
Dim d As Double
Dim c As Char
Dim s As String
si = 0.12345678901234566
d = 0.12345678901234566
dt = Today
c = "U"
s = "VB.Net"
Console.Write(c & " and " & s & vbCrLf)
Console.WriteLine("declaring on the day of: {0}", dt)
Console.WriteLine("We will learn VB.Net seriously")
Console.WriteLine("Let us see what happens to the floating point variables:
")
Console.WriteLine("The Single: {0}, The Double: {1}", si, d)
Console.ReadKey()
End Sub
End Module

--------------------------------------------------------------------------

Activity 3.2

Imports System

Module Program
Sub Main()
Dim i As Integer
Dim dt As Date
Dim c As Char
Dim s As String
i = 20
dt = Today
c = "U"
s = "VB.Net"
'the oath taking
Console.Write(c & " and " & s & vbCrLf)
Console.WriteLine("declaring on the day of: {0}", dt)
Console.WriteLine("We will learn VB.Net seriously")
Console.WriteLine("Let us see what happens to the floating point variables:
")
Console.WriteLine("The Integer: {0}", i)
Console.ReadKey()
End Sub
End Module

Output:

U and VB.Net
declaring on the day of: 30/04/2024 00:00:00
We will learn VB.Net seriously
Let us see what happens to the floating point variables:
The Integer: 20

----------------------------------------------------------------------------

Activity 3.3

Imports System

Module Program
Sub Main()
Dim a As Integer = 20
Dim b As Integer = 28
Dim p As Integer = 4
Dim c As Integer
Dim d As Single
c = a + b
Console.WriteLine("Line 1 - Value of c is {0}", c)
d = a - b
Console.WriteLine("Line 2 - Value of d is {0}", d)
c = a * b
Console.WriteLine("Line 3 - Value of c is {0}", c)
d = a / b
Console.WriteLine("Line 4 - Value of d is {0}", d)
c = a \ b
Console.WriteLine("Line 5 - Value of c is {0}", c)
c = a Mod b
Console.WriteLine("Line 6 - Value of c is {0}", c)
c = b ^ p
Console.WriteLine("Line 7 - Value of c is {0}", c)
Console.ReadLine()
End Sub
End Module

Output:

Line 1 - Value of c is 48
Line 2 - Value of d is -8
Line 3 - Value of c is 560
Line 4 - Value of d is 0.71428573
Line 5 - Value of c is 0
Line 6 - Value of c is 20
Line 7 - Value of c is 614656

------------------------------------------------------------------------

Practice Exercise 3.1

Data Type | Storage Allocation

1. Char | 2 byte
2. Integer | 4 bytes
3. Double | 8 bytes
4. Decimal | 16 bytes
5. Date | 8 bytes

------------------------------------------------------------------------

Practice Exercises 3.2

Step 1: Start
Step 2: Declare a constant to store the value of PI and assign the value 3.14 to PI
Step 3: Declare a variable for Radius and assign the value 8 to it.
Step 4: Declare another variable for Area and assign as value the outcome from the
aritmetic expression: PI * (radius ^ 2) to it.
Step 5: Print the value of Area variable to Screen
Step 6: End

(program)

Imports System

Module Program
Sub Main()
Const PI As Double = 3.14
Dim radius As Double = 8
Dim area_of_circle As Double
area_of_circle = PI * (radius ^ 2)
Console.WriteLine("The area of a circle with radius 8 = {0}",
area_of_circle)
End Sub
End Module
------------------------------------------------------------------------

Practice Exercise 3.3

------------------------------------------------------------------------

Practice Exercise 3.4


program:

Imports System

Module Program
Sub Main()
Dim a As Integer = 42
Dim b As Integer = 26
Dim p As Integer = 6
Dim c As Integer
Dim d As Single
Console.WriteLine("Line 3 - Value of c is {0}", c)
d = a / b
Console.WriteLine("Line 4 - Value of d is {0}", d)
c = a \ b
Console.WriteLine("Line 5 - Value of c is {0}", c)
c = a Mod b
Console.WriteLine("Line 6 - Value of c is {0}", c)
c = b ^ p
Console.WriteLine("Line 7 - Value of c is {0}", c)
Console.ReadLine()
End Sub
End Module

Output:

Line 3 - Value of c is 0
Line 4 - Value of d is 1.6153846
Line 5 - Value of c is 1
Line 6 - Value of c is 16
Line 7 - Value of c is 308915776

-----------------------------------------------------------------------

Practice Exercise 3.5

-----------------------------------------------------------------------

Activity 4.1

Module Program
Sub Main()
Dim colour As String
Dim red As String
If colour = red Then
Console.WriteLine("You have chosen a red car!")
End If
Console.WriteLine("the colour you have chosen is: {0}", colour)
Console.ReadLine()
End Sub
End Module

----------------------------------------------------------------------

Activity 4.2

Program:

Imports System

Module Program
Sub Main()
Dim colour As String
Dim red As String
If colour = red Then
Console.WriteLine("You have chosen a red car!")
Else
Console.WriteLine("Please choose a colour for your car")
End If
Console.ReadLine()
End Sub
End Module

Output:

You have chosen a red car!

----------------------------------------------------------------------

Activity 4.3

Program:

Imports System

Module Program
Sub Main()
Dim level As Integer
Dim salary As Integer
Dim paygrade As Integer
If (paygrade = 7) Then
Console.WriteLine("salary = 1.04")
ElseIf (level >= 0 & level <= 8) Then
Console.WriteLine("salary = 1.05")
Else
'if none of the above conditions is satisfied, execure the followiing
statement
End If
Console.WriteLine("Salary does not match with the above conditions")
Console.WriteLine("Salary is ", salary)
Console.WriteLine("Hit any key to exit...")
Console.ReadLine()
End Sub
End Module

Output:

salary = 1.05
Salary does not match with the above conditions
Salary is
Hit any key to exit...

------------------------------------------------------------------------

Activity 4.4

Program:

Imports System

Module Program
Sub Main()
Dim Number As Integer
Select Case (Number)
Case "1", "10"
Console.WriteLine("Range = 1")
Case "9"
Console.WriteLine("Range = 2")
Case "2"
Console.WriteLine("Range = 3")
Case "3", "5"
Console.WriteLine("Range = 5")
Console.WriteLine("Range = 6")
Console.ReadLine()
End Select
End Sub
End Module

-----------------------------------------------------------------------

Activity 5.1

Program:

Imports System

Module Program
Sub Main()
' Initialization and declaration of variable i
Dim i As Integer = 1
Do
' Executes the following statement
Console.WriteLine("Value of variable I is: {0}", i)
i = i + 1 'increment the variable i by 1
Loop While i < 10 ' Define the while condition

Console.WriteLine(" Press any key to exit...")


Console.ReadLine()
End Sub
End Module

Output:

Value of variable I is: 1


Value of variable I is: 2
Value of variable I is: 3
Value of variable I is: 4
Value of variable I is: 5
Value of variable I is: 6
Value of variable I is: 7
Value of variable I is: 8
Value of variable I is: 9
Press any key to exit...

--------------------------------------------------------------------

Activity 5.2

Imports System

Module Do_loop
Sub Main()
' Initialization and declaration of variable i
Dim i As Integer = 1
Do
' Executes the following statement
Console.WriteLine("Value of variable I is: {0}", i)
i = i + 1 'increment the variable i by 1
Loop Until i = 10 ' Define the Until condition

Console.WriteLine(" Press any key to exit...")


Console.ReadLine()
End Sub
End Module

Output:

Value of variable I is: 1


Value of variable I is: 2
Value of variable I is: 3
Value of variable I is: 4
Value of variable I is: 5
Value of variable I is: 6
Value of variable I is: 7
Value of variable I is: 8
Value of variable I is: 9
Press any key to exit...

---------------------------------------------------------------------

Activity 5.3

Program:

Imports System

Module Table
Sub Main()
' declaration of i and num variable
Dim i, num As Integer
Console.WriteLine("Enter any number to print the table: ")
num = Console.ReadLine() ' accept a number from the user
Console.WriteLine(" Table of " & num)
'define for loop condition, it automatically initialize step to 1
For i = 1 To 10
Console.WriteLine(" " & num & " * " & i & " = " & i * num)
Next
Console.ReadKey()
End Sub
End Module

Output:

Enter any number to print the table:


2
Table of 2
2 * 1 = 2
2 * 2 = 4
2 * 3 = 6
2 * 4 = 8
2 * 5 = 10
2 * 6 = 12
2 * 7 = 14
2 * 8 = 16
2 * 9 = 18
2 * 10 = 20

---------------------------------------------------------------------

Activity 5.4

Program:

Imports System

Module Nested_loop
Sub Main()
Dim i, j As Integer
For i = 1 To 3
'outer loop
Console.WriteLine(" Outer loop, i = {0}", i)
'Console.Writeline(vbCrLf)

'inner loop
For j = 1 To 4
Console.WriteLine(" Inner loop, j = {0}", j)
Next
Console.WriteLine()
Next
Console.WriteLine(" Press any key to exit...")
Console.ReadKey()
End Sub
End Module

Output:

Outer loop, i = 1
Inner loop, j = 1
Inner loop, j = 2
Inner loop, j = 3
Inner loop, j = 4

Outer loop, i = 2
Inner loop, j = 1
Inner loop, j = 2
Inner loop, j = 3
Inner loop, j = 4

Outer loop, i = 3
Inner loop, j = 1
Inner loop, j = 2
Inner loop, j = 3
Inner loop, j = 4

Press any key to exit...

--------------------------------------------------------------------

Activity 5.5

Program:

Imports System

Module Program
Sub Main()
'declare and inititalize an array as integer
Dim An_array() As Integer = {1, 2, 3}
Dim i As Integer 'declare i as integer
For Each i In An_array
Console.WriteLine(" Value of i is {0}", i)
Next
Console.WriteLine("Press any key to exit...")
Console.ReadLine()
End Sub
End Module

Output:

Value of i is 1
Value of i is 2
Value of i is 3
Press any key to exit...

-----------------------------------------------------------------

Activity 5.6

Program:

Imports System

Module Program
Sub Main()
'declare an integer variable
Dim n, remainder, sum As Integer
sum = 0
Console.WriteLine(" Enter the number: ")
n = Console.ReadLine() ' Accept a number from the user

'Use While loop and write given below condition


While (n > 0)
remainder = n Mod 5
sum += remainder
n = n / 5
End While
Console.WriteLine(" Sum of digit is: {0}", sum)
Console.WriteLine(" Press any key to exit...")
Console.ReadKey()

End Sub
End Module

Output:

Enter the number:


34
Sum of digit is: 7
Press any key to exit...

-----------------------------------------------------------------

Activity 5.7

Program:

Imports System

Module Program
Sub Main()
'declare i and j as integer variable
Dim i As Integer = 1
While i < 4
'Outer loop statement
Console.WriteLine(" Counter value of Outer loop is {0}", i)
Dim j As Integer = 1
While j < 3
'Inner loop statement
Console.WriteLine(" Counter value of Inner loop is {0}", j)
j = j + 1 ' Increment Inner Counter variable by 1
End While
Console.WriteLine() 'print space
i = i + 1 ' Increment Outer Counter variable byy 1
End While
Console.WriteLine(" Press any key to exit...")
Console.ReadKey()
End Sub
End Module

Output:

Counter value of Outer loop is 1


Counter value of Inner loop is 1
Counter value of Inner loop is 2

Counter value of Outer loop is 2


Counter value of Inner loop is 1
Counter value of Inner loop is 2

Counter value of Outer loop is 3


Counter value of Inner loop is 1
Counter value of Inner loop is 2

Press any key to exit...

-----------------------------------------------------------------------

Practice Exercise 5.1

Program:

Imports System

Module Program
Sub Main()
For i As Integer = 1 To 4 'Outer loop
Console.WriteLine(" Table of " & i)
For j As Integer = 1 To 12 'Inner loop
Console.WriteLine(" " & i & " * " & j & " = " & i * j)
Next
Console.WriteLine()
Next
End Sub
End Module

Output:

Table of 1
1 * 1 = 1
1 * 2 = 2
1 * 3 = 3
1 * 4 = 4
1 * 5 = 5
1 * 6 = 6
1 * 7 = 7
1 * 8 = 8
1 * 9 = 9
1 * 10 = 10
1 * 11 = 11
1 * 12 = 12

Table of 2
2 * 1 = 2
2 * 2 = 4
2 * 3 = 6
2 * 4 = 8
2 * 5 = 10
2 * 6 = 12
2 * 7 = 14
2 * 8 = 16
2 * 9 = 18
2 * 10 = 20
2 * 11 = 22
2 * 12 = 24

Table of 3
3 * 1 = 3
3 * 2 = 6
3 * 3 = 9
3 * 4 = 12
3 * 5 = 15
3 * 6 = 18
3 * 7 = 21
3 * 8 = 24
3 * 9 = 27
3 * 10 = 30
3 * 11 = 33
3 * 12 = 36

Table of 4
4 * 1 = 4
4 * 2 = 8
4 * 3 = 12
4 * 4 = 16
4 * 5 = 20
4 * 6 = 24
4 * 7 = 28
4 * 8 = 32
4 * 9 = 36
4 * 10 = 40
4 * 11 = 44
4 * 12 = 48

-----------------------------------------------------------------------

Practice Exercise 5.2

Program:

Imports System

Module Program
Sub Main()
Dim i As Integer
For i = 1 To 5 'Outer loop
Console.WriteLine(i)
Next

End Sub
End Module

Output:

1
2
3
4
5

------------------------------------------------------------------------

Practice Exercise 5.3

Program:

Imports System

Module Program
Sub Main()
Dim i As Integer = 1
While (i < 8) 'checks while condition
Console.WriteLine(i) 'prints i to screen
i += 1 'increments i by 1
End While
End Sub
End Module

Output:

1
2
3
4
5
6
7

-------------------------------------------------------------------------

Practice Exercise 5.4

Program:

Imports System

Module Program
Sub Main()
Dim a, b, c As Integer
a = 500
b = 350
c = 200

If ((a > b Or a = b) And (a > c Or a = c)) Then


Console.WriteLine("The maximum of {0}, {1}, and {2} is {3}.", a, b, c,
a)
ElseIf ((b > a Or b = a) And (b > c Or b = c)) Then
Console.WriteLine("The maximum of {0}, {1}, and {2} is {3}.", a, b, c,
b)
ElseIf ((c > b Or c = b) And (c > a Or c = a)) Then
Console.WriteLine("The maximum of {0}, {1}, and {2} is {3}.", a, b, c,
c)
End If
End Sub
End Module

Output:

The maximum of 500, 350, and 200 is 500.

----------------------------------------------------------------------------

Practice Exercise 5.5

Program:

Imports System
Module Program
Sub Main()
Dim num As Integer
Console.Write("Enter a number: ")
num = Console.ReadLine()
Console.WriteLine()
If (num Mod 2) = 0 Then
Console.WriteLine("{0} is an even number.", num)
Else
Console.WriteLine("{0} is an odd number.", num)
End If
End Sub
End Module

Output:

Enter a number: 100

100 is an even number.

-----------------------------------------------------------------------------

Practice Exercise 5.6

Program:

Module Program
Sub Main()
Dim num1 As Integer = 45
Dim num2 As Integer = 65
If num1 > num2 Then
Console.WriteLine("{0} is greater, and {1} is lesser.", num1, num2)
ElseIf num2 > num1 Then
Console.WriteLine("{0} is greater, and {1} is lesser.", num2, num1)
Else
Console.WriteLine("{0} is equal to {1}", num1, num2)
End If
End Sub
End Module

Output:

Enter first number: 45


Enter second number: 65

65 is greater, and 45 is lesser.

---------------------------------------------------------------------------

Practice Exercise 5.7

Program:

Module Program
Function grade_score(ByVal score As Integer) As Char
If score >= 70 Then
Return "A"
ElseIf score >= 60 And score < 70 Then
Return "B"
ElseIf score >= 50 And score < 60 Then
Return "C"
ElseIf score >= 45 And score < 50 Then
Return "D"
ElseIf score >= 40 And score < 45 Then
Return "E"
Else
Return "F"
End If
End Function
Sub Main()
Dim subject(2) As String
Dim score(2) As Integer

For i As Integer = 0 To 2
Console.WriteLine("Enter Subject {0}: ", i + 1)
subject(i) = Console.ReadLine()
Console.WriteLine("Enter score for {0}: ", subject(i))
score(i) = Integer.Parse(Console.ReadLine())
Console.WriteLine()
Next

For j As Integer = 0 To 2
Console.WriteLine("Subject: {0}", subject(j))
Console.WriteLine("Score: {0}", score(j))
Console.WriteLine("Grade: {0}", grade_score(score(j)))
Console.WriteLine()
Next

End Sub
End Module

Output:

---------------------------------------------------------------------------

Practice Exercise 5.8

Program:

Module Program
Sub Main()
Dim num As Integer
For num = 1 To 7
Select Case (num)
Case "1"
Console.WriteLine("Day {0} of the week is Sunday.", num)
Case "2"
Console.WriteLine("Day {0} of the week is Monday.", num)
Case "3"
Console.WriteLine("Day {0} of the week is Tuesday.", num)
Case "4"
Console.WriteLine("Day {0} of the week is Wednesday.", num)
Case "5"
Console.WriteLine("Day {0} of the week is Thursday.", num)
Case "6"
Console.WriteLine("Day {0} of the week is Friday.", num)
Case "7"
Console.WriteLine("Day {0} of the week is Saturday.", num)
End Select
Next
End Sub
End Module

Output:

Day 1 of the week is Sunday.


Day 2 of the week is Monday.
Day 3 of the week is Tuesday.
Day 4 of the week is Wednesday.
Day 5 of the week is Thursday.
Day 6 of the week is Friday.
Day 7 of the week is Saturday.

----------------------------------------------------------------------------

Activity 6.1

Program:

Imports System

Module Program
Sub Main()
Dim whole_numbers(19) As Integer
whole_numbers(0) = 1
For k As Integer = 0 To 19
whole_numbers(k) = k + 1
Console.Write("{0}", whole_numbers(k))
Next
End Sub
End Module

Output:

1234567891011121314151617181920

------------------------------------------------------------------------------

Activity 6.2

Program:

Module Program
Sub Main()
Dim intRanNum(19) As Integer
Dim inty As Integer
Randomize()
' load the "intRanNum" array with
' random numbers between 1 and 200...
For inty = 0 To 19
intRanNum(inty) = Int(200 * Rnd() + 1)
Next
Console.WriteLine("Twenty random numbers between 1 and 200: ")
' display the contents of the "intRanNum" array...
For inty = 0 To 19
Console.WriteLine(CStr(intRanNum(inty)))
Next
Console.WriteLine("Hit the Enter button to exit window.")
Console.ReadLine()
End Sub
End Module

Output:

Twenty random numbers between 1 and 200:


80
102
105
176
54
136
184
45
182
196
122
131
76
109
46
14
108
21
135
123
Hit the Enter button to exit window.

----------------------------------------------------------------------------

Activity 6.3

Imports System

Module Program
Sub Main()
Dim sales(3, 5) As Decimal

' Declare variables for file processing...


Dim salesFileName As String
Dim salesFileNum As Integer

' Declare variables to be used to access elements of the array...


Dim intA, intB As Integer

' Set up the file name...


salesFileName = My.Application.info.directoryPath & "\INVENTORY.DAT"
salesFileNum = FreeFile()

' Open the sales file


FileOpen(salesFileNum, salesFileName, OpenMode.Input)
For intA = 0 To 3
For intB = 0 To 5
Input(salesFileNum, dailySales(intA, intB))
Next
Next
' Close the salaes file
FileClose(salesFileName)
For intA = 0 To 3
Console.Write(CStr(intA).Trim.PadLeft(6))
For intB = 0 To 5
Console.Write(CStr(dailySales(intA, intB)).Trim.Padleft(6))
Next
Console.WriteLine()
Next
Console.WriteLine()
Console.WriteLine("Press Enter to close this window.")
Console.ReadLine()
End Sub
End Module

---------------------------------------------------------------------------

Activity 6.4

Program:

Imports System

Module Program
Sub Main()
Dim intSpeed() As Integer
Dim intEnterNum As Integer
Dim intA As Integer
Dim totSpeed As Integer
Dim avgSpeed As Decimal

Console.Write("Number of speed values to be entered: ")


intEnterNum = Val(Console.ReadLine())
Console.WriteLine()

If intEnterNum = 0 Then Exit Sub

ReDim intSpeed(intEnterNum - 1)

For intA = 0 To (intEnterNum - 1)


Console.Write("Speed #" & (intA + 1) & ": ")
intSpeed(intA) = Val(Console.ReadLine)
totSpeed += intSpeed(intA)
Next
avgSpeed = CInt(totSpeed / intEnterNum)
Console.WriteLine()
Console.WriteLine("The average speed entered was " & avgSpeed & ".")
Console.WriteLine()
Console.WriteLine("Press Enter to end this session.")
Console.ReadLine()
End Sub
End Module

Output:

Number of speed values to be entered: 3

Speed #1: 50
Speed #2: 22.5
Speed #3: 55.9

The average speed entered was 43.

Press Enter to end this session.

-----------------------------------------------------------------------

Activity 6.5

Program:

Imports System

Module Program
Sub Main()
Dim okekes() = {"Ekene", "Nkem", "Chinwe", "Duru", "Chidi", "Nneka"}
Array.Sort(okekes)
Array.Reverse(okekes)
For Each s As String In okekes
Console.Write("{0} ", s)
Next
Console.ReadKey()
End Sub
End Module

Output:

Nneka Nkem Ekene Duru Chinwe Chidi

----------------------------------------------------------------------

Activity 6.6

Program (Edited):

Imports System

Module Program
Sub main()
Dim counter As Integer = 0
For i = 1 To 500
If i Mod 4 = 0 Then
counter = counter + 1
End If
Next
Console.WriteLine("There are {0} factors of 4 inbetween 1 and 500.",
counter)
End Sub
End Module

Output:

There are 125 factors of 4 inbetween 1 and 500.

-----------------------------------------------------------------------

Activity 6.7
Program:

Imports System

Module Program
Sub main()
Dim arrs() As Integer = {2, 32, 14, 11, 25, 11, 38, 50, 34, 15, 44, 79}
Dim arr_index As Integer
arr_index = seqSearch(arrs, 1, arrs.Length)
If (arr_index <> -1) Then
Console.WriteLine("The item was found at the position {0}.", arr_index)
End If
Console.ReadLine()
End Sub
End Module

------------------------------------------------------------------------

Practice Exercise 6.1

Program:

Imports System

Module Program
Sub main()
Dim friends(15) As String '{"Nedu", "Ayobami", "Nneka", "Ubong", "Chidi",
"Infinity", "Gospel", "Akam-Obong", "Newton", "Blessing"}
friends(0) = "Nedu"
friends(1) = "Ayobami"
friends(2) = "Nneka"
friends(3) = "Ubong"
friends(4) = "Chidi"
friends(5) = "Infinity"
friends(6) = "Gospel"
friends(7) = "Akam-Obong"
friends(8) = "Newton"
friends(9) = "Blessing"
For i As Integer = 0 To 9
Console.WriteLine(friends(i))
Next
Console.WriteLine()
End Sub
End Module

Output:

Nedu
Ayobami
Nneka
Ubong
Chidi
Infinity
Gospel
Akam-Obong
Newton
Blessing
------------------------------------------------------------------------

Practice Exercise 6.2

Program:

Imports System

Module Program
Sub main()
Dim arr_num() As Integer
arr_num = New Integer() {2, 4, 6, 8, 10} 'initializes "arr_name" array
Dim k As Integer
For k = 0 To 4 'output arr_num array
Console.Write("{0}", arr_num(k) * arr_num(k) & vbTab)
Next
Console.ReadLine()
End Sub
End Module

Output:

4 16 36 64 100

------------------------------------------------------------------------

Practice 6.3

Program:

Imports System

Module Program
Sub main()
Dim arr_num() As Integer
Dim num As Integer
Console.Write("How many numbers: ")
num = Console.ReadLine() ' collect the number of numbers to check from the
user
Console.WriteLine()

ReDim arr_num(num - 1) ' Redifine the size of "arr_num" array.

' collects the different number elements from user and stores in the
"arr_num" array
For i As Integer = 0 To (num - 1)
Console.WriteLine("Enter number: ")
arr_num(i) = Console.ReadLine()
Next

' loops through the array to find the maximum number


Dim maxNumber As Integer = arr_num(0)
For j As Integer = 1 To (num - 1)
If arr_num(j) > maxNumber Then
maxNumber = arr_num(j)
End If
Next
Console.WriteLine()
Console.Write("The maximum number is: {0}", maxNumber)
End Sub
End Module

Output:

How many numbers: 3

Enter number:
67
Enter number:
80
Enter number:
12

The maximum number is: 80

--------------------------------------------------------------------------

Practice Exercise 6.4

Program:

Module Program
Sub main()
Dim ran_num(6) As Integer
Console.WriteLine("Enter 7 random numbers: ")
For i As Integer = 0 To 6
ran_num(i) = Console.ReadLine()
Next
Console.WriteLine()

Array.Sort(ran_num) ' sorts the array using the "Array.Sort()" method

Console.WriteLine()
Console.Write("Sorted List: ")
For j As Integer = 0 To 6
Console.Write(ran_num(j) & " ")
Next
End Sub
End Module

Output:

Enter 7 random numbers:


45
23
67
32
86
34
2

Sorted List: 2 23 32 34 45 67 86

-------------------------------------------------------------------------

Practice Exercise 6.5


Program:
Imports System
Imports System.Collections.Immutable

Module Program
Sub main()
Console.Write("Enter a number: ")
Dim num As Integer = Convert.ToInt32(Console.ReadLine())
Dim factorial As Integer = 1
For i As Integer = 1 To num
factorial *= i
Next
Console.WriteLine("{0}! is: {1}.", num, factorial)
Console.WriteLine()
End Sub
End Module

Output:

Enter a number: 6
6! is: 720.

----------------------------------------------------------------------
LAB 7

Program:

Imports Microsoft.VisualBasic

Private Function GenerateRandomString(NumberOfCharacters As Integer) As String


Dim GeneratedString As String = String.Empty
For index As Integer = 1 To NumberOfCharacters Step 1
Dim RandomLetter As Char = ConvertTochar(Rnd.nect(97, 123))
GeneratedString += RandomLetter
Next
Return GeneratedString
End Function

Q1

----------------------------
Q2

- "GeneratedString += RandomLetter" concatenates the random char value


"RandomLetter" to the the string "GeneratedString" by adding The value of
"RandomLetter" to the value of "GeneratedString" and then reassign the new value to
"GeneratedString".
- The purpose of "Convert.ToChar" is to convert a value to a char data type. This
method is used to convert a character code, a string, or an object to its
equivalent unicode character.

----------------------------
Q3

----------------------------
Q4
If this program is ran, and 14 (for example) is inputted, the expected output is
14.00.
The output is gotten from calling the Format Function, with "dblTestNumber" as the
first argument, our preffered format style (in our case is "##, ##0.00")as second
argument. The Format function returns a string formmatted according to instruction
contained in a format String espression. The specified format in the code above the
format specified, adds 2 decimal places to the number passed into the Format
function.
----------------------------
Q5
Procedure and functions are used for condensing repeated operatins such as the
frequently used calculations, text and control manipulation. They are imporatant
for breaking a program into discrete logocal limits, thereby making debugging and
code maintenance easier and also allow us to resuse those code blocks again in
other programs.
----------------------------
Q6
False. Sub procedures don't return any values.

----------------------------
Q7
"&" is not a logical operator.

----------------------------
Q8
"If else and select case"
----------------------------
Q9
Dim [Variable_Name] As [defined Data type] = [Value]

-----------------------------------------------------------------------------
Activity 8.1

Program:

Observation:

A window popped up, containg a text box with the text "Hello. Welcome to University
of Port Harcourt". The text can be edited.
------------------------------------------------------------------------------
Activity 8.2

Upon running the code, a form window appeared with two textbox to collect username
and password from the user, and a login button. The characters typed into the
password box was masked by the asterisk character (*) to protect the password typed
in from being exposed.

------------------------------------------------------------------------------
Activity 8.3

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)


Handles ComboBox1.SelectedIndexChanged
ComboBox1.Items.Add("Uniport")
ComboBox1.Items.Add("Faculty of Science")
ComboBox1.Items.Add("Department of Computer Science")
ComboBox1.Items.Add("Rivers")
ComboBox1.Items.Add("Nigeria")
ComboBox1.Items.Add("Africa")
End Sub

-----------------------------------------------------------------------------
Practice Exercise 8.1
Control properties are attributes that define the appearance and behavior of a
control on a form.
Five most used form properties are:
1. Name: The Name property is used to give a unique identifier to a form or
control.
2. Text: The Text property is used to set the text that appears in the title bar of
a form.
3. BackColor: The BackColor property is used to set the background color of a form
or control.
4. ForeColor: The ForeColor property is used to set the text color of a form or
control.
5. Size: The Size property is used to set the width and height of a form or
control.

-----------------------------------------------------------------------------

Practice Exercise 8.2

Control methods are predefined actions that can be called to manipulate controls.
Examples of control methods include Hide(), Show(), Focus() e.t.c. While Control
events are predefined occurrences that can be responded to with event handlers in
the code. Examples of control events include Click, MouseHover, KeyPress,
TextChanged, etc.

-----------------------------------------------------------------------------
Practice Exercise 9.1

WEBSITE | WEB APPLICATION


→ Primarily static content. → Dynamic content and functionality.
→ Informational Purpose. → Interactive Purpose.
→ Simple Navigation. → Complex Application and User
Interface.
→ Typically built using HTML, CSS and JavaScript. → Built using a programing
language(e.g Python, Java) and a Framework(e.g Django, ASP.Net).
→ Basically, Users can only view contents. → Users can input and interact
with the application.

------------------------------------------------------------------------------

Practice Exercise 9.2

In application development, a round trip refers to the process of sending a request


from a client to a server, processing the request on the server, and then sending
back a response to the client.

------------------------------------------------------------------------------

Practice Exercise 9.3

Web.config |
Machine.config
→ Specific to a web application. → Applies to all .NET
applications on the machine
→ Configurations settings apply only to the current web application. →
Configuration settings are global and apply to all web applications.
→ Located in the root directory of the web application. → Located
in the %runtime%\config directory.
→ overrides setting in the Machine.config file. → Sets default
settings for all web applications.
→ Used to store application specific settings, such as: → Used to store
machine-wide settings, such as:
- Database connection strings - .NET Framework
settings
- Authentication and authorization settings. - Security
settings.
- Error handling and debugging settings. - Database
connection settings.
- Custom application settings. - Default
web application settings.

------------------------------------------------------------------------------

Practice Exercise 9.4'

A connection string in Web.comfig file is defined using the <connectionStrings>


element, which is a child element of the <configuration> element.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy