Programming 2 (NPRG031), Summer 2023

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# 10 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, 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 ReCodEx exercises. Any points that you earn over 85% (up to a maximum of 15%) will be applied as bonus points to your exam score. For example, if your ReCodEx score is 90%, 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 Monday, May 15th. A first working version of your project (in Nese Günes's tutorial only) is due by Tuesday, August 15th. A final version of your project is due by Sunday, September 10th.

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

  2. Regularly attend the lectures and tutorials.

textbooks

resources

syllabus

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

Feb 13 (notes) (exercises)
Introduction to C#. Hello, world. Writing a Main() method. Implicit namespaces. Variables. Comments and whitespace. Integral data types: int, long, byte. Integer overflow. The bool type. Arithmetic, boolean, and relational operators. Flow control: if, while. The char and string types. Null. Nullable types. The null-forgiving operator (!). Reading input.
Feb 20 (notes) (exercises)
Unsigned integral types. Numeric conversions. Floating-point numbers. For loops. Preincrement and postincrement operators. Break and continue. Characters and Unicode. Indexing strings. Foreach. String interpolation. Arrays. Multidimensional and jagged arrays. Functions.
Feb 27 (notes) (exercises)
'using static'. The 'do' statement. The 'switch' statement. The conditional operator (?:). Tuples. Named tuples. Expression-bodied functions. Optional arguments. Variable numbers of arguments. Reference and output parameters. Classes. Fields. Private and public members. Constructors. 'this'. Methods. Overloaded methods and constructors.
Mar 6 (notes) (exercises)
Enums. Value and reference types. Constants. Constructor chaining. Static members, static classes. Properties. Indexers. Operator overloading.
Mar 13 (notes) (exercises)
Inheritance. Conversions between base and derived types. The 'is' and 'as' operators. Single and multiple inheritance. Overriding the base class. Virtual methods. Accessing base members. Protected members. Abstract methods and classes. The top-level 'object' class. Interfaces. Interface inheritance. Generic classes and interfaces. Generic constraints. The 'var' keyword. Collection classes in the standard library.
Mar 20 (notes) (exercises)
Command-line arguments. Exceptions. try/catch. Disposing resources with 'using'. Local methods. Generic methods. Nested types. Delegates. Lambda expressions. Events.
Mar 27 (notes) (exercises)
Combinatorial recursion. Exhaustive search. N queens. Iterators. The 'yield' statement.
Apr 3 (notes) (exercises)
Exhaustive search in graphs. Dynamic programming. One- and two-dimensional dynamic programming problems.
Apr 10
No lecture (Easter Monday)
Apr 17 (notes) (exercises)
Game playing. Minimax.
Apr 24 (notes) (exercises)
Depth-limited searching. Extreme value pruning. Alpha-beta pruning. Negamax. Simple games. Introduction to GTK. Drawing with Cairo. Mouse and keyboard input. Animation.
May 1
No lecture (May Day)
May 8
No lecture (Victory Day)
May 15 (notes) (exercises)
Text processing. File formats (CSV, JSON, XML). Regular expressions. Records in C#.
May 22 (notes)
Writing larger programs. Organizing and structuring code. Debugging. Optimization. Performance profiling.