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