SH

Exam Notes

Exam Structure and Guidelines

  • The exam consists of three sections: A, B, and C.
  • Total number of questions: 33.
  • Closed book exam: No calculators or external materials allowed; only ID and PIN are permitted.

Section A: Multiple Choice (20 Marks)

  • 20 multiple choice questions, each worth one mark.
  • Only one correct answer per question.
  • Topics covered:
    • Variable types
    • Scope of variables
    • Operations on variables
    • Loops
    • Selection statements
    • Boolean logic
    • Random number generation
    • Methods
    • Arrays
    • Lists
    • Basic computer terminology (CPU, RAM, OS, bit, byte, IDE)
  • Review previous years' exams (2018, 2014) available on Moodle.
  • Focus on 2018 and 2014 exams for practice.

Example Questions from Previous Exams

  • Drawing lines to create shapes (understanding draw line statements).
  • Variable assignment and operations: tracing the values of variables after each assignment.
  • Mystery functions: determining what a function does based on its arguments and behavior.
  • Method calling: understanding method signatures (parameters and return types) and predicting results.
  • File reading and parsing: converting strings from file input into numerical data types (integers, doubles).
  • List manipulation: understanding the removeAt method (removes element at a given index).
    • Example: list.removeAt(3) removes the element at index 3.
  • String splitting: using the split method with separators.
    • Example: string.split(",") splits a string into an array of strings using a comma as a separator.
    • Another Example: string.split(" ") splits a string into an array of strings using space as a separator.
  • Binary to decimal conversion.
  • Hexadecimal to decimal conversion:
    • Two hexadecimal digits can represent 2^8 = 256 decimal numbers (since one hexadecimal digit is represented by 4 bits).
  • String concatenation.
  • Acronym for IDE: Integrated Development Environment.
  • Two-dimensional arrays (not included in the current exam).
  • Boolean logic operations.
  • Random number generation:
    • Random.Next(0, 10) generates a number between 0 (inclusive) and 10 (exclusive).
  • Variable scope (class variables vs. local variables).

Section B: Coding Questions (60 Marks)

  • Six questions, each worth 10 marks.
  • Requires writing code.
  • Minor syntax errors (e.g., missing 'e' in WriteLine) will not be heavily penalized.
  • Three requirements for pseudocode questions:
    • Processing the input
    • Handling input errors
    • Performing the calculation

Question 21: Calculation with GUI Input (10 Marks)

  • Similar to written test questions.
  • GUI application: takes input from the user and performs calculations.
  • Parts:
    • Pseudocode (4 marks)
    • C# code (6 marks)
  • Pseudocode requirements:
    • Read input from text box controls.
    • Handle input errors using try-catch blocks.
    • Declare variables of the correct type (e.g., double for decimal numbers).
    • Perform arithmetic operations (+, -, *, /).
  • Input processing:
    • Declare variables and get input from TextBoxControl (returns string type).
    • Parse the string input to the desired type such as int or double.
    • Handle errors using try-catch blocks and display error messages using MessageBox.Show().

Question 22: Selection Statements (if-else) (10 Marks)

  • Tests understanding of if, else if, and else statements.

  • Example 1: Assign message based on score

    string message;
    int score = ...;
    if (score < 50)
        message = "Fail";
    else
        message = "Good";
    
  • Example 2: Extend branch with an "Excellent" category

    string message;
    int score = ...;
    if (score < 50)
        message = "Fail";
    if (score >= 80)
        message = "Excellent";
    else
        message = "Good";
    

Question 23: Loops (for loop) and Drawing Objects on Canvas (10 Marks)

  • Two parts: Pseudocode and C# code.
  • Use a for loop to draw a certain number of objects on a Canvas.
  • Counter-controlled loop: use for when you know the number of iterations.
  • Sentinel-controlled loop: use while to check conditions until a specific condition is true.
  • Drawing objects:
    • graphics.DrawLine(Pen pen, int x1, int y1, int x2, int y2)
      • (x1, y1) is the starting point.
      • (x2, y2) is the ending point.
    • graphics.DrawRectangle(Pen pen, int x, int y, int width, int height)
      • (x, y) is the top-left corner.
      • width and height define the rectangle's dimensions.
    • graphics.DrawEllipse(Pen pen, int x, int y, int width, int height)
      • Similar to DrawRectangle; ellipse is bounded by a rectangle defined by x, y, width, and height.
  • Drawing a circle from the center with radius r:
    • X = X_center - r
    • Y = Y_center - r

Question 24: Methods (10 Marks)

  • Part 1: Write code for a method.
  • Part 2: Use the method in a program.
  • Method definition elements:
    • Access modifier (optional)
    • Return type (e.g., void, int, double)
    • Method name
    • Argument list (type and name for each argument)
    • Method body
    • Return value (if return type is not void)
  • First step: write skeleton solution for Q24.

Question 25: Files (10 Marks)

  • Part 1: Read data from a file, perform calculations, and show the result.
  • Part 2: Process each line of data from a file and write the result to another file.
  • File reading:
    • Open file (e.g., File.OpenText, new StreamReader)
    • Read line by line (ReadLine)
    • Check end of stream (EndOfStream property)
    • Close file (Close)

Question 26: Arrays.

  • Three questions, A, B, and C.

  • Know how to declare an array.

  • Access elements using index (starting from 0).

  • Find the length of array use length property.

  • Two ways to loop array: for loop and for each.

  • Write code to check how many elements meet certain conditions.