Wednesday, December 9, 2015

Array Worksheet ( Visual Basic )



1. Write a program to input price of 10 items in a one-dimentional array and display them in a row on the screen. Also, display the average price of all the items.

Programming Language: Visual Basic

Module Module1
Sub Main()
Dim price(10), counter, average, total As Decimal
Console.WriteLine("Enter the price of 10 items")
For counter = 1 To 10
price(counter) = Console.ReadLine()
Next
Console.WriteLine()
For counter = 1 To 10
Console.Write(price(counter) & " ")
total = total + price(counter)
Next
average = total / 10
Console.WriteLine()
Console.WriteLine()
Console.WriteLine("The average price of all the items is=" & average)
Console.ReadLine()
End Sub

End Module


Programming Language: C++ (Turbo)
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int price[10],counter;
int total=0;
int average=0;
cout<<"Enter the price of10 items: \n";
for (counter=1;counter<=10;counter=counter+1)
{
cin>>price[counter];
}
for (counter=1;counter<=10;counter=counter+1){
cout<<" "<<price[counter];
total=total+price[counter];
}
average=total/10;
cout<<" ";
cout<<"\n The average price of 10 items is="<<average;
getch();
return 0;
}






2. Make changes in program (1) such that it also displays number of items that cost more than average, equal to average and less than average.

Programming Language: Visual Basic
Module Module1

Sub Main()
Dim price(10), counter, average, total As Decimal
Dim greater, lesser, equal As Decimal
Console.WriteLine("Enter the price of 10 items")
For counter = 1 To 10
price(counter) = Console.ReadLine()
Next
Console.WriteLine()
For counter = 1 To 10
Console.Write(price(counter) & " ")
total = total + price(counter)
Next
average = total / 10
For counter = 1 To 10
If price(counter) > average Then
greater = greater + 1
ElseIf price(counter) < average Then
lesser = lesser + 1
Else
equal = equal + 1
End If
Next
Console.WriteLine()
Console.WriteLine("The average price of the given items is=" & average)
Console.WriteLine("The number of price greater than average=" & greater)
Console.WriteLine("The number of price lesser than average=" & lesser)
Console.WriteLine("The number of price equal than average=" & equal)
Console.ReadLine()
End Sub

End Module







3.       Write a program to input age of 10 people in a one-dimensional array. Display the age the oldest and the youngest person with appropriate message.


 Module Module1

    Sub Main()
        Dim age(10) As Integer
        Dim counter, old, young, store As Integer
        Console.WriteLine("Enter the age of 10 people:")
        For counter = 1 To 10
            age(counter) = Console.ReadLine
             Next
        store = age(1)
        For counter = 1 To 10
            If store > age(counter) Then
                store = age(counter)
            End If
        Next

        young = store
        For counter = 1 To 10
            If store < age(counter) Then
                store = age(counter)
            End If
        Next
        old = store
        Console.WriteLine()
        Console.WriteLine("The youngest age is=" & young)
        Console.WriteLine("The oldest age is=" & old)
        Console.ReadLine()
    End Sub

End Module




4.       Write a program to store eight integer values such that every next value is greater than the previous values. Display the difference between the subsequent values. For examples, if the array store.
  5         9       12      20       30   41     50    58

The output should be

            4       3         8      10       11       9     8


Module Module1

    Sub Main()

        Dim store1(8), Difference(7), temp As Integer
        Dim counter As Integer
        Console.WriteLine("Enter 8 values:")
        For counter = 1 To 8
            store1(counter) = Console.ReadLine()
        Next
        Dim just As Boolean


        just = True

        Do While just

            just = False

            For counter = 1 To 7
                If store1(counter) > store1(counter + 1) Then
                    temp = store1(counter)
                    store1(counter) = store1(counter + 1)
                    store1(counter + 1) = temp
                    just = True
                End If
            Next
        Loop

        For counter = 1 To 7

            Difference(counter) = store1(counter + 1) - store1(counter)
        Next
        Console.WriteLine("The difference between the subsequent values:")
        For counter = 1 To 7
            Console.WriteLine(Difference(counter))
        Next

        Console.ReadLine()

    End Sub
End Module





5.       Refer to array in program (4). Write a program to print the product of the consecutive values. The output should be
  45              240             1230         2900


Module Module1

    Sub Main()
        Dim store(8), product(4) As Integer
        Dim counter, num1, num2 As Integer
        num1 = 1
        num2 = 2
        Console.WriteLine("Enter 8 values such that every next value is greater than the previous values:")
        For counter = 1 To 8
            store(counter) = Console.ReadLine()
        Next
        For counter = 1 To 4
            product(counter) = store(num1) * store(num2)
            num1 = num1 + 2
            num2 = num2 + 2
        Next
        Console.WriteLine("The product of  the consecutive values:")
        For counter = 1 To 4
            Console.WriteLine(product(counter))
        Next
        Console.ReadLine()
    End Sub

End Module





6.       Refer to array in program (3). Write a program to swap the contents of the alternate elements and then displays the values. The output should be
12         20         5        9          50         58        30             41



Module Module1

    Sub Main()
        Dim store(8), num(8) As Integer
        Dim temp As Integer = 3
        Dim counter As Integer
        Console.WriteLine("Enter 8 values such that every next value is greater than the previous values:")
        For counter = 1 To 8
            store(counter) = Console.ReadLine()
        Next
        For counter = 1 To 4
            If counter = 3 Then
                temp = 1
                num(counter) = store(temp)
            Else
                num(counter) = store(temp)
            End If
            temp = temp + 1
        Next
        temp = 7
        For counter = 5 To 8
            If counter = 7 Then
                temp = 5
                num(counter) = store(temp)
            Else
                num(counter) = store(temp)
            End If
            temp = temp + 1
        Next
        Console.WriteLine("The values after swaping:")
        For counter = 1 To 8
            Console.WriteLine(num(counter))
        Next
        Console.ReadLine()
    End Sub

End Module





7.       Write a program to input five integer values in a one-dimensional array A1 and another five integer values in another array called   A2. Mix the values in a third array called A3 by taking values alternating from each one of them. For example, if
 A1         9         3        29        63        7
 A2        70        5        96        33        5
The resultant array should be    
A3          9       70         3          5          29          96         63        33        7          5



Module Module1

    Sub Main()
        Dim A1(10), A2(10) As Integer
        Dim A3(10), counter As Integer
        Console.WriteLine("Enter five values for A1:")
        For counter = 1 To 10
            If counter Mod 2 <> 0 Then A1(counter) = Console.ReadLine()
        Next
        Console.WriteLine("Enter five values for A2:")
        For counter = 2 To 10 Step 2
            If counter Mod 2 = 0 Then A2(counter) = Console.ReadLine()
        Next
        For counter = 1 To 10
            If counter Mod 2 = 0 Then
                A3(counter) = A2(counter)
            Else
                A3(counter) = A1(counter)
            End If
        Next
        Console.WriteLine("The resultant array i.e, A3:")
        For counter = 1 To 10
            Console.WriteLine(A3(counter))
        Next
        Console.ReadLine()
    End Sub

End Module





8.       Write a program to input total income of 10 people in array. Display the values stored in an array and also print how many of them are taxpayers. If the total income is greater than or equal to Rs 200000 then the person has to pay the tax.



Module Module1

    Sub Main()
        Dim income(10), taxP As Integer
        Dim counter As Integer
        Console.WriteLine("Enter total income of ten peoples:")
        For counter = 1 To 10
            income(counter) = Console.ReadLine()
        Next
        For counter = 1 To 10
            If income(counter) >= 200000 Then taxP = taxP + 1
            Console.WriteLine("income(" & counter & ")=" & income(counter))
        Next
        Console.WriteLine("The number of taxpayers=" & taxP)
        Console.ReadLine()
    End Sub

End Module








9.       Write a program that stores 20 characters in a one-dimensional array and displays the location of all the vowels in it. For example, if the array stores

  S       P        R        I           N           G            M            E          A             D       O     W            S


The output should be
                      3                     8                    9                    11



Module Module1

    Sub Main()
        Dim str1(20) As String
        Dim counter As Integer
        Console.WriteLine("Enter 20 characters:")
        For counter = 1 To 20
            str1(counter) = Console.ReadLine()
        Next
        Console.WriteLine("Location of vowels:")
        For counter = 1 To 10
            If UCase(str1(counter)) = "A" Or UCase(str1(counter)) = "E" Or UCase(str1(counter)) = "I" Or UCase(str1(counter)) = "O" Or UCase(str1(counter)) = "U" Then
                Console.WriteLine(counter)
            End If
        Next
        Console.ReadLine()
    End Sub

End Module




10.   Write a program to copy the values stored in two-dimensional array to a one-dimensional array.  


  Module Module1

    Sub Main()
        Dim array1D(9), array2D(3, 3) As Integer
        Dim length, counter2, counter1 As Integer
        length = 1
        For counter1 = 1 To 3
            For counter2 = 1 To 3
                array2D(counter1, counter2) = Console.ReadLine()
                array1D(length) = array2D(counter1, counter2)
                length = length + 1
            Next
        Next
        For counter2 = 1 To 9
            Console.Write(" ")
            Console.WriteLine(array1D(counter2))
        Next
        Console.ReadLine()
    End Sub
End Module
                     



Thursday, September 17, 2015

Programming ( AS Level Computer Science)

Programming question ( Examination type):


The cost of delivery is calculated as follows:

     ● There is a basic delivery charge of $5 for all orders.
     ●   If the total weight of an order is more than 1 kg, there is an additional charge of $0.50 or every extra 0.1 kg.
         ●   If the total volume of an order is more than 1000 cubic.cm, there is an additional charge of $0.50 for every extra 200 cubic.cm
Write a program to ask user total weight and total volume of the items , and then show the total cost of delivery.




Module Module1

    Sub Main()
       Dim Totalweight, Totalvolume, Extravolume As Decimal
        Dim costweight, costvolume, totalcost As Decimal
        Console.Write("Enter total weight in kg:")
        Totalweight = Console.ReadLine()
        Console.Write("Enter it volume in  cubic.cm :")
        Totalvolume = Console.ReadLine()
        If Totalweight > 1 Then
            costweight = ((Totalweight - 1) / 0.1) * 0.5 + 5
        ElseIf Totalweight > 0 And Totalweight <= 1 Then
            costweight = 5
        Else
            costweight = 0
        End If
        If Totalvolume > 1200 Then
            Extravolume = (Totalvolume - 1000)
            If (Extravolume / 200) > 0 Then
                If (Extravolume / 200) Mod 200 = 1 Then
                    costvolume = ((Extravolume / 200) * 0.5) + 5
                Else
                    costvolume = (((Extravolume \ 200) + 1) * 0.5) + 5
                End If
            End If
        ElseIf Totalvolume > 0 And Totalvolume < 1200 Then
            costvolume = 5
        Else
            costvolume = 0
        End If
        If costweight > 1 And costvolume > 1 Then
            totalcost = costweight + costvolume - 5
        Else
            totalcost = 0
        End If
        Console.WriteLine("The cost of delivery=" & totalcost & "$")Console.ReadLine()
    End Sub

End Module







 Instagram


Sunday, September 6, 2015

AS-Level Related Computer Science Programming .( Visual Basic )

Programming Questions with solutions:



1.       Gina is developing her programming skills in string handling.

                 She is going to input one string. The string contains letters and zero or more " * " characters in any positions. Gina wants to remove all the " * "s and output the letters in their original order. For example:
                       ●    Input  "com*put**er*" , the output is "computer"
                       ●   Input "hardware", the output is "hardware"
(a)        Using a high-level programming language, write the code to perform this task. 
    ( Ensure that you use meaningful variable names and lay the code out clearly )


Module module1

    Sub main()
        Dim counter As Integer
        Dim inputString, temp, newString As String
        newString = ""

        Console.WriteLine("Enter any word:")
        inputString = Console.ReadLine()

        For counter = 1 To Len(inputString)
            temp = Mid(inputString, counter, 1)
            If temp <> "*" Then newString = newString + temp
        Next

        Console.WriteLine(newString)
        Console.ReadLine()
    End Sub

End Module





2.       John is developing his programming skills in string handling.

                 He is going to input two string.
           Each string is made up of three parts:
                       ●    Letters following by
                       ●    a single " * " character, followed by
                       ●     Letters

The groups of letters after the " * " characters are joined together to form a new string which is then output.

 For example, with " DFG*COM" and "B*PUTER" as inputs, the new string output will be
"COMPUTER".
(a) Using a high-level programming language, write the code to perform this task. ( Ensure that you use meaningful variable names and lay the code out clearly.)




Module module1
    Sub main()
        Dim counter As Integer
        Dim inputString1, inputString2, temp, newString, finalWord As String
        Dim newString1, newString2 As String
        Console.WriteLine("Enter any word:")
        inputString1 = Console.ReadLine()

        Console.WriteLine("Again enter any word:")
        inputString2 = Console.ReadLine()

        For counter = 1 To Len(inputString1)
            temp = Mid(inputString1, counter, 1)
            If temp = "*" Then newString1 = Mid(inputString1, counter + 1, Len(inputString1) - counter)
        Next

        For counter = 1 To Len(inputString2)
            temp = Mid(inputString2, counter, 1)
            If temp = "*" Then newString2 = Mid(inputString2, counter + 1, Len(inputString2) - counter)
        Next

        newString = newString1 + newString2
        For counter = 1 To Len(newString)
            temp = Mid(newString, counter, 1)
            If temp <> "*" Then finalWord = finalWord + temp
        Next
        Console.WriteLine(finalWord)
        Console.ReadLine()
    End Sub


End Module


Instagram

Wednesday, August 26, 2015

Programming Visual Basic ( Work Sheet )

1.Use different types of technique to implement the following:

( a )   Write a program to input integer , N between 1 and 9 and print a line of output consisting of ascending digits from 1 to N. For example, if N=4, produce the line 1234.

Module Module1
  Sub Main()
        Dim a, b As Integer
        Console.WriteLine("Enter number from 1-9")
        a = Console.ReadLine()
        For b = 1 To a
            Console.Write(b)
        Next
        Console.ReadLine()
    End Sub
End Module




Module Module1

    Sub Main()
   
        Dim a, b As Integer
        Dim c As String
        Console.WriteLine("Enter number from 1-9")
        a = Console.ReadLine()
        For b = 1 To a
            c = c + Str(b)
        Next
        Console.WriteLine(Val(c))
        Console.ReadLine()
    End Sub

End Module



Module Module1

    Sub Main()
   
        Dim a, b As Integer
        Console.WriteLine("Enter any integer")
        a = Console.ReadLine()
        Do
            b = b + 1
            Console.Write(b)
 Loop Until b = a    
        Console.ReadLine()
    End Sub

End Module




( b )   Write a program to input integer , N between 1 and 9 and print a line of output consisting of descending digits from N to 1. For example, if N=4, produce the line 4321.

Module Module1

    Sub Main()
        Dim a, b As Integer
        Console.WriteLine("Enter number from 1-9")
        a = Console.ReadLine()
        For b = a To 1 Step -1
            Console.Write(b)
        Next
        Console.ReadLine()
    End Sub

End Module

Module Module1

    Sub Main()
   
        Dim a, b As Integer
        Dim c As String
        Console.WriteLine("Enter number from 1-9")
        a = Console.ReadLine()
        For b = 1 To a
            c = Str(b) + c
        Next
        Console.WriteLine(Val(c))
        Console.ReadLine()
    End Sub

End Module


Module Module1

    Sub Main()
   
        Dim a, b As Integer
        Console.WriteLine("Enter any integer")
        a = Console.ReadLine()
        b = a
        Do

            Console.Write(b)
            b = b - 1
        Loop Until b = 0
     
        Console.ReadLine()
    End Sub

End Module




( c )         Write a program to input integer , N between 1 and 9 and print a line of output consisting of ascending digits from 1 to N followed by descending digits from (N-1) to 1. For example, if N=5, produce the line 123454321.

Module Module1

    Sub Main()
        Dim a, b As Integer
        Console.WriteLine("Enter number from 1-9")
        a = Console.ReadLine()
        For b = 1 To a
            Console.Write(b)
        Next
        For b = (a - 1) To 1 Step -1
            Console.Write(b)
        Next
        Console.ReadLine()
    End Sub
End Module


Module Module1

    Sub Main()
   
        Dim a, b, e As Integer
        Dim c As String
        Console.WriteLine("Enter number from 1-9")
        a = Console.ReadLine()
        For b = 1 To a
            c = c + Str(b)
        Next
        For b = (a - 1) To 1 Step -1
            c = c + Str(b)
        Next
        Console.WriteLine(Val(c))
        Console.ReadLine()
    End Sub

End Module






( d )      Write a program that asks a user to type 5 integers and print the largest value.



Module Module1

    Sub Main()
        Dim a(5), n As Integer
        Console.WriteLine("Enter 5 numbers")
        For n = 1 To 5
            a(n) = Console.ReadLine()
        Next
        For n = 1 To 5
            If a(1) < a(n) Then a(1) = a(n)
        Next
        Console.WriteLine("Greatest=" & a(1))
        Console.ReadLine()
    End Sub

End Module





( e )        Write a program that askes the user to type 10 integers and writes the smallest value.

Module Module1

    Sub Main()
        Dim a(10), n As Integer
        Console.WriteLine("Enter 10 numbers")
        For n = 1 To 10
            a(n) = Console.ReadLine()
        Next
        For n = 1 To 10
            If a(1) > a(n) Then a(1) = a(n)
        Next
        Console.WriteLine("smallest=" & a(1))
        Console.ReadLine()
    End Sub

End Module


( f )          Write a program that asks the user to type an integer N and computes the sum of the cubes from 1 to N.

Module Module1

    Sub Main()
        Dim s, a, counter As Integer
        Console.WriteLine("Enter an integer:")
        a = Console.ReadLine()
        For counter = 1 To a
            s = s + counter ^ 3
        Next
        Console.WriteLine("Sum of the cubes from 1 to " & a & " is = " & s)
        Console.ReadLine()
    End Sub

End Module






( g )     Write a program to calculate the factorial of a given number.


Module Module1

    Sub Main()
        Dim a, counter As Integer
        Dim s As Integer = 1
        Console.WriteLine("Enter any integer:")
        a = Console.ReadLine()
        For counter = 1 To a
            s = s * counter
        Next
        Console.WriteLine("The factorial of given integer is= " & s)
        Console.ReadLine()
    End Sub

End Module






( h)      Write a program that asks the user to type a positive integer. When the user types a negative value the program writs ERROR and asks for another value. When the user types 0, it means that the last value has been typed and the program must write the average of the positive integers. If the number typed values is zero the program writes "NO AVERAGE".


Module Module1

    Sub Main()
        Dim a, s, c As Integer

        Console.WriteLine("Enter positive integer: ")

d:
        a = Console.ReadLine()
        If a > 0 Then
            s = a + s
            c = c + 1
            GoTo d
        ElseIf a < 0 Then
            Console.WriteLine("Error!!.Enter positive number")
            GoTo d
        Else
         
            If s = 0 Then
                Console.WriteLine("no average")
            Else
                Console.WriteLine("Average=" & s / c)
                GoTo u
            End If
        End If

u:
        Console.ReadLine()
    End Sub

End Module


Module Module1

    Sub Main()
        Dim a, b, c As Integer
        Console.WriteLine("Enter positive number")
        Do
            a = Console.ReadLine()
            If a > 0 Then
                b = b + a
                c = c + 1
            ElseIf a < 0 Then
                Console.WriteLine("Error.!!!Enter positive number")
            End If
        Loop Until a = 0
        If b = 0 Then
            Console.WriteLine("No Average")
        Else

            Console.WriteLine("Average of all the number are=" & (b / c))
        End If
        Console.ReadLine()
    End Sub

End Module



( i)        Request the user to type positive numbers, or to stop by typing a number smaller than 1. Print the average.

Module Module1

    Sub Main()
        Dim a, s, c As Integer

        Console.WriteLine("Enter positive integer: ")

d:
        a = Console.ReadLine()
        If a > 0 Then
            s = a + s
            c = c + 1
            GoTo d
        ElseIf a < 1 Then
            Console.WriteLine("stop typing negative number")
            s = a + s
            c = c + 1
            GoTo d
        Else
         
            If s = 0 Then
                Console.WriteLine("no average")
            Else
                Console.WriteLine("Average=" & s / c)
                GoTo u
            End If
        End If

u:
        Console.ReadLine()
    End Sub

End Module


Module Module1

    Sub Main()
        Dim a, b, c As Integer
        Console.WriteLine("Enter positive number")
        Do
            a = Console.ReadLine()
            If a > 0 Then
                b = b + a
                c = c + 1
            ElseIf a < 0 Then
                Console.WriteLine("Stop!!Typing negative numbers")
                b = b + a
                c = c + 1
            End If
        Loop Until a = 0
        If b = 0 Then
            Console.WriteLine("No Average")
        Else

            Console.WriteLine("Average of all the number are=" & (b / c))
        End If
        Console.ReadLine()
    End Sub

End Module



( j )     Request the user to type positive numbers, or type 0 to stop. Show how many numbers were between 100 and 200 (Both included).

Module Module1
    Sub Main()
        Dim a, c As Integer
        Console.WriteLine("Enter positive integer: ")
d:
        a = Console.ReadLine()
        If a > 0 Then
            If a >= 100 And a <= 200 Then
                c = c + 1
            Else
                c = c
            End If
        ElseIf a = 0 Then
            GoTo u
        End If
        GoTo d
  Console.WriteLine("Total numbers between 100 and 200 (both included) is = " & c)
        Console.ReadLine()
    End Sub

End Module


Module Module1

    Sub Main()
        Dim a, c As Integer
        Console.WriteLine("Enter positive number")
        Do
            a = Console.ReadLine()
            If a >= 100 And a <= 200 Then  c = c + 1
        Loop Until a = 0
   Console.WriteLine("Total numbers between 100 and 200 (both included) = " & c)
        Console.ReadLine()
    End Sub

End Module


( k )     The country A has 50M inhabitants, and its population grows 3% per year. The country B has  70M and grows 2% per year. Tell in how many years A will surpass B.

( l )       Write a program to calculate the sum of squares of first n natural numbers  using while loop.

Sub Main()
        Dim a, c As Integer
        Dim b As Integer = 1
        Console.WriteLine("Enter any integer:")
        a = Console.ReadLine()
        Do While b <> (a + 1)
            c = b ^ 2 + c
            b = b + 1
     Loop
        Console.WriteLine(c)
    Console.ReadLine()
    End Sub

End Module






( m )    Write a program to reverse the given number.

Module Module1

    Sub Main()
        Dim a, b, c As String
        Console.WriteLine("Enter any integer")
        a = Console.ReadLine()
        Do Until a = 0
            b = a Mod 10
            a = a \ 10
            c = c * 10 + b
        Loop
        Console.WriteLine(c)
        Console.ReadLine()
    End Sub

End Module


Module Module1
    Sub Main()
        Dim a, c As Integer
        Dim d As String
        Console.WriteLine("Enter any number")
        a = Console.ReadLine()
        d = Str(a)
        c = Val(StrReverse(d))
        Console.WriteLine(c)
        Console.ReadLine()
    End Sub

End Module








( n )     Write a program to check whether the given number is palindrome or not.

Module Module1

    Sub Main()
        Dim a, b, c, d As String
        Console.WriteLine("Enter any intege:r")
        a = Console.ReadLine()
        d = a
        Do Until a = 0
            b = a Mod 10
            a = a \ 10
            c = c * 10 + b
        Loop
        If c = d Then
            Console.WriteLine("The given number is pallindrome!!")
        Else
            Console.WriteLine("The given is not pallindrome!!")
        End If
        Console.ReadLine()
    End Sub

End Module




Module Module1

    Sub Main()
        Dim a, c As Integer
        Dim d As String
        Console.WriteLine("Enter any number")
        a = Console.ReadLine()
        d = Str(a)
        c = Val(StrReverse(d))
        If a = c Then
            Console.WriteLine("Pallindrome!!")
        Else
            Console.WriteLine("Not..Pallindrome!!")
        End If

        Console.ReadLine()
    End Sub

End Module

Tuesday, June 30, 2015

Think about it?????

                 
Be a Master of likes/dislike 
                 You have to learn to like what you dislike too and even dislike what you like, so that you are above likes and dislikes, instead of likes and dislikes of having you! That is true mastery. Ba a master of likes and dislikes. The human soul takes that in any adverse circumstances, be silent, calm, quiet and show patience and endurance; mere the self-soul with the supreme soul, which will bring happiness and joy.
                I treat others as I would want to be treated. By taking time to reflect on my highest principles before I act and make decisions, I maintain my dignity and am held in high esteem by others. When I combine the power of self-belief with pure motives; there is very little I cannot achieve. Using this power Nasty to bring benefit to everyone in my life. I can rest steadily how my way...