Programming 2 (NPRG031), Summer 2025

Instructor: Adam Dingle

Programming 2 will build on our knowledge from Programming 1 and Introduction to Algorithms. The course has several goals:

  1. We will learn the C# language and expand our knowledge of object-oriented programming. We’ll study features shared by C# and other modern languages, such as static typing, classes, inheritance, interfaces, generics and exceptions. 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# or go deeply into its class library. For that, you can take NPRG035 Programming in C# Language, offered in the winter term.)

  2. We’ll study various algorithms and programming techniques including combinatorial recursion, dynamic programming and game-playing algorithms.

  3. We’ll learn about event-driven programming and graphical interfaces, and will discuss how to build larger programs using object-oriented design.

  4. If time permits, we may also discuss other topics such as regular expressions, recursive-descent parsing, multithreaded programming, network programming, and/or writing interpreters.

lectures and other meetings

requirements

To successfully complete this class, you must:

  1. Complete a number of programming exercises through the semester, which your tutorial teacher will assign weekly. You can submit your solutions to ReCodEx. You will need to earn at least 70% of the possible points for these exercises.

  2. Write a program in C# as a semester project. Your program should accomplish something that is interesting, and should be more substantial than your semester project for Programming 1. It should be written in an object-oriented way, making good use of classes and other features we have learned in this course. A typical project for Programming 2 might be 300-500 lines long. Here are some project ideas. Please send your tutorial teacher a project proposal by Sunday, May 4th. A first working version of your project is due by Sunday, June 9th. A final version of your project is due by Sunday, June 15th.

  1. Take an exam at the end of the semester. In the exam you'll need to write several programs in C#. You may attempt the exam up to three times during the exam period (May 26 - June 30). I will not offer the exam again after June 30th.

  2. Regularly attend the lectures and tutorials.

You may not use GPT, Copilot or other AI tools to generate code that you submit in any homework assignment or semester project in this course. Any use of such tools is considered cheating and may disqualify you from passing the class.

textbooks

resources

syllabus

This is a rough plan for this class; it will probably evolve as the semester goes on.

Feb 17 (notes) (exercises)
Introduction to C#. Hello, world. Writing a Main() method. Implicit namespaces. Variables. Comments and whitespace. Integral data types: int, long. Unsigned types. The bool type. Arithmetic, boolean, and relational operators. Flow control: if, while, for. Break and continue. The char type. Characters and Unicode.
Feb 24 (notes) (exercises)
Strings. Indexing strings. Arithmetic overflow. Numeric and character conversions. Type casts. Floating-point types. Value and reference types. Null. Nullable types. The null-forgiving operator (!). Reading input. Standard library methods. String interpolation. Foreach. The 'do' statement. The conditional operator (?:). Arrays. Splitting and joining strings. Rectangular and jagged arrays. Lists.
Mar 3 (notes) (exercises)
Command-line arguments. File input/output. Reading all input lines. Closing files with 'using'. The 'switch' statement. Functions. Expression-bodied functions. Output and reference parameters. Variable numbers of arguments. Tuples. Named tuples. Type aliases. Classes. Fields. Methods. Access levels. Constructors. 'this'.
Mar 10 (notes) (exercises)
Preincrement and postincrement operators. Optional parameters. Named arguments. Enums. Overloaded methods and constructors. Static members, static classes. Constants. Properties. Indexers. Operator overloading.
Mar 17 (notes) (exercises)
Inheritance. Overriding the base class. Constructor chaining. Virtual methods. Accessing base members. Protected members. Subtyping. Conversions between base and derived types. The 'is' and 'as' operators. Abstract classes and methods. The top-level 'object' class. The Equals() method. Interfaces. Interface inheritance. Single and multiple inheritance. Generic methods. Generic classes. Generic interfaces. Collection classes in the standard library.
Mar 24 (notes) (exercises)
'var'. Exceptions. try/catch. Generic method constraints. Generic class constraints. IComparable. Nested classes. Delegates. Lambda expressions. Extension methods. Linq methods.
Mar 31 (notes) (exercises)
Combinatorial recursion. Exhaustive search with backtracking. N queens. Plotting.
Apr 7 (notes) (exercises)
One-dimensional dynamic programming.
Apr 14 (notes) (exercises)
Two-dimensional dynamic programming.
Apr 21
No lecture (Easter Monday)
Apr 28
Game playing. Minimax. Depth-limited searching. Extreme value pruning. Alpha-beta pruning. Negamax. Simple games.
May 5
Events in C#. Introduction to GTK. Drawing with Cairo. Mouse and keyboard input. Animation in GTK.
May 12
Regular expressions. Records. Extracting data from text. Least-squares regression.
May 19
Other topics, time permitting.