NPRG031 Programming II (summer 2017-8)

Instructor: Adam Dingle

Programming II is a fast-paced course that will build on our knowledge from Programming I. The course has several goals:

  1. We will learn the fundamentals of the C# language. We’ll study a number of features that are shared by C# and many other modern programming languages, such as classes, inheritance, interfaces, generics, exceptions, and lambda expressions. We will also study the C# collection class hierarchy and will learn to build our own collection classes.

    We will not attempt to cover every feature of C# 7 or go deeply into its class library; for that, you can take NPRG035 C# Language and .NET Framework, offered in the winter term.

  2. We’ll study various algorithms, data structures and programming techniques including hash tables, dynamic programming, recursive-descent parsing, informed (heuristic) searching and game-playing algorithms.

  3. We’ll learn how to build larger programs. We will discuss basic principles of object-oriented design. Toward the end of the semester, we’ll look at how to build programs in various practical domains and will work through some extended examples. One such domain will be graphical user interfaces. Others may include network, database and/or game programming depending on how much time we have and on students’ interests.

Lectures and other meetings


To successfully complete this class, you must:

  1. Complete a number of programming exercises through the semester. I will assign these exercises weekly, and you can submit your solutions to the ReCodEx automated grading system. You will need to earn at least 70% of the possible points in ReCodEx.

  2. Write a program in C# as a semester project. Your program should accomplish something that is interesting, cool, or fun and should be more substantial than your semester project for Programming I. A typical project for Programming II might be 300-500 lines long.

  3. Take an exam at the end of the semester.

  4. Regularly attend the lectures and tutorials and participate in class.


You can purchase these books in PDF format via the links above.



This is a rough plan for the sequence of topics we will cover in this class. It will probably evolve as the semester goes on.

Feb 20 (tutorial notes)
Local variables and assignment. Integer types, bool, char, string. Floating-point and decimal types. Arithmetic and Boolean operators. Compound assignment operators. String interpolation. Flow control: if, while, do/while​​​. Accessing methods and properties in the base class library.
Feb 27 (tutorial notes) (exercises)
Variable scope. More flow control: for, foreach, break, continue, switch, goto. Implicit and explicit type conversions. Writing static methods. Parameters and arguments. The return statement. Expression-bodied methods. Arrays. The 'new' operator. Multidimensional and jagged arrays. Calling constructors and operators in the base class library. The 'using' directive. File I/O.
Mar 6 (lecture notes) (lecture/tutorial examples) (exercises)
Verbatim strings. Format strings. The conditional operator (?:). Reference and output parameters. Out variables. TryParse. Parameter arrays. Overloaded methods. Value and reference types. Null. Encapsulation via abstract data types. Defining classes and instance methods. The 'this' keyword. 'public' and 'private' access modifiers. Defining constructors. Default constructors. Overloading constructors. Constructor chaining. Overriding ToString().
Mar 13 (lecture notes) (lecture/tutorial examples) (exercises)
Increment and decrement operators. Equality. Passing reference types by value and reference. Nullable types and conversions. Null-coalescing (??) and null-conditional (?.) operators. Enums. Static fields. Static constructors. Static classes. Defining properties. Indexers. Operator overloading. Resizable arrays. Linked data structures.
Mar 20 (lecture notes) (lecture/tutorial examples) (exercises)
Assignment expressions. The 'is' operator. Polymorphism. Interfaces. Casting between base and derived types. The 'as' operator. Interface inheritance. Multiple interface inheritance. Explicit and implicit member implementation. Implementation inheritance. Virtual methods. The 'override' modifier. Calling base class methods. Defining structs. Streams.
Mar 27
Readonly fields. Inheritance in the standard library. Calling base class constructors. The 'protected' access modifier. Abstract classes. Sealed classes and methods. Inheritance versus containment. Model-view separation. Hash functions. Hash tables. Chaining. Open addressing with linear probing. Dynamically growing hash structures. The System.Object class. Overriding Equals() and GetHashCode(). Exceptions. throw, try/catch/finally. Optional parameters. Named arguments. Finalizers. The 'using' statement. Nested methods. Conversion operators.
Apr 3
Generic methods, classes and interfaces. Multiple type parameters. Covariance and contravariance. Array covariance. Generic constraints. Implicitly typed variables. Collection interfaces and classes. Lists, stacks, queues, dictionaries. Collection initializers. Extension methods on classes and interfaces. Checked and unchecked conversions. Overflow and modular arithmetic. Bitwise operators. Representation of signed integers and floating-point numbers.
Apr 10
Events. Programming graphical interfaces. The GTK# toolkit.
Apr 17
Delegate types. Lambda expressions. Statement lambdas, expression lambdas. Outer variables. Map and filter functions on sequences. Standard query operators: Where(), Select(), Count(). Deferred execution.
Apr 24
Recursive-descent parsing. Dynamic programming. Top-down and bottom-up approaches. Optimal substructure, overlapping subproblems.
May 1
No lecture (state holiday).
May 8
No lecture (state holiday).
May 15
Informed (heuristic) searching. The greedy and A* search algorithms. Admissible heuristics.
May 22
Game playing. The minimax algorithm. Alpha-beta pruning.