Wednesday, 18 September 2013

Assignment 4 for print of vb.net

Assignmebnt No. – 04
 
Program on Innterface :-
 
Module IntefaceExamplekb
 
    Sub Main()
        Dim obj As New Class2
        obj.add()
        obj.pro()
        Console.ReadLine()
    End Sub
 
End Module
 
 
Interface in1
    Sub add()
End Interface
 
Interface in2
    Sub pro()
End Interface
 
Interface in3
    Inherits in1, in2
End Interface
 
 
Public Class Class2 : Implements in3
 
    Public Sub add() Implements in1.add
        Console.WriteLine("Add Function...")
    End Sub
 
    Public Sub pro() Implements in2.pro
        Console.WriteLine("Product Function...")
    End Sub
End Class
 
 
Output :-
 


Program on Exception Handling :-
 
Module ExecptionHandlingExamplekb
 
    Sub Main()
        Dim a, b, c As Integer
        Console.Write("Enter a and b :")
        a = CInt(Console.ReadLine)
        b = CInt(Console.ReadLine)
        Console.WriteLine("a = " + a.ToString())
        Console.WriteLine("b = " + b.ToString())
        Console.WriteLine()
        Try
            c = a \ b
            Console.WriteLine("c = " + c.ToString())
        Catch ex As Exception
            Console.WriteLine("Exception occured: " + ex.Message())
        End Try
        Console.ReadLine()
    End Sub
 
End Module
 
Output :-

Assignment 3 for print of vb.net



Assignment No. – 03

Program on Class & Object :-
 
Public MustInherit Class Class1
    Public n As Integer
    Sub New()
        Console.WriteLine("Inside Abstract CLass1 Constructor...")
        Console.Write("Enter a number = ")
        n = CInt(Console.ReadLine)
    End Sub
    MustOverride Sub display()
End Class
 
 
Public Class Class2 : Inherits Class1
 
    Public Overrides Sub display()
        Console.WriteLine("n= " + n.ToString())
    End Sub
End Class
 
Module AbstractClassExample
    Sub Main()
        Dim obj As Class1
        Dim obj1 As New Class2
        obj = obj1
        obj.display()
        Console.ReadLine()
    End Sub
End Module
 
Output :-
 
Inside Abstract CLass1 Constructor...
Enter a number = 2 
 
n=2
 
 
Program on Inheritance :-

' Base class
Class Rectangle
   Protected width As Double
   Protected length As Double
   Public Sub New(ByVal l As Double, ByVal w As Double)
      length = l
      width = w
   End Sub
   Public Function GetArea() As Double
      Return (width * length)
   End Function
   Public Overridable Sub Display()
      Console.WriteLine("Length: {0}", length)
      Console.WriteLine("Width: {0}", width)
      Console.WriteLine("Area: {0}", GetArea())
   End Sub
   'end class Rectangle  
End Class
 
 
 
 
'Derived class
Class Tabletop : Inherits Rectangle
   Private cost As Double
   Public Sub New(ByVal l As Double, ByVal w As Double)
      MyBase.New(l, w)
   End Sub
   Public Function GetCost() As Double
      Dim cost As Double
      cost = GetArea() * 70
      Return cost
   End Function
   Public Overrides Sub Display()
      MyBase.Display()
      Console.WriteLine("Cost: {0}", GetCost())
   End Sub
    'end class Tabletop
End Class
Class RectangleTester
   Shared Sub Main()
      Dim t As Tabletop = New Tabletop(4.5, 7.5)
      t.Display()
      Console.ReadKey()
   End Sub
End Class
 
Output :-

Length: 4.5
Width: 7.5
Area: 33.75
Cost: 2362.5


Assignment 2 for print of vb.net



Assignment No. – 02

Program on Function :-

Module myfunctionskb
   Function FindMax(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
      ' local variable declaration */
      Dim result As Integer
      If (num1 > num2) Then
          result = num1
      Else
          result = num2
      End If
      FindMax = result
   End Function
   Sub Main()
      Dim a As Integer = 100
      Dim b As Integer = 200
      Dim res As Integer
      res = FindMax(a, b)
      Console.WriteLine("Max value is : {0}", res)
      Console.ReadLine()
   End Sub
End Module
 
Output :-
 
Max value is : 200
 
 
Program on sub procedure :-

Module mysubkb
   Sub CalculatePay(ByVal hours As Double, ByVal wage As Decimal)
      'local variable declaration
      Dim pay As Double
      pay = hours * wage
      Console.WriteLine("Total Pay: {0:C}", pay)
   End Sub
   Sub Main()
      'calling the CalculatePay Sub Procedure
      CalculatePay(25, 10)
      CalculatePay(40, 20)
      CalculatePay(30, 27.5)
      Console.ReadLine()
   End Sub
End Module
 
 
Output :-
 
Total Pay: $250.00
Total Pay: $800.00
Total Pay: $825.00


Assignment 1 for print of vb.net



Assignment No. – 01

Program on if - else :-

Module decisionskb
   Sub Main()
      'local variable definition '
      Dim a As Integer = 100
      ' check the boolean condition '
      If (a = 10) Then
          ' if condition is true then print the following '
          Console.WriteLine("Value of a is 10") '
      ElseIf (a = 20) Then
          'if else if condition is true '
          Console.WriteLine("Value of a is 20") '
      ElseIf (a = 30) Then
          'if else if condition is true 
          Console.WriteLine("Value of a is 30")
      Else
          'if none of the conditions is true
          Console.WriteLine("None of the values is matching")
      End If
      Console.WriteLine("Exact value of a is: {0}", a)
      Console.ReadLine()
   End Sub
End Module

Output :-
None of the values is matching
Exact value of a is: 100
 
Program on Select Case :-

Module decisionskb
   Sub Main()
      'local variable definition
      Dim grade As Char
      grade = "B"
      Select grade
          Case "A"
              Console.WriteLine("Excellent!")
          Case "B", "C"
              Console.WriteLine("Well done")
          Case "D"
              Console.WriteLine("You passed")
          Case "F"
              Console.WriteLine("Better try again")
          Case Else
              Console.WriteLine("Invalid grade")
      End Select
      Console.WriteLine("Your grade is  {0}", grade)
      Console.ReadLine()
   End Sub
End Module
 
Output :-
Well done
Your grade is B
Program on Do - While :-
 
Module loopskb
   Sub Main()
      ' local variable definition 
      Dim a As Integer = 10
      'do loop execution 
      Do
          Console.WriteLine("value of a: {0}", a)
          a = a + 1
      Loop While (a < 20)
      Console.ReadLine()
   End Sub
End Module
 
 
Output :-
 
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
 
Program on For loop :-
 
Module loopskb
   Sub Main()
      Dim a As Byte
      ' for loop execution 
      For a = 10 To 20
          Console.WriteLine("value of a: {0}", a)
      Next
      Console.ReadLine()
   End Sub
End Module
 
Output :-
 
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
value of a: 20