0% found this document useful (0 votes)
22 views38 pages

Notes Pseudo Code Vs VB. NET

Uploaded by

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

Notes Pseudo Code Vs VB. NET

Uploaded by

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

Data types

Pseudo Code VB.Net ( Console Mode)


INTEGER Integer
STRING String written in double quotes
CHAR CHAR written in double quotes
BOOLEAN Boolean
DATE Date
REAL Single , Double, Decimal

Pseudo Code VB.Net ( Console Mode)


DECLARE Num : INTEGER Dim Num As Integer
DECLARE StName : STRING
Dim StName As String

OUTPUT “ Enter Student Name” Console.WriteLine("Enter Student Name")

INPUT StName, Num StName = Console.ReadLine()

Console.WriteLine("Enter Number")

Num = Console.ReadLine()

Console.readkey() (to stop/hold the screen)

Page 1 of 38
Q.1 Write an algorithm in the form of pseudo code to input a number
and print whether the number is negative or positive. 0 is considered
as positive.
Pseudocode:
DECLARE Num : INTEGER
INPUT Num
IF Num >=0
THEN
OUTPUT “ Number is Positive”
ELSE
OUTPUT “ Number is Positive”
ENDIF

VB.NET
Dim Num As Integer
Console.WriteLine(" Please enter a number")
Num = Console.ReadLine()

IF Num >= 0 Then


Console.WriteLine("Number is positive")
Else
Console.WriteLine("Number is Negative")
End If

Console.ReadKey()

Page 2 of 38
Q.2 Write an algorithm in the form of pseudo code to input a number and
print whether the number is Odd or Even. You may use MOD Operator.
Pseudocode:
DECLARE Num : INTEGER
INPUT NUM

IF Num MOD 2 = 0
THEN
OUTPUT “ Number is Even”
ELSE
OUTPUT “ Number is odd”
ENDIF

VB Code
Dim Num As Integer
Console.WriteLine(" Please enter a number")
Num = Console.ReadLine()
IF Num Mod 2 = 0 Then
Console.WriteLine("Number is Even")
Else
Console.WriteLine("Number is Odd")
End If

Console.ReadKey()

Page 3 of 38
Q.3 Write an algorithm in the form of pseudo code to input a number and
print whether the number is Odd or Even. You may use MOD Operator.
Pseudocode:
DECLARE Num : INTEGER
INPUT NUM
IF Num MOD 2 = 0
THEN
OUTPUT “ Number is Even”
ELSE
OUTPUT “ Number is odd”
ENDIF

VB Code

Dim Num As Integer


Console.WriteLine(" Please enter a number")
Num = Console.ReadLine()
If Num Mod 2 = 0 Then
Console.WriteLine("Number is Even")
Else
Console.WriteLine("Number is Odd")
End If

Console.ReadKey()

Page 4 of 38
Q.4 Write an algorithm to input grade and display Excellent if
grade is A, Display Good if grade is B , Display Average if
grade is C . Display improvement is need on other Grades.

PseudoCode:
DECLARE Grade : CHAR
INPUT Grade
IF Grade = ‘A’
THEN
OUTPUT “ Excellent”
ELSEIF Grade = ‘B’
THEN
OUTPUT “ Good”
ELSEIF Grade= ‘C’
THEN
OUTPUT “ Average”
ELSE
OUTPUT “ Improvement is needed”
ENDIF

Page 5 of 38
VB.Net Code:
Dim Grade As Char
Console.WriteLine("Please enter Grade")
Grade = Console.ReadLine()
If Grade = "A" Then
Console.WriteLine("Excellent")
ElseIf Grade = "B" Then
Console.WriteLine("Good")
ElseIf Grade = "C" Then
Console.WriteLine("Average")
Else
Console.WriteLine("Improvement is needed")
End If
Console.ReadKey()

Q. Input there different numbers and output the largest


Number.

Pseudo code:

DECLARE Num1 , Num2 , Num3 : INTEGER

INPUT Num1 , Num2, Num3


IF Num1 > Num2 AND Num1 > Num3
THEN
OUTPUT Num1
ELSEIF Num2 > Num1 AND Num2 > Num3
THEN
OUTPUT Num2
ELSE
OUTPUT Num3
ENDIF

Page 6 of 38
Vb.Net

Dim Num1 As Integer


Dim Num2 As Integer
Dim Num3 As Integer

Console.WriteLine("Please enter Number 1")


Num1 = Console.ReadLine()
Console.WriteLine("Please enter Number 2")
Num2 = Console.ReadLine()
Console.WriteLine("Please enter Number 3")
Num3 = Console.ReadLine()

If Num1 > Num2 And Num1 > Num3 Then


Console.WriteLine("Largest Number =" & Num1)
ElseIf Num2 > Num1 And Num2 > Num3 Then
Console.WriteLine("Largest Number =" & Num2)
Else
Console.WriteLine("Largest Number =" & Num3)
End If

Console.ReadKey()

Page 7 of 38
Q Write an algorithm to input grade and diplay Excellent if grade is A,
Display Good if grade is B , Display Average if grade is C . Display
improvement is need on other Grades.
DECLARE Grade : CHAR
DECLARE Grade : CHAR
INPUT Grade
INPUT Grade
IF Grade = ‘A’
CASE OF Grade
THEN
‘A’ OR ‘a’ : OUTPUT “ Excellent”
OUTPUT “ Excellent”
‘B’ OR ‘b’ : OUTPUT “ Good”
ELSEIF Grade = ‘B’
‘C’ OR ‘c’ : OUTPUT “ Average”
THEN
OTHERWISE OUTPUT “ Improvement is needed”
OUTPUT “ Good”
END CASE
ELSEIF Grade= ‘C’
THEN
OUTPUT “ Average”
ELSE
OUTPUT “ Improvement is needed”
ENDIF

Page 8 of 38
VB.Net Code:
Dim Grade As Char

Console.WriteLine("Please enter Grade")


Grade = Console.ReadLine()

Select Case Grade


Case "A", "a"
Console.WriteLine("Excellent")
Case "B", "b"
Console.WriteLine("Good")
Case "C", "c"
Console.WriteLine("Average")
Case Else
Console.WriteLine("Improvement is needed")
End Select

Q. Write an algorithm to input day of the week from 1 to 7 and display its
equalent day of the week. E.g if User input 1 then display Monday, User Input 2,
Display Tuesday and so on… Also display an error message if number is invalid.
Pseud Code: DECLARE Day : Integer
DECLARE Day : INTEGER INPUT Day
INPUT Day
IF Day=1 CASE OF Day
THEN
OUTPUT “ Monday” 1 : OUTPUT “ Monday
ELSEIF Day=2 2 : OUTPUT “ Tuesday”
THEN
OUTPUT “ Tuesday” 3 : OUTPUT “ Wednesday”
ELSEIF Day=3
THEN 4 : OUTPUT “ Thursday”
OUTPUT “ Wednesday” 5 : OUTPUT “ Friday”
6 : OUTPUT “ Saturday”
ELSEIF Day=4
THEN 7 : OUTPUTn” Sunday”
OUTPUT “ Thursday” OTHERWISE OUTPUT “ Invalid Day”
END CASE
Page 9 of 38
ELSEIF Day=5
THEN
OUTPUT “ Friday”

ELSEIF Day=6
THEN
OUTPUT “ Saturday”

ELSEIF Day=7
THEN
OUTPUT “ Sunday”
ELSE
OUTPUT “ Invalid Day”
ENDIF

VB.Net Code with IF Statement:


Dim Day As Integer

Console.WriteLine("Please enter a Day number from 1 to 7")


Day = Console.ReadLine()
If Day = 1 Then
Console.WriteLine("Monday")
ElseIf Day = 2 Then
Console.WriteLine("Tuesday")
ElseIf Day = 3 Then
Console.WriteLine("Wednesday")
ElseIf Day = 4 Then
Console.WriteLine("Thursday")
ElseIf Day = 5 Then
Console.WriteLine("Friday")
ElseIf Day = 6 Then
Console.WriteLine("Saturday")
ElseIf Day = 7 Then
Console.WriteLine("Sunday")
Else
Console.WriteLine("Invalid day")
End If

Console.ReadKey()

Page 10 of 38
VB.Net Code with SELECT CASE Statement:
Dim Day As Integer

Console.WriteLine("Please enter a Day number from 1 to 7")


Day = Console.ReadLine()
Select Case Day
Case 1
Console.WriteLine("Monday")
Case 2
Console.WriteLine("Tuesday")
Case 3
Console.WriteLine("Wednesday")
Case 4
Console.WriteLine("Thursday")
Case 5
Console.WriteLine("Friday")
Case 6
Console.WriteLine("Saturday")
Case 7
Console.WriteLine("Sunday")
Case Else
Console.WriteLine("Invalid day")
End Select

Console.ReadKey()

LOOP:

Q Write an algorithm to input marks of computer subject of 10 students of


a class. Print overall total and average of the whole class.
Using FOR ….To ….NEXT loop.

Pseudo Code:

DECLARE Marks, Total, Count: INTEGER


DECLARE Avg : REAL

Total  0
FOR Count  1 TO 10
INPUT Marks
Total  Total + Marks
NEXT
Avg  Total / 10
OUTPUT Total , Avg
Page 11 of 38
VB.NET Code:

Dim Marks As Integer


Dim Total As Integer
Dim Count As Integer
Dim Avg As Decimal

Total = 0

For Count = 1 To 10
Console.WriteLine("Please eneter marks")
Marks = Console.ReadLine()
Total = Total + Marks
Next
Avg = Total / 10
Console.WriteLine("Total marks = " & Total)
Console.WriteLine("Average marks= " & Avg)
Console.ReadKey()

Q Write an algorithm to input marks of computer subject of 10 students of


a class. Print overall total and average of the whole class.
Using WHILE …DO …. ENDWHILE loop.

Pseudo Code:

DECLARE Marks, Total, Count: INTEGER


DECLARE Avg : REAL

Total  0
Count 1
WHILE Count <= 10
INPUT Marks
Total  Total + Marks
Count  Count + 1
ENDWHILE
Avg  Total / 10
OUTPUT Total , Avg

Page 12 of 38
VB.Net Code:

Dim Marks As Integer


Dim Total As Integer
Dim Count As Integer
Dim Avg As Single

Total = 0

Count = 1
While Count <= 10
Console.WriteLine("Please eneter marks")
Marks = Console.ReadLine()
Total = Total + Marks
Count = Count + 1
End While
Avg = Total / 10
Console.WriteLine("Total marks = " & Total)
Console.WriteLine("Average marks= " & Avg)

Console.ReadKey()
Q Write an algorithm to input marks of computer subject of 10 students of
a class. Print overall total and average of the whole class.
Using REPEAT …UNTIL loop.

Pseudo Code:

DECLARE Marks, Total, Count: INTEGER


DECLARE Avg : REAL

Total  0
Count 1
REPEAT
INPUT Marks
Total  Total + Marks
Count  Count + 1
UNTIL Count > 10

Page 13 of 38
Avg  Total / 10
OUTPUT Total , Avg

VB.NET Code:
' This program is developed by talat jahangir on 15th July 2024 at 3:41 P.m

Dim Marks As Integer ' Its variable declaration


Dim Total As Integer
Dim Count As Integer
Dim Avg As Single

Total = 0

Count = 1
Do ' in Pseudo Code REPEAT
Console.WriteLine("Please eneter marks")
Marks = Console.ReadLine() ' in Pseudo Code INPUT Marks
Total = Total + Marks
Count = Count + 1
Loop Until Count > 10 ' in Pseudo Code UNTIL Count > 10
Avg = Total / 10
Console.WriteLine("Total marks = " & Total)
Console.WriteLine("Average marks= " & Avg)

Console.ReadKey()

Unknown Number of Repeatition:


Q. Write an algorithm to input marks of computer subject of students of a class.
Terminate the loop if user Input -1 . Using WHILE … DO … ENDWHILE loop

Pseudo Code:

DECLARE Marks : INTEGER

INPUT Marks
WHILE Marks <> -1

NPUT Marks
ENDWHILE

Page 14 of 38
VB.Net Code:
Dim Marks As Integer

Console.WriteLine("Please eneter marks")


Marks = Console.ReadLine()
While Marks <> -1

Console.WriteLine("Please eneter marks")


Marks = Console.ReadLine()
End While

Console.ReadKey()

Q. Write an algorithm to input marks of computer subject of students of a class.


Terminate the loop if user Input -1 . Using REPEAT … UNTIL loop

Pseudo Code:

DECLARE Marks : INTEGER

REPEAT
NPUT Marks

UNTIL Count = -1

VB.Net Code :

Dim Marks As Integer

Do

Console.WriteLine("Please enter marks")


Marks = Console.ReadLine()
Loop Until Marks = -1

Console.ReadKey()

Page 15 of 38
Algorithm Techniques:
1. How Many

Solution: +1 increment when condition is true

Q.1. Input ten numbers and print how many numbers are positive and how
many numbers are negative? (Using FOR ….To ….NEXT. 0 is considered as
positive.

Pseudo Code:

DECLARE Num , Pos, Neg, Count : INTEGER

Pos  0
Neg  0
FOR Count  1 TO 10
INPUT Num
IF Num >= 0 THEN
Pos  Pos + 1
ELSE
Neg  Neg + 1
ENDIF
NEXT
OUTPUT Neg , Pos

Page 16 of 38
VB Code:
Dim Num As Integer
Dim Pos As Integer
Dim Neg As Integer
Dim Count As Integer

Neg = 0
Pos = 0
For Count = 1 To 10
Console.WriteLine("Enetr Number")
Num = Console.ReadLine()
If Num >= 0 Then
Pos = Pos + 1
Else
Neg = Neg + 1
End If
Next
Console.WriteLine("Negatve numbers are " & Neg)
Console.WriteLine("Positive numbers are " & Pos)

Console.ReadKey()

Same code Using WHILE Loop:


Dim Num As Integer
Dim Pos As Integer
Dim Neg As Integer
Dim Count As Integer

Neg = 0
Pos = 0
Count = 1
While Count <= 10
Console.WriteLine("Enetr Number")
Num = Console.ReadLine()
If Num >= 0 Then
Pos = Pos + 1
Else
Neg = Neg + 1
End If
Count= Count + 1
End While

Console.WriteLine("Negatve numbers are " & Neg)


Console.WriteLine("Positive numbers are " & Pos)

Console.ReadKey()

Page 17 of 38
Same code Using REPEAT Loop:

Dim Num As Integer


Dim Pos As Integer
Dim Neg As Integer
Dim Count As Integer

Neg = 0
Pos = 0
Count = 1

Do
Console.WriteLine("Enetr Number")
Num = Console.ReadLine()
If Num >= 0 Then
Pos = Pos + 1
Else
Neg = Neg + 1
End If
Count = Count + 1
Loop Until Count > 10

Console.WriteLine("Negatve numbers are " & Neg)


Console.WriteLine("Positive numbers are " & Pos)

Console.ReadKey()

Page 18 of 38
Unknown Number of Repetition:

Pseudo Code:

DELCARE Num , Less1000 , Greater1000 : INTEGER

Less1000 0
Greater1000  0

INPUT Num
WHILE Num <> -1

IF Num < 1000 THEN


Less1000  Less1000 + 1
ELSE
IF Num > 1000 THEN
Greater1000  Greater1000 + 1
ENDIF
ENDIF

INPUT Num
ENDWHILE

OUTPUT “ Less than 1000 Numers = “ & Less1000


OUTPUT “ Greater than 1000 Numers = “ & Greater1000

Page 19 of 38
Pseudo code using REPEAT Loop:

DELCARE Num , Less1000 , Greater1000 : INTEGER

Less1000 0
Greater1000  0

REPEATE
INPUT Num

IF Num < 1000 THEN


Less1000  Less1000 + 1
ELSE
IF Num > 1000 THEN
Greater1000  Greater1000 + 1
ENDIF
ENDIF

UNTIL Num = -1

OUTPUT “ Less than 1000 Numers = “ & Less1000


OUTPUT “ Greater than 1000 Numers = “ & Greater1000

Page 20 of 38
VB.Net Code using WHILE Loop:
Dim Num As Integer
Dim Less1000 As Integer
Dim Greater1000 As Integer

Less1000 = 0
Greater1000 = 0

Console.WriteLine(" Please enter number")


Num = Console.ReadLine()
While Num <> -1
If Num < 1000 Then
Less1000 = Less1000 + 1
Else
If Num > 1000 Then
Greater1000 = Greater1000 + 1
End If
End If
Console.WriteLine(" Please enter number")
Num = Console.ReadLine()
End While
Console.WriteLine("Less than 1000 Numers = " & Less1000)
Console.WriteLine("Greater than 1000 Numers = " & Greater1000)

Using DO..LOOP…UNTIL

Dim Num As Integer


Dim Less1000 As Integer
Dim Greater1000 As Integer

Less1000 = 0
Greater1000 = 0

Do
Console.WriteLine(" Please enter number")
Num = Console.ReadLine()
If Num < 1000 Then
Less1000 = Less1000 + 1
Else
If Num > 1000 Then
Greater1000 = Greater1000 + 1
End If
End If
Loop Until Num = -1
Console.WriteLine("Less than 1000 Numers = " & Less1000)
Console.WriteLine("Greater than 1000 Numers = " & Greater1000)
Console.ReadKey()

Page 21 of 38
Minimum and Maximum Technique:

Q. Write an algorithm in the form of pseudo code to Input the


temperature of 10 days(once in a day) .Calculate and display minimum and
maximum temperature.
Pseudo Code : 2nd Method

DECLARE Temp, Min, Max, Count : INTEGER DECLARE Temp, Min, Max, Count : INTEGER

Min  10000 INPUT Temp


Max  -10000 Min  Temp
Max  Temp
FOR count= 1 to 10
INPUT Temp FOR count= 1 to 9
IF Temp < Min THEN INPUT Temp
Min  Temp IF Temp < Min THEN
ENDIF Min  Temp
IF Temp > Max THEN ENDIF
Max  Temp IF Temp > Max THEN
ENDIF Max  Temp
NEXT ENDIF
NEXT
OUTPUT “ Minimum Temerature = “ & Min
OUTPUT “ Maximum Temerature = “ & Max OUTPUT “ Minimum Temerature = “ & Min
OUTPUT “ Maximum Temerature = “ & Max
VB.Net Code:

Dim Temp As Integer


Dim min As Integer
Dim max As Integer
Dim Count As Integer

min = 10000
max = -10000
For Count = 1 To 10
Console.WriteLine("Please enter Temerature")
Temp = Console.ReadLine()
If Temp < min Then
min = Temp
End If
If Temp > max Then
max = Temp
End If
Next

Page 22 of 38
Console.WriteLine(" Minmum Temperature = " & min)
Console.WriteLine(" Maximum Temperature = " & max)

Console.ReadKey()

VB.Net Code (2nd method):

Dim Temp As Integer


Dim Min As Integer
Dim Max As Integer
Dim Count As Integer

Console.WriteLine("Please enter Temerature")


Temp = Console.ReadLine()
Min = Temp
Max = Temp

For Count = 1 To 9
Console.WriteLine("Please enter Temerature")
Temp = Console.ReadLine()
If Temp < Min Then
Min = Temp
End If
If Temp > Max Then
Max = Temp
End If
Next

Console.WriteLine(" Minmum Temperature = " & min)


Console.WriteLine(" Maximum Temperature = " & max)

Console.ReadKey()

Page 23 of 38
Array: 1D ARRAY
Q. Declare an Array with the name of Mars of 10 elements.
Declaration in Pseudo Code:
DECLARE Marks : ARRAY [0:9] OF INTEGER
VB.Net Code:
Dim Marks(9) As Integer

Q. Enter the marks into array elements and then display


all of them.
Pseudo code:
DECLARE MyList : ARRAY [0 : 6 ] OF INTEGER
DECLARE I : INTEGER
FOR i  0 TO 6
INPUT MyList[i]
NEXT

FOR i  0 TO 6
OUTPUT MyList[i]
NEXT

VB.Net Code:
Dim MyList(6) As Integer
Dim i As Integer

For i = 0 To 6
Console.WriteLine("Enter Values")
MyList(i) = Console.ReadLine()
Next

For i = 0 To 6
Console.WriteLine(MyList(i))
Next

Console.ReadKey()

Page 24 of 38
Q. Enter the following values into Array MyList.

VB.Net Code:
Linear / Serial Search
Dim MyList(6) As Integer
Pseudo Code:
MyList(0) = 25
MyList(1) = 34 DECLARE SearchVal , i : INTEGER
MyList(2) = 98
DECLARE Found : BOOLEAN
MyList(3) = 7
MyList(4) = 41 Found  False
MyList(5) = 19 i0
MyList(6) = 5 INPUT SearchVal
Console.ReadKey() REPEAT
IF SearchVal = MyList[i] THEN
Found  true
ELSE
ii+1
END IF
UNTIL Found = True OR i > 6
IF Found = True THEN
OUTPUT “ Match found at location “ & i
ELSE
OUTPUT “ Match Not Found”
ENDIF

Page 25 of 38
VB.Net Code ( Linear/ Serial Search):
Dim MyList(6) As Integer

MyList(0) = 25
MyList(1) = 34
MyList(2) = 98
MyList(3) = 7
MyList(4) = 41
MyList(5) = 19
MyList(6) = 5

Dim SearchVal As Integer


Dim i As Integer
Dim Found As Boolean
Found = False
i = 0

Console.WriteLine("Please enter the value you want to search")


SearchVal = Console.ReadLine()
Do
If SearchVal = MyList(i) Then
Found = True
Else
i = i + 1
End If
Loop Until Found = True Or i > 6
If Found = True Then
Console.WriteLine("Match found at Location " & i)
Else
Console.WriteLine("Match not Found")
End If

Console.ReadKey()

Page 26 of 38
Bubble Sorting in Ascending order:
DECLARE N ,Count , Temp : INTEGER
DECLARE Swap : BOOLEAN
N  5
REPEAT
Swap  False
FOR Count  0 TO N
IF mylist[Count] > Mylist [Count] THEN
Temp  MyList[Count]
MyList[Count]  MyList[Count]
MyList [Count]  Temp
Swap  True
ENDIF
NEXT
N  N - 1
UNTIL Swap = False
To display sorted Data:
FOR Count= 0 TO 6
OUTPUT MyList[Count]
NEXT

Page 27 of 38
VB.Net Code (Bubble sort in ascending order)
Dim MyList(6) As Integer

MyList(0) = 25
MyList(1) = 34
MyList(2) = 98
MyList(3) = 7
MyList(4) = 41
MyList(5) = 19
MyList(6) = 5

' Bubble sorting in Ascending order


Dim N As Integer
Dim Temp As Integer
Dim Count As Integer
Dim Swap As Boolean

N = 5
Do
Swap = False
For Count = 0 To N
If MyList(Count) > MyList(Count + 1) Then
Temp = MyList(Count)
MyList(Count) = MyList(Count + 1)
MyList(Count + 1) = Temp
Swap = True
End If
Next
N = N - 1
Loop Until Swap = False

' To display sorted data


For Count = 0 To 6
Console.WriteLine(MyList(Count))
Next
Console.ReadKey()

Page 28 of 38
2 D Array:
Pseudo Code:
DECLARE BOARD : ARRAY [ 0 : 2 , 0 : 3] OF INTEGER
Enter Data directly by programmer:
Board [0,0]  10
Board [0,1]  20
Board [0,2]  30
Board [0,3]  40
Board [1,0]  50
Board [1,1]  52
Board [1,2]  54
Board [1,3]  56
Board [2,0]  60
Board [2,1]  62
Board [2,2]  64
Board [2,3]  66

Page 29 of 38
VB.Net Code:
Dim Board(2, 3) As Integer ' 2 D Array Declarartion
Board(0, 0) = 10
Board(0, 1) = 20
Board(0, 2) = 30
Board(0, 3) = 40
Board(1, 0) = 50
Board(1, 1) = 52
Board(1, 2) = 54
Board(1, 3) = 56
Board(2, 0) = 60
Board(2, 1) = 62
Board(2, 2) = 64
Board(2, 3) = 66

Data entered in 2 D Array by user:


Pseudo Code:
DECLARE i , j : INTEGER
FOR i  0 TO 2
FOR j  0 TO 3
INPUT Board[i,j]
NEXt j
NEXT i
VB. Net Code:
Dim Board(2, 3) As Integer
Dim i, j As Integer

For i = 0 To 2
For j = 0 To 3
Console.WriteLine("Enter data in 2D Array")
Board(i, j) = Console.ReadLine()
Next
Next

Page 30 of 38
Initialize all elements of 2D Array Grid with ‘A’

Pseudo code:

DECALARE Grid : ARRAY [ 0:2 , 0 : 2] OF CHAR


DECLARE I , j : INTEGER

FOR i  0 TO 2
FOR j  0 TO 2
Grid [I,j]  0
NEXT j
NEXT i

VB.Net Code:
Dim Grid(2, 2) As Char

Dim i, j As Integer
For i = 0 To 2
For j = 0 To 2
Grid(i,j)='A'
Next
Next

Console.ReadKey()

Page 31 of 38
Record Type/ Structure:
TYPE Employee
DECALRE EName : STRING
DECLARE ESal : REAL
DECLARE DOA : DATE
END TYPE

Q. Declare a variable of type Employee.


Ans :
DECLARE Emp : Employee

Q. Assign value “Muhammad” to EName, 50.5 to


ESal and 11/11/2000 to DOA
Ans:
Emp.EName  “Muhammad”
Emp.ESal  50.5
Emp.DOA  #11/11/2000#

Page 32 of 38
VB.Net Code:
Module Module1
Structure Employee
Dim ENAme As String
Dim ESal As Single
Dim DOA As Date
End Structure

Sub Main()
Dim Emp As Employee
Emp.ENAme = "Muhammad"
Emp.ESal = 50.5
Emp.DOA = #11/11/2000#
Console.ReadKey()
End Sub

End Module
Q. Enter value by user into a record Structure/Type
And output.
DECLARE Emp : Employee
INPUT Emp.EName
INPUT emp.ESal
INPUT Emp.DO

OUTPUT Emp.EName
OUTPUT emp.ESal
OUTPUT Emp.DO

Page 33 of 38
VB.Net Code:
Module Module1
Structure Employee
Dim EName As String
Dim ESal As Single
Dim DOA As Date
End Structure

Sub Main()
Dim Emp As Employee
Console.WriteLine("Enter Employee Name")
Emp.EName = Console.ReadLine()
Console.WriteLine("Enter Employee Salary")
Emp.ESal = Console.ReadLine()
Console.WriteLine("Enter Employee Date of Appointment")
Emp.DOA = Console.ReadLine()

Console.WriteLine("Employee Name = " & Emp.EName)


Console.WriteLine("Employee Salary = " & Emp.ESal)
Console.WriteLine("Employee DOA = " & Emp.DOA)
Console.ReadKey()

End Sub
End Module

Page 34 of 38
FUNCTION:

Pseudo Code:

FUNCTION Sqr (n : INTEGER) RETURNS INTEGER

Sqr  n * n

END FUNCTION

Calling Function by User:

DECLARE Ans : INTEGER


Ans = Sqr (5) ‘ Function Calling statement

VB.Net Code:
Module Module1

Function Sqr(n As Integer) As Integer ' Function header


Sqr = n * n
End Function
Sub Main()
Dim ans As Integer
ans = Sqr(4) ' Function calling statement

Console.WriteLine("Its Square = " & ans)


Console.ReadKey()
End Sub

End Module

Page 35 of 38
Q. Make a Function with Identifier Sum
. It takes two values from user
. and returns its Sum.
e.g if user enters 4 and 5 then it returns 9

Pseudo Code:

FUNCTION Sum (Num1 : INTEGER , Num2 : INTEGER) RETURNS INTEGER

Sum  Num1 + Num2

END FUNCTION Method 2 : Call this function by User.


DECLARE Num1 , Num2 , Ans as INTEGER

Call this function by User. INPUT Num1 , Num2


DECLARE Ans : INTEGER Ans  Sum (Num1 , Num2)

Ans  Sum ( 4 , 5 ) OUTPUT “ Its Sum = “ & Ans

OUTPUT “ Its Sum = “ & Ans

VB.NET Code:

Module Module1
Function Sum(Num1 As Integer, Num2 As Integer)
Sum = Num1 + Num2
End Function
Sub Main()
Dim Ans As Integer
Ans = Sum(4, 5)
Console.WriteLine("Its Sum = " & Ans) ' Console.WriteLine("Its Sum = " & Ans)
Console.ReadKey()
End Sub

End Module

Page 36 of 38
VB.NET Code: Method 2

Module Module1
Function Sum(Num1 As Integer, Num2 As Integer)
Sum = Num1 + Num2
'Alternative methods
'Dim Add As Integer
' Add = Num1 + Num2
' Return Add / Sum = Add
End Function
Sub Main()
Dim Ans As Integer
Dim N1 As Integer
Dim N2 As Integer

Console.WriteLine("Please enter Num1")


N1 = Console.ReadLine()
Console.WriteLine("Please enter Num2")
N2 = Console.ReadLine()
Ans = Sum(N1, N2)
Console.WriteLine("Its Sum = " & Ans) ' Console.WriteLine("Its Sum = " & Sum(4,
5))
Console.ReadKey()
End Sub

End Module

Procedure:
PROCEDURE Sqr (n : INTEGER) ‘ Procedure Header
DECLARE Ans : INTEGER
Ans  n * n
OUTPUT Ans
END PROCEDURE

Calling Function by User:


2nd Method
CALL Sqr (3)
DECLARE Num : INTEGER
INPUT Num
CALL Sqr (Num)

Page 37 of 38
VB.Net Code:
Module Module1

Sub Sqr(n As Integer) ' Procedure Header


Dim ans As Integer
ans = n * n
Console.WriteLine("Its Square = " & ans)
End Sub

Sub Main()
Dim Num As Integer
Console.WriteLine("Enter a value to find its square")
Num = Console.ReadLine()
Call Sqr(Num)

Console.ReadKey()
End Sub

End Module

Page 38 of 38

You might also like