You are on page 1of 10

Write console based program to calculate simple interest.

Imports system.console
Module Module1
Sub main()
Dim P_saj, r_saj, t_saj, si_saj As Double
console.writeline("Enter Principle = ")
P_saj = CDbl(console.readline())

console.writeline("Enter Rate = ")


r_saj = CDbl(Console.Readline())

console.writeline("Enter Time = ")


t_saj = CDbl(console.Readline())

si_saj = P_saj * r_saj * t_saj / 100


console.writeline("Simple interset = " & si_saj)
readkey()

End Sub
End Module

Write console based program to implement concept of selection


logic.
Imports system.console

Module module1

Sub main()

Dim choice_saj As Integer

Dim num1 As Integer = 0

Dim num2 As Integer = 0

Dim result As Integer = 0

Do

console.writeline("=====MENU=====")

console.writeline(" 1. Addition ")

console.writeline(" 2. Substraction ")

console.writeline(" 3. Multiplication")
console.writeline(" 4. Division")

console.writeline("Enter choice = ")

choice_saj = console.readline()

Select Case choice_saj

Case 1

console.writeline("Number 1 =")

num1 = console.Readline()

console.writeline("Number 2 =")

num2 = console.Readline()

result = num1 + num2

Case 2

console.writeline("Number 1 =")

num1 = console.Readline()

console.writeline("Number 2 =")

num2 = console.Readline()

result = num1 - num2

Case 3

console.writeline("Number 1 =")

num1 = console.Readline()

console.writeline("Number 2 =")

num2 = console.Readline()

result = num1 * num2

Case 4

console.writeline("Number 1 =")

num1 = console.Readline()

console.writeline("Number 2 =")

num2 = console.Readline()

result = num1 / num2

Case Else

console.writeline("Invaild")
Stop

End Select

console.writeline("result = {0}" & result)

Loop While choice_saj > 0

End Sub

End Module

3) Write console based program to implement


concept of iteration logic.
3.1 Do while
.
Imports system.console

Module Do_While

Sub main()

Dim i_saj As Integer = 0

Do

console.writeline("Values : {0}", i_saj)

i_saj = i_saj + 1

Loop While i_saj <= 10

End Sub

End Module

3.2 while loop.


.
Imports system.console

Module whileLoop

Sub main()

Dim i_saj As Integer

While i_saj <= 10

console.writeline("Value : {0}", i_saj)

i_saj = i_saj + 1

End While

End Sub

End Module
3.3 For loop
Imports system.console

Module ForLoop

Sub main()

Dim i_saj As Integer

For i_saj = 1 To 10

console.writeline("Value : {0}", i_saj)

Next
.
readkey()

End Sub

End Module

3.4 For each next.

Imports system.console

Module For_Each_Next_saj

Dim arr() As Integer = {10, 11, 12, 13, 14, 15}

Dim i_saj, j_saj As Integer

Sub main()

console.writeline("Using For loop")

For i_saj = 0 To 4

console.writeline(arr(i_saj))

Next

console.writeline("Using For Each Next")

For Each j_saj In arr

console.writeline(j_saj)

Next

read()

End Sub

End Module
3.4 for loop with step
.
imports System.Console

Module module1_saj

Sub Main()

Dim i_saj As Integer

For i_saj = 2 To 10 Step 2

WriteLine("i=" & i_saj)

Next

Read()

End Sub

End Module

4) Write console based program using functions


(Addition,subtraction,Fact,Febonacci series,)
4.1 addition and substraction
Imports System
Module find_sum_saj
'create the sumoftwo() function and pass the parameters
Function sumOfTwo_saj(ByVal n1_saj As Integer, ByVal n2_saj As Integer)
'Define the local variable
Dim sum_saj As Integer = 0
sum_saj = n1_saj + n2_saj
Return sum_saj

End Function
Function SubtractionOfTwo_saj(ByVal n1_saj As Integer, ByVal n2_saj As
Integer) As Integer
'define the local variable
Dim subtract_saj As Integer
subtract_saj = n1_saj - n2_saj
Return subtract_saj
End Function
Sub main()
Dim a_saj As Integer = 50
Dim b_saj As Integer = 20
Dim total_saj, totall_saj As Integer
Console.WriteLine("First Number is : {0}", a_saj)
Console.WriteLine("second Number is : {0}", b_saj)
total_saj = sumOfTwo_saj(a_saj, b_saj)
totall_saj = SubtractionOfTwo_saj(a_saj, b_saj)
Console.WriteLine("sum of two number is : {0}", total_saj)
Console.WriteLine("Substraction of two number is : {0}", totall_saj)
Console.ReadKey()
End Sub
End Module
4.2 fact
Imports System

Module factorial_function_saj
'create A fact() Function
Function fact_saj(ByVal num_saj As Integer) As Integer
If (num_saj = 0) Then
Return 0
ElseIf (num_saj = 1) Then
Return 1
Else
Return num_saj * fact_saj(num_saj - 1)
End If
End Function
Sub Main()
' define the local variable as integer
Dim n_saj, f_saj As Integer
Console.WriteLine("Enter the number you want to calculate")
n_saj = Console.ReadLine() 'accept a number
f_saj = fact_saj(n_saj) 'call fact() function
Console.WriteLine("Factorial is: {0}", f_saj)
Console.WriteLine("Press any key to exit.......")
Console.ReadKey()
End Sub
End Module

4.3 febbonaci
Imports System.Console
Module Module1
' ByVal means that you are passing a copy of a variable to your Subroutine.
Function Fibonacci(ByVal n As Integer) As Integer
Dim Value1 As Integer = 0
Dim Value2 As Integer = 1
' Add up numbers.
For i As Integer = 0 To n - 1
Dim tempValue As Integer = Value1
Value1 = Value2
Value2 = tempValue + Value2
Next
Return Value1
End Function

Sub Main()

For i As Integer = 0 To 20

Console.Write(Fibonacci(i))

Console.Write(" ")
Next
End Sub
End Module

5) Write console based program using


procedure(prims no)or any own logic using sub
procedure
Imports system 'Assignement no. 4 -->add and substract using Sub pro
Module Sub_program
Sub sample()
console.writeline("*****Welcome*****")
End Sub
Sub circle_saj(ByVal r_saj As Integer) 'For finding area of circle
Dim area_saj As Integer
Const PI = 3.14
area_saj = PI * r_saj * r_saj
console.writeline("Area Of Circle is = {0}", area_saj)
End Sub

Sub SumOfTwo_saj(ByVal n1_saj As Integer, ByVal n2_saj As Integer)


Dim sum_saj As Integer = 0
sum_saj = n1_saj + n2_saj
console.writeline("Sum of two number is = {0}", sum_saj)
End Sub

Sub SubtractionOfTwo_saj(ByVal n1_saj As Integer, ByVal n2_saj As Integer)


Dim subtract_saj As Integer
subtract_saj = n1_saj - n2_saj
console.writeline("Substraction of Two number is : {0}", subtract_saj)
End Sub

Sub Multiplication_saj(ByVal n1_saj As Integer, ByVal n2_saj As Integer)


Dim multiply_saj As Integer
multiply_saj = n1_saj * n2_saj
console.writeline("Multiplication of two number is = {0}", multiply_saj)
End Sub

Sub Main()
Dim a_saj, b_saj, rad_saj As Integer
sample() 'calling function sample
console.writeline("Plz Enter the first number = ")
a_saj = console.Readline()
console.writeline("Enter second number = ")
b_saj = console.Readline()

SumOfTwo_saj(a_saj, b_saj)
SubtractionOfTwo_saj(a_saj, b_saj)
Multiplication_saj(a_saj, b_saj)

console.writeline("Enter the radius of circle = ")


rad_saj = console.readline()
circle_saj(rad_saj)
console.writeline("Press any key to exit .........")
console.readkey()

End Sub
End Module

6)Write console based program Using Arrays .(1,2,3


dimension array)
1-D array
Imports System.Console

'Assignment no.5 ---> 1-D Array


Imports system.console
Module Module1

Sub main()
Dim n_saj(10) As Integer ' n is an array of 11 integers '
Dim i_saj, j_saj As Integer
' initialize elements of array n '

For i_saj = 0 To 10
n_saj(i_saj) = i_saj + 100 ' set element at location i to i + 100
Next i_saj
' output each array element's value '

For j_saj = 0 To 10
Console.WriteLine("Element({0}) = {1}", j_saj, n_saj(j_saj))
Next j_saj
Console.ReadKey()
End Sub
End Module

2-D Array
Imports System
Module TwodimenArray_saj
Sub Main()
' Definition of 2 Dimensional Array
Dim intArray_saj(,) As Integer = {{5, 4}, {3, 2}, {4, 7}, {4, 5}}
Console.WriteLine(" Two Dimensional Arraye in VB.NET are")
For i_saj As Integer = 0 To 3
For j_saj As Integer = 0 To 1
Console.WriteLine("intArray[{0}, {1}] = {2}", i_saj, j_saj,
intArray_saj(i_saj, j_saj))
Next j_saj
Next i_saj
End Sub
End Module

3-D Array
Imports system.console
Module Module1 'Assignment no. 5 -->Multi-D array

Sub Main()
Dim array3D_saj As Integer(,,) = New Integer(1, 1, 2) {{{1, 2, 3}, {4, 5,
6}}, {{7, 8, 9}, {10, 11, 12}}}
Console.WriteLine("---Three Dimensional Array Elements---")

For i_saj As Integer = 0 To 2 - 1

For j_saj As Integer = 0 To 2 - 1

For k_saj As Integer = 0 To 3 - 1


Console.WriteLine("a[{0},{1},{2}] = {3}", i_saj, j_saj,
k_saj, array3D_saj(i_saj, j_saj, k_saj))

Next

Next

Next
Console.WriteLine("Press Enter Key to Exit..")
Console.ReadLine()
End Sub
End Module

7) Write console based program to


implement the concept of Exception
Handling.(Try Catch Finally)
Choose your choice any one from 7.1 and
7.2
7.1 Divide by zero

'Assignment 6 -->Divide by zero exception occur

Imports system.console
Module Modiule1
Sub division(ByVal num1_saj As Integer, ByVal num2_saj As Integer)
Dim result_saj As Integer
Try
result_saj = num1_saj \ num2_saj
Catch e_saj As DivideByZeroException
Console.WriteLine("Exception caught: {0}", e_saj)
Finally
Console.WriteLine("Result: {0}", result_saj)
End Try
End Sub
Sub Main()
division(16, 0)
Console.ReadKey()
End Sub
End Module
7.2 User define Exception
Module exceptionProg
Public Class TempIsZeroException : Inherits ApplicationException
Public Sub New(ByVal message As String)
MyBase.New(message)
End Sub
End Class
Public Class Temperature
Dim temperature_saj As Integer = 0
Sub showTemp()
If (temperature_saj = 0) Then
Throw (New TempIsZeroException("Zero Temperature found"))
Else
Console.WriteLine("Temperature: {0}", temperature_saj)
End If
End Sub
End Class
Sub Main()
Dim temp_saj As Temperature = New Temperature()
Try
temp_saj.showTemp()
Catch e As TempIsZeroException
Console.WriteLine("TempIsZeroException: {0}", e.Message)
End Try
Console.ReadKey()
End Sub
End Module

You might also like