AdBlock Detected!

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

Computer Neek

AQA A level Computing Paper 1 Section B

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 on your ability to program. Students often think that you have to be a programming genius to get high marks on this section of the test but that is not necessarily the case. Although 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 and foreach loops as well as while loops)
  2. Splitting strings called .Split() and finding out how frequently a char occurs
  3. Finding the length of a string(.Length)
  4. Conversions(int to string, string to char etc...)
  5. Using lists and arrays and converting list to arrays and vice versa.
  6. .Contains()
  7. .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 way to go 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 will use C#.

For, foreach and while loops

A lot of the questions asked have to do with manipulating a users input like counting how many times a user inputs a specific character. As a result, in most cases you will be using a loop of some sort to loop through the whole of the users input.It is adviced to be profficient in using loops and all the things used alongside with them sometimes like the .Length function in a for loop statement(c#).You should also be familair with index positions.

        Console.WriteLine("Enter in a input");
	string input = Console.ReadLine();
	//using a for loop
	for(int i =0; i < input.Length; i++)
	{
		if(input[i] == "a")
		{
			Console.WriteLine("Your input has the letter a")
		}
	}
	 
	//using a foreach loop
	foreach(char ch in input)
	{
		if(ch == "a")
		{
			Console.WriteLine("Your input has the letter a")
	 
		}
	}

An aspect of strings that people don't typically know you can do in c# and other programming languages is that you can get a specific index of a string without running it through a loop or putting it in an array or list.

Look at the example below

  1. Console.WriteLine("Enter in a word");
  2. //Stores the users input
  3. string input = Console.ReadLine();
  4. //output index 2.
  5. Console.WriteLine(input[2]);
  6.  

When using while loops, it's common practise to create a bool in advance and set it to false after the loop's conditions have been met.


Look at the illustration below.


  1. bool correct = true;
  2. //loop till if correct = true
  3. while(correct)
  4. {
  5. if(1 != 2)
  6. {
  7. //while loop will now stop
  8. correct = false;
  9. }
  10. }

.Split()

The .Split() is also a useful tool. To use it, first you ask for the users input and store it in a string variable. After, you create a string array variable which will store the result. You then append the .Split(' ') to the string variable that stores the user's input and store it to the string array. Whatever you add in the brackets of the .Split(' ') is where it will split the inputted string. For an example if the user typed "Hello everyone", it will be saved in the string array at index position 0 as Hello and everyone at index position 1 because it was instructed to split the string whenever there is a space. If the .Split() function had a dash in the brackets(.Split('/')) then it will split the string every time there was a dash. If the user typed "Hello/everyone" it will be saved in the string array at index position 0 as Hello and everyone at index position 1.

Console.WriteLine("Enter in an input");
//store user input
string input = Console.ReadLine();
//store each word with a space in the strArr 
string[] strArr = input.Split('');
foreach(string item in strArr)
{
	//outputs all the values in strArr
	Console.WriteLine(item);
}
 
 
 
 

You can also use .split(' ') to find how many times a character occurs in a given string.


Console.WriteLine("Input text");
//storing users input
string input = Console.ReadLine();
int freq;
 
foreach (char c in input)
{
//stores number of times the letter occurs
freq = input.Split(c).Length - 1;
}
Console.ReadLine();

The .Split('c') gets the individual letters and the .Length - 1 returns how many time that specific letter appears in the inputted string.

.Length

.length(c#) is one of the easiest things to use in section b. It returns the length of a string. Look at the example below

Look at example below

  1. Console.WriteLine("Enter in an input");
  2. //store user input
  3. string input = Console.ReadLine();
  4. //stores the length of the string
  5. int length = input.Length;
  6.  
  7.  

Lits and Arrays

The ability to use arrays and lists is crucial. Often, you may need to store a specific section of the user's input. Look at the example below.

Look below for an example

  1. Console.WriteLine("Enter in an input");
  2. //store user input
  3. string input = Console.ReadLine();
  4. //converting string to char array;
  5. char[] charArr = input.ToCharArray();
  6. //creating a list
  7. List<string>strList = new List<string>();
  8. foreach(char letter in input)
  9. {
  10. strList.Add(letter);
  11. }

.Contains()

The .Contains() is a easy to use function that can be incredibly benefical when programming. It allows you to check if a specific, word, character or number is in a variable.

Console.WriteLine("enter in your name");
string name = Console.ReadLine();
if(name.Contains("Emma"))
{ 
   Console.WriteLine("That's my name too.");
}

.Max() and .Min()

.Max() and .Min() uses LINQ. Its a way of finding the greatest item in a list or an array.

using System;
using System.Linq;
static void Main(string[] args)
{
  int[] numbers = new int[]{1,2,3,6,4,55};
   Console.WriteLine(numbers.Max());
}
 

You have to write usuing System.Linq; to be able to access .Max() and .Min()

Modulus %

Modulus in c# is represented by the character % otherwise know as the percentage sign. What it does is finds the remainder of a division. For an example if you were to do 5 % 2, the answer would be 5. This is because 5 / 2 is 2.5 but the modulus only finds the remainder which is 5. Modulus is usually used in things conditional statments and in tasks like prime/even numbers.

Console.WriteLine("Enter in a number");
int number = int.Parse(Console.ReadLine());
//checking if its even
if(number % 2 == 0)
{
	Console.WriteLine("That is an even number");
}
Console.ReadLine();

In the example above, it checks if the number is divisable by 2 and if it is it must mean its an even number. Anything divisible by 2 gives no remainder or alternativly gives a remainder 0.

To see past papers and its solutions click here or to read about different topics, click here