0% found this document useful (0 votes)
4 views

Pseudocode Practice Vb

Uploaded by

mustajabffgaming
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Pseudocode Practice Vb

Uploaded by

mustajabffgaming
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

PSEUDOCODE PRACTICE VISUAL BASIC SHEET

Write Algorithms of following given Visual basic codes using these stated examples

Example: 1

Dim Total as integer = 0

DECLARE TOTAL: INTEGER = 0

Example: 2

Console.Writeline(“Input Number”)

Number = console.Readline

Number = INPUT “Input number ”

Or

INPUT “Input Number” , Number

Example: 3

Console.writeline(“Your number is ” & Number)

OUTPUT “ Your number is ” , Number

Example: 4

VB Code

IF number > 0 then


Console.writeline(“Positive”)
Else if number = 0 then
Console.writeline(“Exactly zero”)
Else
Console.writeline(“Negative”)
Algorithm

IF number > 0
then
OUTPUT “ Positive ”
Elseif number = 0
then
OUTPUT “ Exactly Zero ”
ELSE
OUTPUT = “Negative ”
ENDIF

NAVID SAQIB: +923334259883 1


PSEUDOCODE PRACTICE VISUAL BASIC SHEET

Example: 5

Dim Price(0 to 4) as integer

DECLARE Price [1: 5] : INTEGER


Example: 6

VB

Select Case number

Case Is = “A”

Price = 20

Case Is = “B”

Price = 30

Case Else

Console.writeline(“Input valid entry”)

END CASE

Algorithm

CASE OF number
“A”: Price = 20

“B”: Price = 30

OTHERWISE
OUTPUT = Input valid entry
ENDCASE

NAVID SAQIB: +923334259883 2


PSEUDOCODE PRACTICE VISUAL BASIC SHEET

VISUAL BASIC CODES ALGORITHMS


Dim name(0 To 1) as String
Dim price(0 To 1) As Integer
Dim category(0 To 1) As String
Dim qty(0 To 1) As Integer
Dim total(0 To 1) As Integer

For X = 0 To 1
Console.WriteLine("input product name")
name(X) = Console.ReadLine()
Console.WriteLine("enter quantity")
qty(X) = Console.ReadLine()
Console.WriteLine("There are only four catagories: A, B,
C, D")
Console.WriteLine("enter catagory")
category(X) = Console.ReadLine()

If category(X) = "A" Then


Price(X) = 150

ElseIf category(X) = "B” Then


price(X) = 250

ElseIf category(X) = "C" Then


price(X) = 350

ElseIf category(X) = "D" Then


Price = 450
End If
total(X) = price(X) * qty(X)
Next
For Y = 0 To 1
Console.WriteLine("Product name :" & name(Y) &
vbTab & "quantity :" & qty(Y) & vbTab & "Catagory is
:"&category(Y) & vbTab & "your total is " total (Y)
Next

NAVID SAQIB: +923334259883 3


PSEUDOCODE PRACTICE VISUAL BASIC SHEET

Dim data() As Integer = {34, 95, 12, 6}


Dim max As Integer = 0

For X = 0 To 3
If data(X) > max Then
max = data(X)

End If
Next
Console.WriteLine("max data is :" & max)

NAVID SAQIB: +923334259883 4


PSEUDOCODE PRACTICE VISUAL BASIC SHEET

Dim name(0 To 4) As String


Dim test1(0 To 4) As Integer
Dim test2(0 To 4) As Integer
Dim test3(0 To 4) As Integer
Dim avg(0 To 4) As Integer

For X = 0 To 4

Console.WriteLine("ïnput name")
name(X) = Console.ReadLine()
Console.WriteLine("input marks for test 1 ")
test1(X) = Console.ReadLine()
Console.WriteLine("input marks for test 2 ")
test2(X) = Console.ReadLine()
Console.WriteLine("input marks for test 3 ")
test3(X) = Console.ReadLine()
avg(X) = (test1(X) + test2(X) + test3(X)) / 3

Next

For Y = 0 To 4

Console.WriteLine("name of student :" & name(Y)


& " " & "test1 marks : " & test1(Y) & " " & "test2 marks
:" & test2(Y) & " " & "test3 marks :" & test3(Y) & " " & "
avgrage marks: " & avg(Y))
Next

NAVID SAQIB: +923334259883 5


PSEUDOCODE PRACTICE VISUAL BASIC SHEET

Dim price(0 To 1)
Dim qty(0 To 1) As Integer
Dim total(0 To 1) As Integer
Dim tvalue(0 To 1) As Integer
Dim gtotal(0 To 1) As Integer
Dim pname(0 To 1) As String

For X = 0 To 1

Console.WriteLine("input product name")


Pname(X) = Console.ReadLine()

Console.WriteLine("input quantity")
qty(X) = Console.ReadLine()

Console.WriteLine("input price")
price(X) = Console.Readline()

total(X) = qty(X) * price(X)

If total(X) < 150 Then

tvalue(X) = total(X) * 0.0


gtotal(X) = total(X) + tvalue(X)

ElseIf total(X) > 150 And total(X) < 500 Then

tvalue(X) = total(X) * 0.1


gtotal(X) = total(X) + tvalue(X)

ElseIf total(X) > 500 And total(X) < 1000 Then

tvalue(X) = total(X) * 0.16


gtotal(X) = total(X) + tvalue(X)

ElseIf total(X) > 1000 Then

tvalue(X) = total(X) * 0.2


gtotal(X) = total(X) + tvalue(X)

End If
Next

For Y = 0 To 1

NAVID SAQIB: +923334259883 6


PSEUDOCODE PRACTICE VISUAL BASIC SHEET

Console.WriteLine("product name is : " &


pname(Y) & " " & "quantity is :" & qty(Y) & " " & "tax
value is :" & tvalue(Y) & " " & "gross bill is :" & gtotal(Y))
Next

NAVID SAQIB: +923334259883 7


PSEUDOCODE PRACTICE VISUAL BASIC SHEET

Dim names(0 To 1) As String


Dim marks(0 To 1) As Integer

For X = 0 To 1

Console.WriteLine("Input name")
names(X) = Console.ReadLine()
Console.WriteLine("input marks")
marks(X) = Console.ReadLine()

Next

For Y = 0 To 1

Console.WriteLine("student names :" & names(Y) & "


" & " their marks are :" & marks(Y))
Next

NAVID SAQIB: +923334259883 8


PSEUDOCODE PRACTICE VISUAL BASIC SHEET

Dim product(0 To 1) As String

Dim qty(0 To 1) As Integer

Dim price(0 To 1) As Integer

Dim total(0 To 1) As Integer

For X = 0 To 1

Console.WriteLine("Input product name ")


product(X) = Console.ReadLine()

Console.WriteLine("enter price")
price(X) = Console.ReadLine()

Console.WriteLine("input quantity")
qty(X) = Console.ReadLine()

total(X) = qty(X) * price(X)

Next

For Y = 0 To 1
Console.WriteLine("Product name :" & product(Y)
& " " & " price is :" & price(Y) & " " & "quantity is :" &
qty(Y) & " " & "total is :" & total(Y))

Next
Dim noplate(0 To 1) As Integer
Dim speed(0 To 1) As Integer
Dim fine(0 To 1) As Integer

For X = 0 To 1

Console.WriteLine("input cars number plate :")


noplate(X) = Console.ReadLine()

Console.WriteLine("Input speed of the car:")


speed(X) = Console.ReadLine()

If speed(X) > 150 Then


fine(X) = 200

Else

NAVID SAQIB: +923334259883 9


PSEUDOCODE PRACTICE VISUAL BASIC SHEET

Console.WriteLine("You are driving on safe


speed")

End If

Next

For Y = 0 To 1
Console.WriteLine("Your car number is :" &
noplate(Y) & " " & "your speed was :" & speed(Y) & " " &
"You have to pay this amount as a fine :" & fine(Y))

Next
Dim names(0 To 9) As String

For X = 0 To 9

Console.WriteLine("Enter student names")


names(X) = Console.ReadLine()

Next

For Y = 0 To 9
Console.WriteLine("Students names are :" &
names(Y))

Next

NAVID SAQIB: +923334259883 10


PSEUDOCODE PRACTICE VISUAL BASIC SHEET

Dim grade(3, 4) As String


grade(0, 0) = "Student name"
grade(0, 1) = "Test 1 marks"
grade(0, 2) = "test 2 marks"
grade(0, 3) = "average marks"
grade(0, 4) = "Grade"

For R = 1 To 3

For c = 0 To 2

Console.WriteLine("input data at" & "(" & R & ","


& c & ")" & grade(0, c))
grade(R, c) = Console.ReadLine()

Next

Next

For A = 1 To 3

grade(A, 3) = (grade(A, 1) + grade(A, 2)) \ 2


If grade(A, 3) >= 90 Then
grade(A, 4) = "A*"
ElseIf grade(A, 3) < 90 And grade(A, 3) > 80 Then
grade(A, 4) = "A"
ElseIf grade(A, 3) < 80 And grade(A, 3) > 70 Then
grade(A, 4) = "B"
ElseIf grade(A, 3) < 70 And grade(A, 3) > 60 Then
grade(A, 4) = "C"
ElseIf grade(A, 3) < 60 And grade(A, 3) > 50 Then
grade(A, 4) = "D"
ElseIf grade(A, 3) < 50 And grade(A, 3) > 40 Then
grade(A, 4) = "E"
Else
grade(A, 4) = "FAIL"
End If
Next

For X = 0 To 3
For Y = 0 To 4

Console.Write(grade(X, Y) & vbTab)

Next
Console.WriteLine(“”)

NAVID SAQIB: +923334259883 11


PSEUDOCODE PRACTICE VISUAL BASIC SHEET

Next

NAVID SAQIB: +923334259883 12


PSEUDOCODE PRACTICE VISUAL BASIC SHEET

Dim data(3, 4) As String


data(0, 0) = "id"
data(0, 1) = "Name"
data(0, 2) = "Price"
data(0, 3) = "Quantity"
data(0, 4) = "Total"

For R = 1 To 3

For c = 0 To 3

Console.WriteLine("input data at" & "(" & R & ","


& c & ")" & data(0, c))
data(R, c) = Console.ReadLine()

Next

Next

For A = 1 To 3
data(A, 4) = data(A, 2) * data(A, 3)

Next

For X = 0 To 3

For Y = 0 To 4

Console.Write(data(X, Y) & vbTab)

Next
Console.WriteLine("")
Next

NAVID SAQIB: +923334259883 13


PSEUDOCODE PRACTICE VISUAL BASIC SHEET

Dim product(0 To 4) As String


Dim qty(4) As Integer
Dim price(4) As Integer
Dim total(4) As Integer
Dim GT As Integer

For x = 0 To 4
'input
Console.WriteLine("Enter product name:")
product(x) = Console.ReadLine
Console.WriteLine("Enter {0} Qty:", product(x))
qty(x) = Console.ReadLine
'validation
While qty(x) < 0 Or qty(x) > 30
Console.WriteLine("Error : Wrong entry ")
Console.WriteLine("Re Enter {0} Qty:",
product(x))
qty(x) = Console.ReadLine
End While
Console.WriteLine("Enter {0} Price:", product(x))
price(x) = Console.ReadLine
'validation
While price(x) < 0 Or price(x) > 500
Console.WriteLine("Error : Wrong entry ")
Console.WriteLine("Re Enter {0} Price:",
product(x))
price(x) = Console.ReadLine
End While
'process
total(x) = qty(x) * price(x)
GT = GT + total(x)
Next
Console.WriteLine()
Console.WriteLine("sr no" & vbTab & "product" &
vbTab & "Qty" & vbTab & "Price" & vbTab & "Total")
For y = 0 To 4
Console.WriteLine(y & vbTab & product(y) & vbTab
& qty(y) & vbTab & price(y) & vbTab & total(y))
Next
Console.WriteLine()
Console.WriteLine("Grand total is : " & GT)
Console.ReadKey()

NAVID SAQIB: +923334259883 14


PSEUDOCODE PRACTICE VISUAL BASIC SHEET

Dim num As Integer

Sub Main()
Console.Write("Enter a Number : ")
num = Console.ReadLine()

If (num Mod 2 = 0) Then


Console.WriteLine("{0} is even", num)
Else
Console.WriteLine("{0} is odd", num)
End If
'This line is to hold the output screen
Console.ReadKey()
End Sub

Dim p, n, i As Integer
p=1
Console.WriteLine("Prime Numbers are : ")
For n = 1 To 100
For i = 2 To n - 1

If n Mod i = 0 Then
p=0
Exit For
Else
p=1
End If
Next

If p = 1 Then
Console.WriteLine("Prime numbers are : " & n)
End If
Next

NAVID SAQIB: +923334259883 15


PSEUDOCODE PRACTICE VISUAL BASIC SHEET

NAVID SAQIB: +923334259883 16

You might also like