Skip to navigation | Skip to main content | Skip to footer

COMP20021: Imperative Programming with C and C++ (2008-2009)

This is an archived syllabus from 2008-2009

Imperative Programming with C and C++
Level: 2
Credit rating: 10
Pre-requisites: COMP10081 or COMP10580
Co-requisites: No Co-requisites
Duration: 11 weeks in first semester
Lectures: 22 in total, 2 per week
Labs: 18 hours in total, 9 2-hour sessions
Lecturers: Aphrodite Galata, Roger Hubbold
Course lecturers: Aphrodite Galata

Roger Hubbold

Additional staff: view all staff
Sem 1 w1-5,7-12 Lecture ROSC A Tue 10:00 - 11:00 -
Sem 1 w1-5,7-12 Lecture CRAW TH.1 Fri 14:00 - 15:00 -
Sem 1 w2,4,7,9,11 Lab LAMB LambLab Thu 11:00 - 13:00 H
Sem 1 w2,4,7,9,11 Lab 3rdLab Mon 14:00 - 16:00 F
Sem 1 w2,4,7,9,11 Lab UNIX Tue 15:00 - 17:00 G
Sem 1 w3,5,8,10,12 Examples UNIX Fri 10:00 - 11:00 H
Sem 1 w3,5,8,10,12 Examples UNIX Thu 10:00 - 11:00 G
Sem 1 w3,5,8,10,12 Examples UNIX Wed 12:00 - 13:00 xtra
Sem 1 w3,5,8,10,12 Examples UNIX Tue 15:00 - 16:00 F
Assessment Breakdown
Exam: 70%
Coursework: 0%
Lab: 30%


This course unit introduces students to the C and C++ programming languages and the tools used to support them.

Learning Outcomes

A student completing this course unit should:

Be able to critically compare C, C++ and Java and identify the strengths and weaknesses of each for a given application area (A2, A3, B3).
Understand the syntax and structure of C and C++ programs (A2).
Be able to design C and C++ programs to meet requirements expressed in English (B2).
Write and debug programs in both languages using appropriate tools (C5, C6).
Use 3rd party libraries of functions or classes (C5).
Understand how C and C++ are implemented on the host architecture (A3).

Assessment of Learning outcomes

Learning outcome (1) is assessed by examination. Learning outcome (2), (4) and (5) in the laboratory, and learning outcome (3), and (6) by both examination and in the laboratory.

Contribution to Programme Learning Outcomes

A2, A3, B2, B3, C5, C6, D4


Introduction and Motivation [1]

What C and C++ are used for (embedded systems, operating systems, real-time systems, device drivers, computer graphics). Brief recap on the CPU/store model. Compilation of Java to its VM and byte-codes compared with compilation of C/C++ to native instructions. Pros and cons of these approaches.
Basic C [2]

Very similar constructs to Java (control statements, loops, basic data types, expression evaluation). Similar rules for variable names, similar variable scope, similar operator precedence. Some of the differences (size of data types not fixed size). Functions not methods.

The anatomy a simple `standalone' C program

Compiling, linking and executing [1]

The compiler and pre-compiler. Header files and libraries. Dynamic and static linking. Running a program. Comparison of command line and IDE compilers.

Introduction to Lab Exercise 1: The Mandelbrot Set [1]

What is the Mandelbrot Set, why is it interesting? Writing a C program from the ground up: some good practice hints. The MSet library and header file. Inspecting a program with nm and ldd. The Mset formula. Progressive refinement. Exploring the set with a mouse.

Aggregate types [1]

Structs and Typedefs, Unions, Arrays and Enums. How these relate to objects/classes or abstract data types.
Pointers and memory management [3]

C Pointers and Java references. Malloc compared to Java's `new'. Manual memory management. Const pointers. Pointers and arrays. Command line arguments. Pointer errors: segmentation faults and bus errors. Examples of dynamic data structures: linked lists, trees.
Function Pointers and callbacks [1]

Comparison with non-final methods in Java / `dynamic binding' of functionality at runtime.

Introduction to Lab Exercise 2: Pangolins [1]

What is a pangolin? A simple expert system, using a tree to store questions. The user things of an object, the program learns how to guess what this object is by accumulating a decision tree of `yes/no' questions. Exercises string manipulation, dynamic data structures (trees) and memory management. Introduces the `valgrind' program to test for memory corruption or leaks. The basic program is extended to have a `load', `save' and `merge' functions.
I/O in C [2]

File handling, incompatibilities between operating system versions (e.g. handling of carriage return)
Esoteric Features [1]

Variable parameter function calls, dark and scary features (`,', `?:', goto, break, continue)

Variations on a theme: overview of Objective C, C# and C++ [1]

Basic C++ [1]

Simple class definition, similarities with Java (private, public, protected). Constructors and Destructors.

Inheritance and Virtual Functions [1]

The QT toolkit as an example of a deep hierarchy of conserved functions. Virtual functions and dynamic binding (comparison with Java methods). Multiple inheritance compared to Java interfaces.

Introduction to Exercise 3: A drawing program [1]

A more complex program. Use of multilple files, a makefile and the linker. Dynamic data structures, a hierarchy of drawing primitives (bitmaps, poly-lines). An event based programming model.

Templates and the STL [2]

Class templates for implementing generic constructs like vectors, stacks, lists, queues that can be used with any arbitrary type. C++ templates provide a way to re-use source code as opposed to inheritance and composition which provide a way to re-use object code. Function templates as a way of building generic algorithms.

C++ behind the scenes [1]

How C++ classes are `implemented in C'; constructors and destructors and virtual functions. What inherited classes look like in memory.

C++ Type system [1]

Old style deprecated casts and coercions. New style casts (const, static, dynamic and void) and the run-time type system.

C and C++ Best practice [1]

Side effects, obfuscated C, dangers of multiple inheritance, mad operator overloading. Use const.