CS 330: Lecture 22 – Templates

Dear students, The most common application of templates is to create reusable collections. But in C++ we can also pass the compiler a value to help it specialize the templated pattern. For example, suppose we want lightning fast multiplication. Let’s take a first stab, which is anything but lightning fast: int multiply(int a, int n) […]

CS 330: Lecture 21 – Parametric Polymorphism

Dear students, Don’t get me started on arrays in C. What sort of world is this where an array is fixed in size, but yet it doesn’t know what that size is? We must fix this. Let’s create a growable array: class Flexray { public: Flexray() : capacity(10), nitems(0), elements(new int[capacity]) { } ~Flexray() { […]

CS 318: Lab 15 – Midterm

Dear students, Today we have a midterm. I’m cheering for you. Here’s your TODO list for next time: Complete CSS Diner, a game for learning a whole new set of CSS selectors that we will use throughout the second half of the semester. Read chapter 9 in your book. On a quarter sheet, share 2-3 […]

CS 330: Lecture 20 – Midterm Review

Dear students, Today we’ll go over the midterm together. It’s too good an opportunity to pass up. A bunch of problems that you’ve all looked at before class. Sincerely,

CS 318: Lab 14 – Viewport Parallax

Dear students, Let’s shake things up a bit today. When game developers get together to build a game in a very short amount of time, they call that a game jam. We will have a web jam. I want to devote all of today’s lab time to that, so I won’t be doing any talking. […]

CS 330: Midterm

See the PDF.

CS 330: Lecture 19 – Vtables

Dear students, Did you know that in the early days of C++, it was just a thin veneer over C? Classes were just syntactic sugar. We might have had a class that looked like this: class Hero { public: Hero(char *name, int hp) { this->name = strdup(name); this->hp = hp; } void cure(int boost) { […]

CS 330: Lecture 18 – Memory

Dear students, We’ve been talking about memory a fair bit lately, and I think it’s helpful that we have a clear picture of what’s happening when we run an executable. So, let’s have a quick discussion. When we double-click on a program or invoke it in the shell, the machine code for that program gets […]

CS 318: Lab 13 – Responsive Design

Dear students, Today we begin our investigation into responsive design, the central mechanic of which is selectively applying styles based on the viewing context. You have one style for large desktop displays, another for tablets, another for phones, and so on. In general, we might do the following on smaller screens: Remove images or present […]

CS 330: Lecture 17 – Subtype Polymorphism

Dear students, As we discussed last time, polymorphism is the pursuit of code that works with many types. It manifests itself in several forms that we’ve been discussing: Coercion, in which we have a value of type X and an operation that expects type Y, but there’s a known path for converting Xs into Ys. […]