Ad Block Detected!

Our website is made possible by displaying ads to our visitors. Please support us by whitelisting our website or allowing necessary trackers.

What to expect

Although this is specific to AQA A-Level Computing Section B of paper 1, it's still good practice for people with other exam boards. Section B of paper 1 on the AQA Computer Science A-Level tests your ability to program. Students often think that you have to be a programming genius to get high marks on this section, but that is not necessarily the case. While having a broad range of programming skills is advantageous, you only need to be proficient in a small number of skills to perform well in this area.

What to practice

  1. Loops (for, foreach, and while loops)
  2. Splitting strings by using the .Split() and finding the frequency of a character
  3. Finding the length of a string (.Length)
  4. Conversions (int to string, string to char, etc.)
  5. Using lists and arrays, and converting between them
  6. Using .Contains()
  7. Using .Max() and .Min()
  8. Modulus

The most important thing to keep in mind is that the examiner doesn't care how you finish the code as long as you answer the questions. In other words, adopting sophisticated tactics or challenging alternatives won't earn you any extra marks, so why not just choose the simplest solution? This is the best approach, especially since you only have 20 minutes to finish it. Built-in methods like .Split() in C# can save you a huge amount of time. The following examples use C#.

For, Foreach, and While Loops

Many questions involve manipulating a user's input, such as counting how many times a specific character appears. In most cases, you will use a loop to iterate through the user's input. It's advisable to be proficient in using loops and related functions like .Length in a for loop statement in C#. You should also be familiar with index positions.

Console.WriteLine("Enter input");
string input = Console.ReadLine();

for(int i = 0; i < input.Length(); i++)
{
  if(input[i] == 'a')
  {
    Console.WriteLine("Your input contains the letter a");
  }
}
 

foreach(char ch in input)
{
  if(ch == 'a')
  {
    Console.WriteLine("Your input contains the letter a");
  }
}

An aspect of strings that people don't typically know is that you can access a specific index of a string without looping through it or converting it into an array or list.

Console.WriteLine("Enter a word");

string input = Console.ReadLine();

Console.WriteLine(input[2]);

When using while loops, it's common practice to create a boolean variable and set it to false once the loop's conditions are met.

bool correct = true;

while(correct)
{
  if(1 != 2)
  {
    
    correct = false;
  }
}

.Split()

The .Split() method is also a useful tool. You can ask for user input, store it in a string variable, and then split the string wherever a specific character appears (like a space or a dash). This is stored in a string array.

Console.WriteLine("Enter input");

string input = Console.ReadLine();

string[] strArr = input.Split(' ');
foreach(string item in strArr)
{
  Console.WriteLine(item);
}

You can also use .Split('c') to find out how many times a character appears in a string.

Console.WriteLine("Input text");

string input = Console.ReadLine();
int freq;
foreach(char c in input)
{

  freq = input.Split(c).Length() - 1;
  Console.WriteLine(c + " " + freq);
}

.Length

The .Length property is used to find the number of elements in an array or the number of characters in a string. This is particularly useful when iterating over arrays or strings using loops.

Console.WriteLine("Enter a word");

string input = Console.ReadLine();

int length = input.Length;
Console.WriteLine("The length of the input is: " + length);

Remember, .Length is a property, not a method, so it doesn't require parentheses. It's often used in conjunction with loops to avoid out-of-bound errors.