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

Monday, January 19, 2015

Graphics on QBASIC

                  Hey, Viewers !  Here are some interesting QBASIC programmes especially for SLC students for broadening their concept on programming. These programmes are beyond curriculum of SLC. Its just for extra knowledge and for fun.   



1.          Write a programme in QBASIC to make a circle of radius 25 units..(   Syntax:CIRCLE (x-coordinate,y-coordinate),radius,[color].....    )
Ans:
                        CLS
                     SCREEN 13
                     CIRCLE (50,50),25
                      END
                    


2.          Write a programme in QBASIC to make a circle of radius 50 units and fill any color in boarder.
Ans:
                     CLS
                     SCREEN 13
                     CIRCLE (50,50),50,10                      
                      END
      Note: It shows green color in circles boarder.        


3.          Write a programme in QBASIC to make a circle which can move in any direction and terminate as required or ordered by User.

Ans:
                      
DIM KeyPress  AS STRING
                      DIM x AS INTEGER
                      DIM y AS INTEGER

                      x = 159
                      y = 99

                      SCREEN 13

                      CLS

                      DO

    
                      KeyPress = UCASE$(INKEY$)

    
                      IF KeyPress = "W" THEN                               
                           CLS
                           y = y - 1
                 ELSEIF KeyPress = "S" THEN   
                           CLS
                           y = y + 1
                         ELSEIF KeyPress = "A" THEN   
                           CLS
                           x = x - 1
                         ELSEIF KeyPress = "D" THEN  
                           CLS
                           x = x + 1
                         END IF

   
                       CIRCLE (x, y), 25, 10

                      LOOP UNTIL KeyPress = "Q"   

                        Note: If pressed "W" then it moves in upward direction.
                                    If pressed "S" then it moves in downward direction.
                                     If pressed "A" then it moves in  left direction.
                                     If pressed "D" then it moves in right direction.
                                      If pressed "Q" the programme terminates.




Note: More interesting things will be published soon. Please do comment if you like my work and I recommend you to visit website https://www.qbasicsolutions.blogspot.com. Here you will find lots of QBASIC SLC solution and other practice
materials which will help you to boost your knowledge on QBASIC. Similarly, If you have any problem 
regarding computer subject
you can ask question on that blog site. Deepak Shrestha, computer teacher of Jagat Mandir School, will help you out.
.Thanks for visit.Take care.