A-level Computing 2009/AQA/Problem Solving, Programming, Data Representation and Practical Exercise/Skeleton code/2013 Exam/Section B
Section B Introduction
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.
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 Cipher
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 Next Console.WriteLine(codedNum) Console.ReadLine() End Sub
'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 Next If search Then textarr(searchele, 1) += 1 Else textarr(newele, 0) = text(i) textarr(newele, 1) = 1 newele += 1 End If Next For i = 0 To newele - 1 Console.WriteLine(textarr(i, 0) & " appears " & textarr(i, 1) & " times") Next Console.ReadLine() End Sub