Programming 2 (NPRG031), Summer 2024

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# 12 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. Any points that you earn over 90% (up to a maximum of 10%) will be applied as bonus points to your exam score. For example, if your ReCodEx score is 95%, then you will have a 5% exam bonus.

  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 5th. A first working version of your project is due by Sunday, June 9nd. A final version of your project is due by Sunday, June 16th.

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

  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 20 (notes) (exercises)
Introduction to C#. Hello, world. Writing a Main() method. Implicit namespaces. Variables. Comments and whitespace. Integral data types: int, long. The bool type. Arithmetic, boolean, and relational operators. Flow control: if, while, for. Break and continue. The char and string types. Characters and Unicode. Indexing strings.
Feb 27 (notes) (exercises)
Standard library methods. Preincrement and postincrement operators. Unsigned types. Arithmetic overflow. Numeric and character conversions. Floating-point types. Null. Nullable types. Reading input. The null-forgiving operator (!). String interpolation. Foreach. The 'do' statement. The conditional operator (?:). Arrays. Multidimensional and jagged arrays. Lists.
Mar 5 (notes) (exercises)
Command-line arguments. File input/output. Reading all lines. Closing files with 'using'. The 'switch' statement. Tuples. Named tuples. Functions. Expression-bodied functions. Reference and output parameters. Classes. Fields. Methods. Private and public members. Constructors. 'this'.
Mar 12 (notes) (exercises)
Initializing arrays and lists. Value and reference types. Optional parameters. Named arguments. Variable numbers of arguments. Overloaded methods and constructors. Static members, static classes. Properties. Indexers. Operator overloading. Constants. Enums.
Mar 19 (notes) (exercises)
Inheritance. Subtyping. Conversions between base and derived types. The 'is' and 'as' operators. Overriding the base class. Constructor chaining. Virtual methods. Accessing base members. Protected members. Single and multiple inheritance. Abstract methods and classes. Interfaces. Interface inheritance. Collection classes in the standard library.
Mar 26 (notes) (exercises)
'var'. Exceptions. try/catch. The top-level 'object' class. The Equals() method. Generic methods. Generic classes. Generic interfaces. Generic method constraints. Generic class constraints. IComparable. Nested classes. Multiple type parameters. The 'default' operator.
Apr 2 (notes) (exercises)
Delegates. Lambda expressions. Linq methods. Linq syntax. Combinatorial recursion.
Apr 9 (notes) (exercises)
More combinatorial recursion. One-dimensional dynamic programming.
Apr 16 (notes) (exercises)
Two-dimensional dynamic programming.
Apr 23 (notes) (exercises)
Game playing. Minimax.
Apr 30 (notes) (exercises)
Minimax, continued. Depth-limited searching. Extreme value pruning. Alpha-beta pruning. Negamax. Simple games.
May 7 (notes) (exercises)
Events in C#. Introduction to GTK. Drawing with Cairo. Mouse and keyboard input. Animation in GTK.
May 14
No lecture (Rector's Day)
May 21 (notes) (exercises)
Regular expressions. Records. Extracting data from text. Plotting. Least-squares regression.