COS1511 is not just about learning C++; it is about learning how to think like a computer. Many students fail this module not because they don’t understand the theory, but because they cannot write code that compiles on a piece of paper (or in an exam environment).
This guide moves beyond the textbook definitions to show you the specific structures and logic you need to master to pass this module.

1. The Foundation: Variables and I/O
In C++, syntax is everything. A missing semicolon (;) or a wrong bracket is a fatal error.
- Data Types: You must know when to use
int(whole numbers),double(decimals),char(single letters), andbool(true/false). - Input/Output: This is where 20% of errors happen.
- Output: Use
cout <<. Think of the arrows pointing out of the program to the screen. - Input: Use
cin >>. Think of the arrows pointing into the variable.
- Output: Use
- Exam Tip: Never forget
#include <iostream>andusing namespace std;at the top of your code. If you forget them, nothing works.
2. Control Structures (The Logic)
This allows your program to make decisions.
If-Else
Be careful with the equality operator.
if (x = 5)assigns 5 to x (Logic Error).if (x == 5)checks if x equals 5 (Correct).
Loops
You need to know which tool to use for the job.
- For Loop: Use this when you know exactly how many times to repeat (e.g., “Enter 5 marks”).
- While Loop: Use this when you don’t know when it will end (e.g., “Enter marks until user types -1”).
- Do-While: Use this for menus. It ensures the menu displays at least once.
3. Functions (The “Modular” Approach)
This is usually the biggest section of the exam paper. You need to break a big problem into small pieces.
Void vs. Value-Returning
- Void: Performs a task (like displaying a menu) but gives no answer back. You call it by just writing its name:
displayMenu();. - Value-Returning: Calculates something (like
calcAverage) and sends it back. You must use the answer:answer = calcAverage();.
Parameters
This is the distinction-level concept.
- Pass by Value: The function gets a copy of the variable. Changes inside the function don’t affect the original.
- Pass by Reference (
&): The function gets the address of the variable. Changes inside the function do change the original. You typically use this when a function needs to change more than one value.
4. Arrays and Strings
- Arrays: Lists of variables.
- The Trap: C++ starts counting at 0. If you declare
int arr[5], the last element isarr[4]. If you try to accessarr[5], you crash the program.
- The Trap: C++ starts counting at 0. If you declare
- Strings: You will likely use
apstringor standardstring. Know how to concatenate (join) them using+and how to read a full line of text (including spaces) usinggetline(cin, name).
5. Pointers (The Advanced Section)
This is often considered the most difficult topic in first-year programming.
- The Concept: A variable holds a value (e.g., 50). A pointer holds the address where that 50 is stored in memory.
- The Operators:
&(Address-of): Tells you where a variable is.*(Dereference): Tells you what is inside that address.
- Don’t panic if this feels abstract; focus on the basic syntax of declaring (
int *ptr) and assigning (ptr = &x) pointers.
Decksh’s Top 3 Tips for a Distinction
Tip 1: Master the “Trace Table”
In the exam, you will be given a piece of code and asked “What is the output?”.
- Do not guess. Draw a table with a column for every variable.
- Step through the code line by line, updating the values in your table. This is the only way to track loops accurately.
Tip 2: Write Code on Paper
It feels unnatural, but you must practice writing code by hand.
- In the exam, you don’t have a compiler to tell you that you missed a bracket
}. - Practice writing out full programs (Main function, variables, logic) on blank paper, then type it into a computer to see if it runs.
Tip 3: Understand Scope
- Know the difference between a Local Variable (exists only inside a function) and a Global Variable (exists everywhere, but generally bad practice).
- If you try to use a variable declared in
calcTotalinsidemain, you will get an error.
Conclusion
COS1511 is a language course. You are learning to speak “C++”. The only way to get fluent is to speak it every day. Do not just read the textbook; write the code. If you can master Functions and Loops, you will pass.
Good luck!