Open main menu

Wikibooks β

A-level Computing/AQA/Problem Solving, Programming, Data Representation and Practical Exercise/Skeleton code/2013 Exam/Section B

< A-level Computing‎ | AQA‎ | Problem Solving, Programming, Data Representation and Practical Exercise‎ | Skeleton code‎ | 2013 Exam


Section B IntroductionEdit

This section will ask you questions that you will have to find programming solutions to. The past exam papers have always provided a strict program specification in the form of variable names and pseudocode. It is very likely that a problem will be set around the theme of cryptography but different to the skeleton code in some way. You should be able to interpret pseudocode, structured english, structure charts, stepwise refinement tables and decision tables. Any of these techniques could be used to communicate an algorithm to be coded.

Practice questionsEdit

Obviously all the past papers from AQA have good section B questions that you should attempt. Here are some around this year's theme...

Numeric Caesar CipherEdit

(a) Write a program that encrypts a number sequence using the same principle as the Caesar Cipher. (b) Test your program using a key= 6 and the number sequence 0123456789

OUTPUT "enter a number to encode"
INPUT plainNum
OUTPUT "enter a key"
For i = 0 to (length of plainNum -1)
      codedNum <-- codedNum & (VALUE(PlainNum(i)) + Key) Mod 10
OUTPUT codedNum


    Sub Main()
        Dim plainNum, codedNum As String
        Dim Key As Integer
        Console.WriteLine("enter a number to encode")
        plainNum = Console.ReadLine()
        Console.WriteLine("enter a key")
        Key = Console.ReadLine()
        For i = 0 To (plainNum.Length - 1)
            codedNum = codedNum & ((Val(plainNum(i)) + Key) Mod 10)
            'Val is a bit of a cheat... subtracting 48 from the ascii code converts a character in the range 48-58 to its integer value
            'codedNum = codedNum & ((Asc(plainNum(i)) - 48 + Key) Mod 10) ' this line is a nicer way to solve it, althrough both only cope with number method specified
            'Obviously it is irrelevant which way is nicer, you MUST use the specified algorithm
    End Sub

Character FrequencyEdit

Using the average frequency that characters appear is one way to "crack" many simple ciphers. You can learn more about this here:

Write a program that counts the number of times each character appears in some inputted text. It should output a list of characters with the number of times each appears.

(pseudo-code to follow)


'solution to follow 
    Sub Main()
        Console.WriteLine("enter a string")
        Dim text As String = Console.ReadLine()
        Dim textarr(text.Length - 1, 1) As Object
        Dim search As Boolean
        Dim searchele, newele As Integer
        For i = 0 To text.Length - 1
            search = False
            For j = 0 To text.Length - 1
                If text(i) = textarr(j, 0) Then
                    search = True
                    searchele = j
                End If
            If search Then
                textarr(searchele, 1) += 1
                textarr(newele, 0) = text(i)
                textarr(newele, 1) = 1
                newele += 1
            End If
        For i = 0 To newele - 1
            Console.WriteLine(textarr(i, 0) & " appears " & textarr(i, 1) & " times")
    End Sub

Another question....


'Another solution