Thursday, April 6, 2017

2. Object Oriented Programming ( OOP ): Program code ( visual basic )

Computer Science(9608) notes and Resources






Sample Program code for Practise  #2




Module Module1

    Class box

        Public length As Double
        Public breadth As Double
        Public height As Double

        Public Sub setlength(ByVal len As Double)
            length = len
        End Sub

        Public Sub setbreadth(ByVal bre As Double)
            breadth = bre
        End Sub

        Public Sub setheight(ByVal hei As Double)
            height = hei
        End Sub

        Public Function getvolume() As Double
            Return length * breadth * height
        End Function

    End Class



    Sub Main()

        Dim box1 As box = New box()
        Dim box2 As box = New box()
        Dim volume As Double = 0.0

        box1.setlength(2)
        box1.setbreadth(3)
        box1.setheight(4)


        box2.setlength(5)
        box2.setbreadth(6)
        box2.setheight(7)



        volume = box1.getvolume()
        Console.WriteLine("volume of box 1: " & volume)

        volume = box2.getvolume()
        Console.WriteLine("volume of box 2: " & volume)

        Console.ReadKey()

    End Sub

End Module









No comments:

Post a Comment

Comments here....