Thursday 29 May 2014

program 14: function overloading (console)

program to demonstrate the concept of function overloading.    


-----------------------------------------code---------------------------------------------------------
Imports System.Console
Module Module1
    Sub Main()
        Dim a, b, c, sum As Integer
        Dim l, m, n, str As String
        WriteLine("Enter the value of a,b,c")
        a = ReadLine()
        b = ReadLine()
        c = ReadLine()
        WriteLine("Enter the value of l,m,n")
        l = ReadLine()
        m = ReadLine()
        n = ReadLine()
        sum = addition(a, b, c)
        str = addition(l, m, n)
        WriteLine("Addition of" & a & "," & b & "," & c & "is=" & sum)
        WriteLine("Addition of" & l & "," & m & "," & n & "is=" & str)
        ReadKey()
    End Sub

    Function addition(ByVal x As Integer, ByVal y As Integer, ByVal z As Integer) As Integer
        Return x + y + z
    End Function

    Function addition(ByVal x As String, ByVal y As String, ByVal z As String) As String
        Return x + y + z
    End Function
End Module

-----------------------------------------output----------------------------------------------------


umesh sohaliya
codestrew

program 13: restaurant menu

program to create restaurant menu using listbox and calculate total item and price

-----------------------------------------code---------------------------------------------------------

Public Class Form1
    Dim v, b, n, m, s As Integer
    Dim total As Integer
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click  
        ListBox2.Items.Add(ListBox1.SelectedItem)
        TextBox1.Text = ListBox2.Items.Count()
    End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ListBox2.Items.Remove(ListBox2.SelectedItem)
        TextBox1.Text = ListBox2.Items.Count()
    End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim a, i, j As Integer
        j = 0
        a = ListBox2.Items.Count
        For i = 0 To a
            If (i < a) Then
                If ListBox2.Items(i) = "Vadapav(Rs.10)" Then
                    j = j + 10
                End If
                If ListBox2.Items(i) = "Barger(Rs.15)" Then
                    j = j + 15
                End If
                If ListBox2.Items(i) = "Noodles(Rs.35)" Then
                    j = j + 35
                End If
                If ListBox2.Items(i) = "Maggi(Rs.20)" Then
                    j = j + 20
                End If
                If ListBox2.Items(i) = "Sandwich(Rs.12)" Then
                    j = j + 12
                End If
                If ListBox2.Items(i) = "Chinese Puf(Rs.12)" Then
                    j = j + 12
                End If
                If ListBox2.Items(i) = "Samosa(Rs.15)" Then
                    j = j + 15
                End If
            End If
        Next i

        TextBox2.Text = j
    End Sub
End Class
-----------------------------------------output----------------------------------------------------

umesh sohaliya
codestrew

program 12: multiplication table


program to print multiplication table of given number

-----------------------------------------code---------------------------------------------------------

Imports System
Module Module1
    Sub Main()
        Dim n, i, mul As Integer
        Console.WriteLine("Enter number:-")
        n = Console.ReadLine()
        Console.WriteLine("Multiplication Table")
        For i = 1 To 10
            mul = n * i
            Console.WriteLine(n & "*" & i & "=" & mul)
        Next i
        Console.ReadKey()
    End Sub
End Module


-----------------------------------------output----------------------------------------------------


umesh sohaliya
codestrew

program 11: simple calculator(console)

program for simple calculator in console application.

-----------------------------------------code---------------------------------------------------------
Module Module1

    Sub Main()
        Dim a, b, c As Double
        Dim ch As String
        System.Console.WriteLine("Enter the value of a:")
        a = System.Console.ReadLine()
        System.Console.WriteLine("Enter the value of b:")
        b = System.Console.ReadLine()
        System.Console.WriteLine("Which operation are you perform?")
        ch = System.Console.ReadLine()
        Select Case ch
            Case "+"
                c = a + b
                System.Console.WriteLine("Addition is=" & c)
            Case "-"
                c = a - b
                System.Console.WriteLine("Subtraction is=" & c)
            Case "*"
                c = a * b
                System.Console.WriteLine("Multiplication is=" & c)
            Case "/"
                c = a / b
                System.Console.WriteLine("Division is=" & c)
        End Select
        System.Console.ReadKey()
    End Sub
End Module

-----------------------------------------output----------------------------------------------------

umesh sohaliya
codestrew

program 10: print triangle(console)

program print a following pattern in console application.
                                    *
                                    **
                                    ***
                                    ****
                                    *****

-----------------------------------------code---------------------------------------------------------

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim n, i, c As Integer
        n = TextBox1.Text
        For i = 1 To n
            If (n Mod i = 0) Then
                c = c + 1
            End If
        Next i
        If (c > 2) Then
            MsgBox("Number is not prime", , "Message")
            TextBox1.Text = ""
        Else
            MsgBox("Number is prime", , "Message")
            TextBox1.Text = ""
        End If
    End Sub
End Class
-----------------------------------------output----------------------------------------------------


umesh sohaliya
codestrew

program 9: prime number

program to check the number is prime or not.

-----------------------------------------code---------------------------------------------------------

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim n, i, c As Integer
        n = TextBox1.Text
        For i = 1 To n
            If (n Mod i = 0) Then
                c = c + 1
            End If
        Next i
        If (c > 2) Then
            MsgBox("Number is not prime", , "Message")
            TextBox1.Text = ""
        Else
            MsgBox("Number is prime", , "Message")
            TextBox1.Text = ""
        End If
    End Sub
End Class

-----------------------------------------output----------------------------------------------------


umesh sohaliya
codestrew

umesh sohaliya
codestrew

program 8: find minimum & maximum value



 program to find a maximum value from five values.


-----------------------------------------code---------------------------------------------------------

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim n1, n2, n3, n4, n5 As Integer
        n1 = TextBox1.Text
        n2 = TextBox2.Text
        n3 = TextBox3.Text
        n4 = TextBox4.Text
        n5 = TextBox5.Text
        If n1 > n2 And n1 > n3 And n1 > n4 And n1 > n5 Then
            TextBox7.Text = n1
        ElseIf n2 > n3 And n2 > n4 And n2 > n5 Then
            TextBox7.Text = n2
        ElseIf n3 > n4 And n3 > n5 Then
            TextBox7.Text = n3
        ElseIf n4 > n5 Then
            TextBox7.Text = n4
        Else
            TextBox7.Text = n5
        End If
        If n1 < n2 And n1 < n3 And n1 < n4 And n1 < n5 Then
            TextBox6.Text = n1
        ElseIf n2 < n3 And n2 < n4 And n2 < n5 Then
            TextBox6.Text = n2
        ElseIf n3 < n4 And n3 < n5 Then
            TextBox6.Text = n3
        ElseIf n4 < n5 Then
            TextBox6.Text = n4
        Else
            TextBox6.Text = n5
        End If
    End Sub
End Class



-----------------------------------------output----------------------------------------------------


umesh sohaliya
codestrew

program 7: prepare marksheet


program using select case marks of five subject and display the  total,percentage and class.
-----------------------------------------code---------------------------------------------------------

End ClassPublic Class Form1

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim s1, s2, s3, s4, s5 As Integer
        Dim per As Integer
        s1 = TextBox1.Text
        s2 = TextBox2.Text
        s3 = TextBox3.Text
        s4 = TextBox4.Text
        s5 = TextBox5.Text
        TextBox6.Text = s1 + s2 + s3 + s4 + s5
        TextBox7.Text = TextBox6.Text / 5
        per = TextBox7.Text
        If per >= 0 And per < 35 Then
            TextBox8.Text = "Fail"
        ElseIf per >= 35 And per < 50 Then
            TextBox8.Text = "Pass Class"
        ElseIf per >= 50 And per < 60 Then
            TextBox8.Text = "Second Class"
        ElseIf per >= 60 And per < 70 Then
            TextBox8.Text = "First Class"
        ElseIf per >= 70 And per <= 100 Then
            TextBox8.Text = "Distinction"
        End If
    End Sub
End Class

-----------------------------------------output----------------------------------------------------


umesh sohaliya
codestrew