
The S6 Computer Science 2024 National Examination, sat on 29 July 2024 under NESA, covers hardware, networking, databases, and programming in Java, C++, VB, and HTML: a wide spread of topics for the MCE and MPC combinations. This guide walks through every question step by step, explaining not just the correct answer but the reasoning behind it, so you can apply the same thinking to similar questions on your own exam.
If you're revising for Advanced Level Computer Science more broadly, our full library of past papers is organized on the NESA past papers worked solutions hub.
DOWNLOAD THE PASTPAPER TO GO ALONG WITH ANSWERS S6 Computer Science 2024 Full worked Solutions
The paper has three sections. Section A is compulsory, worth 55 marks, and covers a mix of multiple choice and short-answer questions on hardware, networking, databases, and programming basics. Section B asks you to choose any 3 of 5 questions worth 30 marks, focused on algorithms, networking, SQL, and programming in Java and VB. Section C asks you to choose just 1 of 2 longer questions worth 15 marks, on HTML forms or C++ control flow. You have 3 hours to complete the paper.
The question asks which statement best describes a computer virus, out of four options about replicating programs, spyware, data theft, and website blocking.
Step by step: A virus is defined by one specific behavior: it makes copies of itself and spreads to other files or computers, usually by attaching itself to a program or document. The other options describe different kinds of malware. Monitoring users without consent describes spyware, stealing information describes a trojan or keylogger, and blocking website access describes a different tool entirely, such as a firewall rule or malicious redirect, not a virus.
Answer: a) A program that replicates itself and spreads to other computers.
This question gives you four laptop parts and four functions, and asks you to match them correctly.
Step by step: Think about what each part physically does when you use a laptop. The battery stores and supplies electrical energy, so its job is to power the device. The display is the screen, so its job is showing you visual output. The keyboard is what you press to type letters and commands. The trackpad is what you slide your finger across to move the cursor.
Answer:
a) Battery → 2) Powers the laptop
b) Display → 1) Provides visual output
c) Keyboard → 3) Used for text and command input
d) Trackpad → 4) Enables cursor movement and control
System software is the software that manages and supports the computer itself, rather than software you use directly for tasks like writing documents or browsing the internet.
Step by step: To answer this, think about all the different jobs system software has to do behind the scenes: running the computer at all, translating human-written code into something the machine understands, keeping the computer running efficiently, and connecting hardware devices so they work properly.
Answer: The four sub-categories of system software are:
This question compares two types of network cabling and asks you to identify the correct set of advantages and disadvantages.
Step by step: Fiber optic cable transmits data as pulses of light through a glass or plastic core, rather than electrical signals through copper wire like twisted pair cable does. Light travels faster and with far less signal loss than electricity through copper, which is why fiber supports much higher bandwidth and can carry a signal much farther before it needs to be boosted. The trade-off is that fiber optic cable and the equipment needed to install and repair it are significantly more expensive, and installation requires specialized skill and tools compared to simply crimping a copper cable.
Answer: a) Advantages: higher bandwidth, longer distances; Disadvantages: higher cost, more difficult to install.
This question asks you to distinguish between two ways a computer keeps track of memory locations.
Step by step: When you write a program, you never actually specify the real, physical location in RAM where your data will be stored, since that would be impractical given that the operating system may place your program's data anywhere in physical memory, and that location can even change while the program runs. Instead, the programmer works with logical addresses, which are the memory references visible to the program itself. The operating system then translates these logical addresses into the actual physical addresses in the RAM hardware, a process called address translation.
Answer: b) Logical addressing refers to memory locations visible to the programmer, while physical addressing refers to actual memory locations.
Step by step: Start by defining the term itself. "Multi" means many, and "media" refers to forms of communication or content. Multimedia is therefore the combination of more than one type of content, such as text, images, audio, video, and animation, presented together, often with the ability for the user to interact with it.
Answer: Multimedia is content that combines multiple forms of media, such as text, graphics, audio, video, and animation, often integrated and delivered together through a computer or digital device, frequently with interactivity that lets the user control what they see or hear, for example clicking to play a video or navigating through slides. Traditional media, by contrast, typically presents only a single form of content at a time and offers no interactivity: a newspaper is text and static images only, and the reader cannot interact with it beyond turning pages; a radio broadcast is audio only, and the listener cannot pause, rewind, or click anything. The key differences are: (1) multimedia combines several content types while traditional media usually uses just one, (2) multimedia is often interactive while traditional media is passive, and (3) multimedia typically requires a digital device to access, while traditional media, such as print, radio, or standard television, does not.
Step by step: Think about what could go wrong with a database: hardware failure, accidental deletion, a software bug corrupting records, a cyberattack, or a natural disaster affecting the server. A backup is a saved copy of the database that lets you restore lost or damaged data after any of these events.
Answer: Database backups are important because they protect an organization against permanent data loss from hardware failure, accidental deletion, corruption, malicious attacks such as ransomware, or natural disasters. Without a backup, this data, including customer records, financial transactions, and academic records, could be lost forever, which can be catastrophic for a business or institution and may also breach legal data-retention obligations.
A sound backup strategy would include: (1) Full backups taken on a regular schedule, for example weekly, which copy the entire database; (2) Incremental backups taken more frequently, for example daily, which only save the changes made since the last backup, saving time and storage space; (3) Offsite or cloud storage for backup copies, so that a fire, theft, or disaster at the primary location doesn't destroy the backups along with the original data; and (4) Regular restore testing, meaning periodically practicing restoring the database from a backup to confirm the backup actually works, since a backup that has never been tested may fail when you need it most.
JDBC (Java Database Connectivity) is how a Java program, such as a servlet in a web application, talks to a database like MySQL.
Step by step: Think about this logically, in the order a program actually needs to do things. Before Java can talk to MySQL at all, it needs to load the special driver software that knows how to communicate with that particular database. Only after the driver is loaded can the program actually open a connection to the database. Once connected, the program needs a "statement" object, which is essentially a container for the SQL command it's about to send. Only after all of that is set up can the program actually execute the query and get results back.
Answer: a) Load driver, establish connection, create statement, execute query.
This question has two parts: how friend functions violate encapsulation, and when they should be used.
Step by step, first recall what encapsulation means. Encapsulation is the principle that a class's private data should only be accessible through that class's own member functions, not from outside code. This protects the data from being changed in unexpected or incorrect ways by code that has no business touching it directly.
Now think about what a friend function actually does. A friend function is declared inside a class using the keyword friend, but it is not a member of that class; it's an outside, standalone function. Despite being outside the class, a friend function is given full access to that class's private and protected members, exactly as if it were a member function.
How this violates encapsulation: Because a friend function can read and modify a class's private data directly from outside the class, it breaks the normal rule that only the class's own member functions can touch that private data. This creates a loophole in the protective barrier that encapsulation is supposed to provide, since now there is at least one piece of external code with the same level of access as the class's internal methods.
When friend functions should be used: Despite this, friend functions have legitimate uses and should be used sparingly and deliberately, not as a general shortcut. They are most appropriate when: (1) you need to overload an operator (like + or <<) where the left-hand operand is not an object of your class, so a normal member function wouldn't work naturally; (2) two classes need to work very closely together and repeatedly need access to each other's private data, and writing many getter and setter functions would be more cumbersome and no more secure than a single friend declaration; or (3) a standalone function genuinely needs to operate on the private members of two different classes at once, which a member function belonging to only one class cannot do cleanly.
a) The purpose of file handling in C++:
Step by step: Without file handling, all the data a program creates while it runs, including variables, arrays, and user input, disappears the moment the program closes, because it only exists in the computer's temporary memory (RAM). File handling solves this by letting a program save data to a file on permanent storage, like a hard drive, so that data still exists after the program ends, and can be read back in again later.
Answer: The purpose of file handling in C++ is to allow a program to store data permanently on a storage device and to retrieve that data again later, even after the program has closed or the computer has been restarted, which would not be possible with data held only in memory.
b) Four tasks you can perform in file handling:
<< insertion operator with an output file stream.>> extraction operator with an input file stream.Other valid tasks include appending data to an existing file without erasing what's already there, and deleting a file.
Step by step: A string, in programming, is simply a sequence of characters treated as a single piece of text data, like a word, sentence, or name. In C++, strings can be handled using the built-in string data type from the standard library.
Answer: A string is a sequence of characters (letters, numbers, symbols, and spaces) stored and treated as a single unit of text, such as "Kigali" or "Mathrone Academy".
Two examples of C++ string functions:
length(): returns the number of characters in a string. For example, myString.length() would return 7 for the string "Rwanda!".substr(): extracts and returns a portion of a string. For example, myString.substr(0, 3) would return the first three characters of the string.The program declares an integer array age with five values, then loops through it printing each element with its index.
int[] age = {1, 0, 5, 0, 5}; for (int i = 0; i < 5; ++i) { System.out.println("Element at index " + i + ": " + age[i]); }Step by step: In Java, array indexing starts at 0, not 1. So age[0] is the first value, age[1] is the second, and so on. The array holds the values {1, 0, 5, 0, 5} in that exact order, at index positions 0, 1, 2, 3, and 4. The loop runs once for each index from 0 up to (but not including) 5, printing the index number and the value stored there.
Answer (the exact output):
Element at index 0: 1 Element at index 1: 0 Element at index 2: 5 Element at index 3: 0 Element at index 4: 5Step by step: Think about what "efficiency" actually means in this context. It's not about how the application looks, but about how well and how quickly it performs its core job, which here is connecting to a database and getting data back. Font size and variable naming have no effect on runtime performance; the number of controls on a form affects the interface, not database performance.
Answer: c) The time taken to retrieve and display data from the database. This directly measures how efficiently the connection and query are performing, which is what "efficiency of database connectivity" is actually asking about.
Step by step: A two-dimensional array is like a grid or table, with rows and columns, rather than a single list. Since 14 doesn't divide evenly into a perfectly square grid, a sensible choice is a 2×7 array (2 rows, 7 columns) or 7×2 (7 rows, 2 columns); either works, since 2×7=14. Below is a 2×7 version. The algorithm needs two nested loops: an outer loop for the rows and an inner loop for the columns, so that every cell in the grid is visited exactly once for both reading input and displaying it.
Start Declare array A[2][7]// Step 1: Read 14 elements into the array For i = 0 to 1 // loop through rows For j = 0 to 6 // loop through columns Read A[i][j] End For End For
// Step 2: Display the 14 elements For i = 0 to 1 For j = 0 to 6 Display A[i][j] End For End For
Stop
The outer loop moves down through each row, and for each row, the inner loop moves across each column. This pattern of "outer loop for rows, inner loop for columns" is the standard way to process every cell of a 2D array exactly once.
Step by step: Think about what becomes possible once computers are connected together that isn't possible when they're isolated from each other.
The table needs these columns: id (integer), firstname (character, 20), secondname (character, 20), and birth (date).
a) Creating the student table:
CREATE TABLE student ( id INT, firstname CHAR(20), secondname CHAR(20), birth DATE );Step by step: CREATE TABLE tells the database you're defining a new table. Each column is listed with its name and data type: INT for whole numbers (the id), CHAR(20) for fixed-length text up to 20 characters (the names), and DATE for calendar dates (the birth date).
b) Adding a "schoolname" column before "firstname":
ALTER TABLE student ADD schoolname CHAR(20) AFTER id;Step by step: ALTER TABLE is the command used to change the structure of an existing table, rather than creating a new one. The keyword AFTER id tells the database exactly where to insert the new column, right after id, which places it immediately before firstname in the table's column order, exactly as required.
c) Creating a read-only user account:
CREATE USER 'school'@'rwanda' IDENTIFIED BY 'schl@123'; GRANT SELECT ON school.* TO 'school'@'rwanda';Step by step: The first line creates a new database user with the given username and password. The second line grants that user permission, but only the SELECT permission, which means "allowed to fetch/read data," and specifically nothing else (no INSERT, UPDATE, or DELETE), matching the requirement that the account should only be allowed to fetch data from the school database.
d) Query for students whose firstname ends with 'h' and has exactly six letters:
SELECT * FROM student WHERE firstname LIKE '_____h';Step by step: In SQL, LIKE is used for pattern matching in text. The underscore character _ is a wildcard that matches exactly one character, so five underscores in a row means "any five characters," and following them with h means the sixth and final character must be an "h". Together, '_____h' matches any firstname that is exactly six characters long and ends in "h": for example, "Yusuph" would match, but "Sarah" (five letters) or "Elizabeth" (nine letters) would not.
import java.util.ArrayList; import java.util.Collections;public class StudentNames { public static void main(String[] args) { ArrayList<String> names = new ArrayList<String>();
// Step 1: Add student names to the list names.add("Uwase"); names.add("Karangwa"); names.add("Mutoni"); names.add("Habimana");
// Step 2: Sort the names alphabetically Collections.sort(names);
// Step 3: Display the sorted names for (String name : names) { System.out.println(name); } } }
Step by step: An ArrayList is used instead of a plain array because it can grow or shrink in size as needed, which is more flexible for a changing list of student names. Names are added one by one using the .add() method. The Collections.sort() method, part of Java's built-in library, automatically rearranges the list into alphabetical order for you; you don't need to write your own sorting logic. Finally, a for-each loop prints each name, one per line, now in alphabetical order.
Expected output for the names above:
Habimana Karangwa Mutoni UwaseDim i As Integer Dim sumEven As Integeri = 0 sumEven = 0
While i <= 50 If i Mod 2 = 0 Then sumEven = sumEven + i End If i = i + 1 Wend
MsgBox "Sum of even numbers from 0 to 50 is: " & sumEven
Step by step: Two variables are set up: i, which counts upward from 0, and sumEven, which stores the running total. The While...Wend loop keeps repeating as long as i is 50 or less. Inside the loop, i Mod 2 = 0 checks whether i divides evenly by 2 with no remainder; this is how you test if a number is even in code. If it is even, that value is added to sumEven. After each pass through the loop, i is increased by 1, and the loop checks the condition again, continuing until i exceeds 50.
Answer (final result): The sum of even numbers from 0 to 50 (0+2+4+6+...+50) is 650.
<!DOCTYPE html> <html> <head> <title>User Registration</title> </head> <body><h2>User Registration Form</h2>
<form action="register.php" method="post">
<label for="name">Full Name:</label><br> <input type="text" id="name" name="name" required><br><br>
<label for="email">Email Address:</label><br> <input type="email" id="email" name="email" required><br><br>
<label for="password">Password:</label><br> <input type="password" id="password" name="password" minlength="8" required><br><br>
<label for="dob">Date of Birth:</label><br> <input type="date" id="dob" name="dob" required><br><br>
<input type="submit" value="Register">
</form>
</body> </html>
Step by step, why each part matters for validation:
required is added to every input field. This is a built-in HTML5 attribute that stops the browser from submitting the form at all if that field is left empty, directly satisfying the "must not allow submission with an empty field" requirement.type="email" on the email field doesn't just label it. The browser automatically checks that the entered text is in a valid email format (containing an "@" and a domain) before allowing submission, rejecting invalid entries like "notanemail".type="password" masks the characters as the user types, hiding the password visually, and the minlength="8" attribute prevents submission unless the password is at least 8 characters long, which supports basic password security.type="date" on the date of birth field gives the browser a proper date picker and automatically ensures the entered value is a valid, correctly formatted date, rather than accepting arbitrary text.Together, these built-in HTML5 attributes handle both "required field" checking and basic format validation without needing any separate JavaScript code, which is why HTML5 form attributes like these are the simplest and most reliable way to satisfy this kind of requirement.
Step by step: Control flow statements are the instructions that determine the order in which a program's code actually runs. Instead of executing every line strictly from top to bottom, they let a program make decisions, repeat actions, or skip sections. C++ control flow statements fall into three broad groups: decision-making, looping, and jump statements.
1) Decision-making (selection) statements, which choose between different paths:
if statement: runs a block of code only if a given condition is true.if...else statement: runs one block of code if the condition is true, and a different block if it's false.else if ladder: checks multiple conditions in sequence, running the first block whose condition is true.switch statement: compares one variable against several possible fixed values, running the matching block, which is often cleaner than a long chain of else if statements when checking many exact values.2) Looping (iteration) statements, which repeat a block of code:
for loop: repeats a block a specific, known number of times, commonly used when you know in advance exactly how many repetitions you need, for example looping through every element of an array.while loop: repeats a block as long as a condition remains true, checking the condition before each pass. Useful when you don't know in advance how many repetitions are needed.do...while loop: similar to a while loop, but checks the condition after running the block, which guarantees the block runs at least once even if the condition is false from the start.3) Jump statements, which alter the normal flow by skipping or exiting:
break: immediately exits the current loop or switch statement, skipping any remaining iterations or cases.continue: skips the rest of the current loop iteration and jumps straight to the next one, without exiting the loop entirely.goto: jumps program execution directly to a labeled point elsewhere in the code. It exists in C++ but is rarely used in modern programming since it can make code difficult to follow.return: exits a function immediately and optionally sends a value back to whatever part of the program called that function.A pattern worth noticing across this paper: many questions aren't really testing whether you've memorized a specific fact, but whether you can reason from first principles about how a technology actually works, whether that's why fiber optic cable behaves differently from copper, why a friend function bypasses encapsulation, or why a specific SQL wildcard pattern matches certain names and not others. Practicing this kind of step-by-step reasoning, rather than memorizing isolated answers, will serve you well across topics you haven't seen before on exam day.
Mathrone Academy offers Advanced Level Computer Science tutoring for the MCE and MPC combinations, both online and in person in Kigali, alongside an AI Study Tutor for step-by-step practice with programming and database questions. Ready to get support with your own Computer Science revision?
⚠️ Important Disclaimer: The solutions on this page are prepared by the Mathrone Academy team for revision and learning purposes only. This is not an official NESA marking scheme, REB-approved answer guide, or official Cambridge/Pearson mark scheme. While every effort has been made to ensure accuracy, answers and explanations may differ from the official examiners' marking guide. Always refer to your school teacher or the official examination board publications for authoritative marking guidance. Mathrone Academy accepts no responsibility for any discrepancies between these solutions and official results.