Showing posts with label console. Show all posts
Showing posts with label console. Show all posts

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 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