0% found this document useful (0 votes)
3 views50 pages

Programing

Uploaded by

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

Programing

Uploaded by

mikekimbely
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Module Module1

Sub Main()

Dim max, index As Integer

Dim num() = {14, 15, 38, 53, 685, 12, 40, 0, 98, 74, 32, 9, 39, 25, 87, 8, 658, 129, 45, 5}

max = num(0)

For k = 0 To 19

If num(k) > max Then

max = num(k)

index = k

End If

Next

[Link]("the hightest number is " & max & "index is " & index)

[Link]()

End Sub

End Module

CONSOLE TO WRITE NAMES

Module Module1

Sub Main()

Dim names(3) As String

[Link]("enter names")

For i = 0 To 3

names(i) = [Link]

Next

[Link](" " & vbTab)


For k = 0 To 3

[Link](names(k))

Next

[Link]()

End Sub

End Module

USED TO FIND AVERAGE

Module Module1

Sub Main()

Dim marks(9) As Double

Dim sum As Double = 0

For i = 0 To 9

[Link]("enter mark " & (i + 1) & "i")

marks(i) = [Link]([Link]())

sum += marks(i)

Next

[Link]("average= " & (sum / 10))

[Link]()

End Sub
End Module

PALINDROME

Module Module1

Sub Main()

[Link]("enter name")

Dim name As String

If name = StrReverse(name) Then

[Link]("is a palindrome")

Else

[Link]("is not a palindrome")

End If

[Link]()

End Sub

End Module

In DISCENDING OF OF THE TEMPS

Module Module1

Sub Main()

Dim temp() = {24, 21, 19, 32, 45, 49, 9, 56, 30}

Dim i As Integer

[Link](temp)

[Link]("the temp in descending order ")

For Each i In temp


[Link](i)

Next

[Link]()

End Sub

End Module

Q3a.

Module Module1

Sub Main()

Dim fib(149) As Double

fib(0) = 0

fib(1) = 1

For i = 2 To 149

fib(i) = (fib(i - 1) + fib(i - 2))

Next

For Each m In fib


[Link](m & " ")

Next

[Link]()

End Sub

End Module

Q3d.
Module Module1

Sub Main()
Dim alphabet(19) As Char
For i = 0 To 19
alphabet(i) = Chr(65 + i)
Next
For Each i In alphabet
[Link]()
Next
[Link]()
End Sub
End Module

Fanction-
-Are used to reduce number of lines

Module Module1
Function sumfunction(num1 As Integer, num2 As Integer) As Integer
Dim sum As Integer
sum = num1 + num2
Return sum
End Function
Sub Main()
Dim num1, num2, sum As Integer
[Link]("enter first number")
num1 = [Link]
[Link]("enter second number")
num2 = [Link]
sum = sumfunction(num1, num2)
[Link]("the sum is " & sum)
[Link]()
End Sub

End Module
Write a program that calculate are of a circle using function

Module Module1
Function calarea(ByVal radius As Double) As Double
calarea = 3.14 * radius * radius
End Function
Sub Main()
[Link]("enter radius")
Dim radius As Double = [Link]
[Link]("the are of a circle:" & calarea(radius))
[Link]()
End Sub

End Module

Using function to write a program that calculate bonus basing on


performance and salary
Module Module1
Function bonus(performance, salary)
Select Case performance
Case 1
bonus = salary * 0.1
Case 2, 3
bonus = salary * 0.09
Case 4 To 6
bonus = salary * 0.07
Case Is > 8
bonus = 100
Case Else
bonus = 0
End Select
End Function
Sub Main()
[Link]("enter performation ")
Dim performance As Integer = [Link]
Dim salary As Integer = [Link]
[Link]("the bonus is:" & bonus(performance, salary))
[Link]()
End Sub

End Module

Calculate MBI
Module Module1
Function BMI(height, weight) As Integer
Dim result As Integer
result = height / (weight * height)
End Function
Sub Main()
[Link]("enter weight")
Dim weight As Integer = [Link]
[Link]("enter height:" & calBMI(height,weight)
[Link]()

End Sub

End Module

TO FIND FACTORAL OF A NUMBER

Module Module1
Function factoral(n)
If n = 0 Then
Return 1
Else
Return n * factoral(n - 1)
End If
End Function
Sub Main()
[Link]("input number")
Dim n As Integer = [Link]
[Link]("the factorial of :" & n & "is" & factoral(n))
[Link]()
End Sub

End Module
Fibonacci series
If I <=1 then
Return i
Else
Return fub (n-1)+ fub(n-2)
End function

write a promgram to add 2 num


Module Module1
Function addnumbers(a, b)
Return (a + b)
End Function
Sub Main()
Dim result As Integer = addnumbers(5, 7)
[Link]("sum is: " & result)
[Link]()
End Sub

End Module

Module Module1
Function square(a, b)
Return (a * b)
End Function
Sub Main()
[Link]("enter squar:")
Dim result As Integer = square(5, 7)
[Link]("square is: " & result)
[Link]()

End Sub

End Module

TO FIND EVENNUMBERS
Module Module1
Function evennumbers(number As Integer) As Integer
If number Mod 2 = 0 Then
Return True
Else
Return False
End If
End Function
Sub Main()
[Link](evennumbers(10))
[Link]()
End Sub

End Module

Nov 2024 SOFTWARE ENGINEERING

q.1 NESTED IF statement


start

Sum=30
is
true
>31 Print true

no

Print false stop

[Link]

START

Input first
number

Input sec
number

Average=first
num+sec
num/2

stop

C.
Q 2. A PROGRAM READS 6 MARKS USING A LOOPING STRUCTURE AND STORE THEM IN A AN ARRAY.
THE PROGRAM ADDS THE MARKS AND OUTPUT THE AVERAGE OF THE MARKS. (10)

Module Module1

Sub Main()

Dim marks(5) As Double

Dim sum As Double = 0

For i = 0 To 5

[Link]("enter mark " & (i + 1) & "i")

marks(i) = [Link]([Link]())

sum += marks(i)

Next

[Link]("average= " & (sum / 6))

[Link]()

End Sub

End Module

Q3

Module Module1

Sub Main()

Dim name As Integer

[Link]("enter name")
If name = StrReverse(name) Then

[Link]("the name is")

End If

[Link]("an error message")

[Link]()

End Sub

End Module

SECTION B

Q4.

A) THE TYPES OF ERRORS AREA:


1. Error 1:
If x > H then x = H

2. Error 2:
Print H is inside the loop

3. Error 3:
Until c < 20

B. Module Module1

Sub Main()
Dim max, index As Integer
Dim num() = {0, 19, 2, 3, 40, 25, 6, 79, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19}
max = num(0)
For k = 0 To 19
If num(k) > max Then
max = num(k)
index = k
End If
Next
[Link]("the hightest number is " & max & "index is " & index)
[Link]()
End Sub

End Module

[Link] ENGLISH LANGUAGE


(c) Algorithm
Start
Set h = 0
Set c = 0
Repeat
Input x
If x > h then
h=x
Endif
c=c+1
Until c = 20
Output b
Stop

Q6.

Public Class Form1

Private Sub display_Click(sender As Object, e As EventArgs) Handles [Link]

Dim name, grade As String

Dim mark As Integer

name = [Link]

mark = [Link]

If mark >= 70 & mark <= 100 Then

grade = "Distinction"

ElseIf mark >= 60 Then

grade = "Credit"

ElseIf mark >= 50 Then

grade = "Pass"

End If
grade = "Fail"

End Sub

End Class

Q8.
Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link]

Dim temp As Integer

Dim input As String

temp = [Link]

If temp is =<1 then

input = "frezzing"

End If

If temp >= 20 Then

input = ("hot")

End If

temp >20

End Sub

End Class

vB program codes revision


Q1
Module Module1

Sub Main()
Dim names(3) As String
[Link]("enter names")
For i = 0 To 3
names(i) = [Link]
Next
[Link](" " & vbTab)
For k = 0 To 3
[Link](names(k))
Next
[Link]()
End Sub

End Module

Q2
vbnetModule Module1
Module Module1

Sub Main()
Dim names() As String = {"John", "Mary", "David"}
For i As Integer = [Link] - 1 To 0 Step -1
[Link](names(i))
Next
End Sub

End Module

2. Store student names and grades, display average gradevbnetModule Module2


Sub Main()
Dim students(4, 1) As String
For i As Integer = 0 To 4
[Link]("Enter student name: ")
students(i, 0) = [Link]()
[Link]("Enter grade: ")
students(i, 1) = [Link]()
Next
For i As Integer = 0 To 4
Dim sum As Integer = [Link](students(i, 1))
[Link]($"Average grade for {students(i, 0)} is {sum}")
Next
End Sub
End Module
3. Populate array with random numbers, find maximumvbnetModule Module3
Sub Main()
Dim numbers(9) As Integer
Dim rnd As New Random()
For i As Integer = 0 To 9
numbers(i) = [Link](1, 101)
Next
[Link]($"Maximum value: {[Link]()}")
End Sub
End Module
4. Convert string to uppercasevbnetModule Module4
Sub Main()
[Link]("Enter a string: ")
Dim input As String = [Link]()
[Link]([Link]())
End Sub
End Module
5. Replace character in stringvbnetModule Module5
Sub Main()
[Link]("Enter a string: ")
Dim input As String = [Link]()
[Link]("Enter character to replace: ")
Dim oldChar As Char = [Link]()
[Link]("Enter new character: ")
Dim newChar As Char = [Link]()
Dim result As String = [Link](oldChar, newChar)
[Link](result)
End Sub
End Module
6. Recursion to calculate factorialvbnetModule Module6
Sub Main()
[Link]("Enter a number: ")
Dim num As Integer = [Link]([Link]())
[Link]($"Factorial: {Factorial(num)}")
End Sub
Function Factorial(n As Integer) As Integer
If n = 0 Then
Return 1
Else
Return n * Factorial(n - 1)
End If
End Function
End Module
7. Binary search algorithmvbnetModule Module7
Sub Main()
Dim arr() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9}
[Link]("Enter target: ")
Dim target As Integer = [Link]([Link]())
Dim result As Integer = BinarySearch(arr, target)
If result <> -1 Then
[Link]($"Found at index {result}")
Else
[Link]("Not found")
End If
End Sub
Function BinarySearch(arr() As Integer, target As Integer) As Integer
Dim low As Integer = 0
Dim high As Integer = [Link] - 1
While low <= high
Dim mid As Integer = (low + high) \ 2
If arr(mid) = target Then
Return mid
ElseIf arr(mid) < target Then
low = mid + 1
Else
high = mid - 1
End If
End While
Return -1
End Function
End Module
8. Count words in sentencevbnetModule Module8
Sub Main()
[Link]("Enter a sentence: ")
Dim sentence As String = [Link]()
Dim words() As String = [Link](" ")
[Link]($"Word count: {[Link]}")
End Sub
End Module
9. Display multiplication tablevbnetModule Module9
Sub Main()
[Link]("Enter a number: ")
Dim num As Integer = [Link]([Link]())
For i As Integer = 1 To 10
[Link]($"{num} x {i} = {num * i}")
Next
End Sub
End Module
10. Decimal to binary and backvbnetModule Module10
Sub Main()
[Link]("Enter a decimal number: ")
Dim dec As Integer = [Link]([Link]())
Dim bin As String = [Link](dec, 2)
[Link]($"Binary: {bin}")
Dim backDec As Integer = Convert.ToInt32(bin, 2)
[Link]($"Back to decimal: {backDec}")
End Sub
End Module
11. Decimal to hex and backvbnetModule Module11
Sub Main()
[Link]("Enter a decimal number: ")
Dim dec As Integer = [Link]([Link]())
Dim hex As String = [Link](dec, 16)
[Link]($"Hex: {hex}")
Dim backDec As Integer = Convert.ToInt32(hex, 16)
[Link]($"Back to decimal: {backDec}")
End Sub
End Module
12. String to ASCII codes and backvbnetModule Module12
Sub Main()
[Link]("Enter a string: ")
Dim input As String = [Link]()
Dim asciiCodes As String = ""
For Each c As Char In input
asciiCodes &= Asc(c) & " "
Next
[Link]($"ASCII codes: {asciiCodes}")
' Back conversion omitted for brevity
End Sub
End Module
13. Add binary numbersvbnetModule Module13
Sub Main()
[Link]("Enter binary number 1: ")
Dim bin1 As String = [Link]()
[Link]("Enter binary number 2: ")
Dim bin2 As String = [Link]()
Dim sum As Integer = Convert.ToInt32(bin1, 2) + Convert.ToInt32(bin2, 2)
Dim binSum As String = [Link](sum, 2)
[Link]($"Binary sum: {binSum}")
End Sub
End Module

ARRAY QUESTIONS

1. Store 5 integers, input values, display sumvbnetModule Module1


Sub Main()
Dim numbers(4) As Integer
Dim sum As Integer = 0

For i As Integer = 0 To 4
[Link]("Enter number " & (i + 1) & ": ")
numbers(i) = Convert.ToInt32([Link]())
sum += numbers(i)
Next

[Link]("Sum of array elements: " & sum)


[Link]()
End Sub
End Module
2. Store 3 names, display in reverse ordervbnetModule Module1
Sub Main()
Dim names() As String = {"John", "Mary", "David"}

[Link]("Names in reverse order:")


For i As Integer = [Link] - 1 To 0 Step -1
[Link](names(i))
Next
[Link]()
End Sub
End Module
3. 2D array for student names & grades, display average gradevbnetModule
Module1
Sub Main()
Dim students(4, 1) As String
Dim average As Double
' Input names and grades
For i As Integer = 0 To 4
[Link]("Enter student name: ")
students(i, 0) = [Link]()
[Link]("Enter grade: ")
students(i, 1) = [Link]()
Next

' Display average grade


For i As Integer = 0 To 4
average = [Link](students(i, 1))
[Link](students(i, 0) & "'s average grade: " & average)
Next
[Link]()
End Sub
End Module
4. Array of 10 random numbers, find maximumvbnetModule Module1
Sub Main()
Dim numbers(9) As Integer
Dim random As New Random()
Dim max As Integer

' Populate with random numbers


For i As Integer = 0 To 9
numbers(i) = [Link](1, 101)
Next

max = [Link]()
[Link]("Maximum value in array: " & max)
[Link]()
End Sub
End Module
5. String array of colors, display with indexvbnetModule Module1
Sub Main()
Dim colors() As String = {"Red", "Green", "Blue", "Yellow"}

For i As Integer = 0 To [Link] - 1


[Link]("Index " & i & ": " & colors(i))
Next
[Link]()
End Sub
End Module
STRING MANIPULATION QUESTIONS
1. Convert input string to uppercasevbnetModule Module1
Sub Main()
[Link]("Enter a string: ")
Dim input As String = [Link]()
[Link]("Uppercase: " & [Link]())
[Link]()
End Sub
End Module
2. Remove comma & space from “Hello, World!”vbnetModule Module1
Sub Main()
Dim str As String = "Hello, World!"
str = [Link](", ", "")
[Link]("Result: " & str)
[Link]()
End Sub
End Module
3. Check if string contains a substringvbnetModule Module1
Sub Main()
[Link]("Enter a string: ")
Dim input As String = [Link]()
[Link]("Enter substring to search: ")
Dim subStr As String = [Link]()

If [Link](subStr) Then
[Link]("Substring found!")
Else
[Link]("Substring not found.")
End If
[Link]()
End Sub
End Module
4. Extract first 3 characters from “abcdefg”vbnetModule Module1
Sub Main()
Dim str As String = "abcdefg"
Dim result As String = [Link](0, 3)
[Link]("First 3 characters: " & result)
[Link]()
End Sub
End Module
1. Greeting Program
Module Module1
Sub Main()
[Link]("Enter your name: ")
Dim name As String = [Link]()
[Link]("Hello, " & name & "!")
End Sub
End Module

2. Sum of Two Numbers


Module Module1
Sub Main()
[Link]("Enter first number: ")
Dim num1 As Integer = [Link]([Link]())
[Link]("Enter second number: ")
Dim num2 As Integer = [Link]([Link]())
[Link]("Sum: " & (num1 + num2))
End Sub
End Module

3. Password Checker
Module Module1
Sub Main()
[Link]("Enter password: ")
Dim password As String = [Link]()
If password = "password123" Then
[Link]("Password correct!")
Else
[Link]("Password incorrect!")
End If
End Sub
End Module

4. Voting Eligibility
Module Module1
Sub Main()
[Link]("Enter your age: ")
Dim age As Integer = [Link]([Link]())
If age >= 18 Then
[Link]("You are eligible to vote.")
Else
[Link]("You are not eligible to vote.")
End If
End Sub
End Module

5. Grade Point Converter


Module Module1
Sub Main()
[Link]("Enter grade (A, B, C, D, F): ")
Dim grade As String = [Link]().ToUpper()
Select Case grade
Case "A"
[Link]("Grade point: 4")
Case "B"
[Link]("Grade point: 3")
Case "C"
[Link]("Grade point: 2")
Case "D"
[Link]("Grade point: 1")
Case "F"
[Link]("Grade point: 0")
Case Else
[Link]("Invalid grade")
End Select
End Sub
End Module
6. Coin Toss Game
Module Module1
Dim rnd As New Random()
Sub Main()
Dim toss As Integer = [Link](0, 2) '0=heads, 1=tails
[Link]("Guess (heads or tails): ")
Dim guess As String = [Link]().ToLower()
If (guess = "heads" And toss = 0) Or (guess = "tails" And toss = 1) Then
[Link]("You guessed correctly!")
Else
[Link]("You guessed incorrectly!")
End If
End Sub
End Module

7. Even/Odd Checker
Module Module1
Sub Main()
[Link]("Enter a number: ")
Dim num As Integer = [Link]([Link]())
If num Mod 2 = 0 Then
[Link]("The number is even.")
Else
[Link]("The number is odd.")
End If
End Sub
End Module

8. Minor or Adult Checker


Module Module1
Sub Main()
[Link]("Enter name: ")
Dim name As String = [Link]()
[Link]("Enter age: ")
Dim age As Integer = [Link]([Link]())
If age < 18 Then
[Link](name & ", you are a minor.")
Else
[Link](name & ", you are an adult.")
End If
End Sub
End Module

9. Rock-Paper-Scissors Game
Module Module1
Dim rnd As New Random()
Sub Main()
[Link]("Enter choice (rock, paper, scissors): ")
Dim userChoice As String = [Link]().ToLower()
Dim choices() As String = {"rock", "paper", "scissors"}
Dim compChoice As String = choices([Link](0, 3))
[Link]("Computer chose: " & compChoice)
If userChoice = compChoice Then
[Link]("It's a tie!")
ElseIf (userChoice = "rock" And compChoice = "scissors") Or
(userChoice = "paper" And compChoice = "rock") Or
(userChoice = "scissors" And compChoice = "paper") Then
[Link]("You win!")
Else
[Link]("You lose!")
End If
End Sub
End Module

3. Stream File Read/Write Program


Imports [Link]
Module Module1
Sub Main()
Dim filePath As String = "[Link]"
' Writing to file
Using writer As StreamWriter = New StreamWriter(filePath)
[Link]("Hello, file!")
End Using
' Reading from file
Using reader As StreamReader = New StreamReader(filePath)
[Link]([Link]())
End Using
End Sub
End Module

1️⃣ Replace a specific character in a stringvbModule Module1


Sub Main()
[Link]("Enter a string: ")
Dim inputStr As String = [Link]()
[Link]("Enter the character to replace: ")
Dim oldChar As Char = [Link]()(0)
[Link]("Enter the replacement character: ")
Dim newChar As Char = [Link]()(0)
Dim modifiedStr As String = [Link](oldChar, newChar)
[Link]("Modified string: " & modifiedStr)
End Sub
End Module
2️⃣ Declare “Hello, World!” string, trim spaces & displayvbModule Module2
Sub Main()
Dim str As String = " Hello, World! "
str = [Link]()
[Link](str)
End Sub
End Module
3️⃣ Check if a string is a palindromevbModule Module3
Sub Main()
[Link]("Enter a string: ")
Dim input As String = [Link]()
Dim reversed As String = New String([Link]().ToArray())
If input = reversed Then
[Link]("The string is a palindrome.")
Else
[Link]("The string is NOT a palindrome.")
End If
End Sub
End Module
4️⃣ Read a file and display its contents in a message boxvbImports
[Link]
Module Module4
Sub Main()
[Link]("Enter file name: ")
Dim fileName As String = [Link]()
Dim content As String = [Link](fileName)
[Link](content, "File Content")
End Sub
End Module
5️⃣ Create a text file “[Link]” and write “Hello, World!”vbModule Module5
Sub Main()
Dim fileName As String = "[Link]"
[Link](fileName, "Hello, World!", False)
[Link]("File created & text written.")
End Sub
End Module
6️⃣ Search for a string in a file & show line numbervbModule Module6
Sub Main()
[Link]("Enter file name: ")
Dim fileName As String = [Link]()
[Link]("Enter search string: ")
Dim searchStr As String = [Link]()
Dim lines() As String = [Link](fileName)
For i As Integer = 0 To [Link] - 1
If lines(i).Contains(searchStr) Then
[Link]($"Found on line {i + 1}: {lines(i)}")
Exit For
End If
Next
End Sub
End Module
7️⃣ Count lines in a text filevbModule Module7
Sub Main()
[Link]("Enter file name: ")
Dim fileName As String = [Link]()
Dim lineCount As Integer = [Link](fileName).Length
[Link]($"Total lines: {lineCount}")
End Sub
End Module
8️⃣ Append a string to a filevbModule Module8
Sub Main()
[Link]("Enter file name: ")
Dim fileName As String = [Link]()
[Link]("Enter string to append: ")
Dim appendStr As String = [Link]()
[Link](fileName, appendStr, True)
[Link]("String appended.")
End Sub
End Module
9️⃣ Read file into an array & display in a list boxvbImports [Link]
Module Module9
Sub Main()
[Link]("Enter file name: ")
Dim fileName As String = [Link]()
Dim lines() As String = [Link](fileName)
Dim listBox As New ListBox()
[Link](lines)
For Each item In [Link]
[Link](item)
Next
End Sub
End Module
🔟 Replace a string in a file & save changesvbModule Module10
Sub Main()
[Link]("Enter file name: ")
Dim fileName As String = [Link]()
[Link]("Enter search string: ")
Dim searchStr As String = [Link]()
[Link]("Enter replacement string: ")
Dim replaceStr As String = [Link]()
Dim content As String = [Link](fileName)
content = [Link](searchStr, replaceStr)
[Link](fileName, content, False)
[Link]("File updated.")
End Sub
End Module
Advanced Level
1️⃣ Recursive factorial calculationvbModule Advanced1
Function Factorial(n As Integer) As Integer
If n <= 1 Then
Return 1
Else
Return n * Factorial(n - 1)
End If
End Function

Sub Main()
[Link]("Enter a number: ")
Dim num As Integer = [Link]([Link]())
[Link]($"Factorial of {num} is {Factorial(num)}")
End Sub
End Module
2️⃣ Binary search in a sorted arrayvbModule Advanced2
Function BinarySearch(arr() As Integer, target As Integer) As Integer
Dim low As Integer = 0
Dim high As Integer = [Link] - 1
While low <= high
Dim mid As Integer = (low + high) \ 2
If arr(mid) = target Then Return mid
If arr(mid) < target Then low = mid + 1 Else high = mid - 1
End While
Return -1
End Function

Sub Main()
Dim sortedArray() As Integer = {1, 3, 5, 7, 9}
[Link]("Enter target number: ")
Dim target As Integer = [Link]([Link]())
Dim result As Integer = BinarySearch(sortedArray, target)
If result >= 0 Then
[Link]($"Element found at index {result}.")
Else
[Link]("Element not found.")
End If
End Sub
End Module

CREATE TABLE StudentDetails (


StudentID INTEGER PRIMARY KEY,
Surname CHAR(20),
FirstName CHAR(20),
Class CHAR(2)
);

Imports [Link]
Public Class Form1

Dim con As New OleDbConnection


Dim cmd As OleDbCommand
Dim da As OleDbDataAdapter
Dim dt As New DataTable

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]

[Link] = "Provider=[Link].12.0;Data
Source=[Link]"

[Link]()

Dim sql As String


sql = "SELECT Surname, FirstName FROM Students WHERE Class='1A' AND
FeesPaid < 100"

da = New OleDbDataAdapter(sql, con)

[Link](dt)

[Link] = dt

[Link]()

End Sub

End Class
Module Module1

Sub Main()

Dim age As Integer

[Link]("Enter Age: ")


age = [Link]()

If age >= 13 And age <= 19 Then


[Link]("You are a teenager")
Else
[Link]("You are not a teenager")
End If

[Link]()

End Sub

End Module

1b.
Module Module1

Sub Main()

Dim age As Integer

[Link]("Enter Age: ")


age = [Link]()

If age >= 13 And age <= 19 Then


[Link]("You are a teenager")
Else
[Link]("You are not a teenager")
End If

[Link]()
End Sub

End Module

2. Console program that accepts two numbers and displays the


bigger number or equal
Module Module1

Sub Main()

Dim num1 As Integer


Dim num2 As Integer

[Link]("Enter first number: ")


num1 = [Link]()

[Link]("Enter second number: ")


num2 = [Link]()

If num1 > num2 Then


[Link]("Bigger number is " & num1)

ElseIf num2 > num1 Then


[Link]("Bigger number is " & num2)

Else
[Link]("Numbers are equal")

End If

[Link]()

End Sub

End Module

3. Console program that displays your name, candidate number


and school
Module Module1

Sub Main()
[Link]("Name: Mckay MTC")
[Link]("Candidate Number: 3048")
[Link]("Hlangabeza High School")

[Link]()
End Sub
End Module

Inputs odd and even numbers


Module Module1

Sub Main()
Dim n As Integer
Dim oddsum As Integer = 0
Dim evensum As Integer = 0
n = InputBox("enter a number ")
Do While n >= 0
If n Mod 2 = 0 Then
evensum = evensum + n
Else
oddsum = oddsum + n
End If
n=n-1
Loop
[Link]("the sum of all even numbers is :" & evensum)
[Link]("the sum of oddnumber is" & oddsum)
[Link]()
End Sub

End Module

Program using iteration


Module Module1

Sub Main()
Dim n, c As Integer
Dim f As Long
c=1
F=1
n = InputBox("enter a number ")
F=F*c
c=c+1
loop
[Link]("factorial of number" & n & "is" & f)
[Link]()
End Sub

End Module

Write a number that’s gets a number from a user table and displays table from
number
Module Module1
Sub Main()
Dim n, i As Integer
n = InputBox("enter number:", "table")
i=1
Do
[Link](n & "*" & i & "=" & n * i)
i=i+1
Loop While i <= 10
[Link]()
End Sub

End Module

A program that inputs starting and ending and display all even numbers in a given
range
Module Module1

Sub Main()
Dim s, e, n As Integer
s = InputBox(" enter start number")
e = InputBox("enter end number")
n=s
Do
If n Mod 2 <> 0 Then
[Link](n)
End If
n=n+1
Loop Until n > e
[Link]()
End Sub

End Module

A program that displays Ist 5 oddnumbers


Module Module1

Sub Main()
Dim n As Integer
For n = 1 To 10 Step 2
[Link](n)
Next
[Link]()
End Sub

End Module
Arrays 1D
Write a program that using 1D
Syntax
Dim <array name>length as <type>

Module Module1

Sub Main()
Dim marks(4) As Integer
For i = 0 To 4
marks(i) = InputBox("enter marks", "marks")

Next
For i = 0 To 4
[Link]("value at index " & i & "is" & marks(i))

Next
[Link]()
End Sub

End Module
Program that gets a number from a user and stores them in a array and displays
the average
Module Module1

Sub Main()
Dim num(4) As Integer
Dim sum As Integer = 0
For i = 0 To 4
num(i) = InputBox("enter number", "number")

Next
For i = 0 To 4
sum = sum + num(i)
Next

[Link]("the sum is:" & sum)


[Link]("the avarage is:" & sum / 5)

[Link]()

End Sub

End Module
Searching a term in a array
Qn1. Write a program that stores 5 values in a array and finds it using search
Module Module1

Sub Main()
Dim num(5) As Integer
Dim d, m As Integer
m = -1
num(0) = 10
num(1) = 20
num(2) = 30
num(3) = 40
num(4) = 50
d = InputBox("enter a number to find:", "searching ")
For i = 0 To 4
If num(i) = d Then
m=i
Exit For

End If
Next
If m = -1 Then
[Link]("value not found ")
Else
[Link]("value is at index:" & m)

End If
[Link]()
End Sub

End Module

For sorting
Module Module1

Sub Main()
Dim array(4) As Integer
Dim temp As Integer
Dim min As Integer
For i = 0 To 4
array(i) = InputBox("enter number", "sort")
Next
For i = 0 To 3
min = i

For j = i + 1 To 4
If array(j) < array(min) Then
min = j
End If
Next
If min <> i Then
temp = array(i) = array(min)
array(min) = temp
End If
[Link]("sorted array ia as follows")
For n = 0 To 4
[Link](array(i))
Next
[Link]()
End Sub

End Module

You might also like