COMP20021: Imperative Programming with C and C++ (2007-2008)
This course unit introduces students to the C and C++ programming languages and the tools used to support them.
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 outcomesLearning 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 OutcomesA2, A3, B2, B3, C5, C6, D4
Introduction and Motivation 
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++
I/O in C 
File handling, incompatibilities between operating system versions (e.g. handling of carriage return)
Esoteric Features 
Variable parameter function calls, dark and scary features (`,', `?:', goto, break, continue) Variations on a theme: overview of Objective C, C# and C++ 
Basic C++ 
Simple class definition, similarities with Java (private, public, protected). Constructors and Destructors.
Inheritance and Virtual Functions 
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 
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 
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 
How C++ classes are `implemented in C'; constructors and destructors and virtual functions. What inherited classes look like in memory.
C++ Type system 
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 
Side effects, obfuscated C, dangers of multiple inheritance, mad operator overloading. Use const.