Object-Oriented Programming

Course Overview

Welcome! This course takes the C++ you already know and builds on it with classes and objects. Over eight weeks you will learn how to group data and the functions that work on it, how to manage memory, how to reuse code through inheritance, and how to make your own types behave like the built-in ones. In short, this course is where you stop writing programs as a list of functions and start designing them as a set of cooperating objects.

Prerequisites

The Structured Programming course. Week 1 revises the parts you need: basic statements, variables, conditionals, loops, functions, pointers, function overloading and arrays. If something there feels new, go back to the Structured Programming notes before moving on.

Textbook

We will use the following textbook. We will also use slides, notes, and other resources as necessary.

C++ How to Program Book Cover
C++ How to Program, by Deitel and Deitel, Prentice Hall, 10th Edition.

References

C++ Programming From Problem Analysis Book Cover
C++ Programming: From Problem Analysis to Program Design, Latest edition, DS Malik.

Course Topics

The first week revises the Structured Programming material. The next four weeks cover classes: how to build them, create and destroy objects, protect data, and manage memory. The last three weeks cover how classes relate to each other and how to make them easy to use: inheritance, polymorphism and operator overloading.

WeekTopic
1Revision: functions, pointers, arrays
2Classes I: constructors, destructors, set and get functions
3Classes I: object parameters, interface vs implementation, arrays of objects
4Classes II: const, static, composition
5Classes II: dynamic memory, this, friend functions and classes
6Inheritance
7Polymorphism
8Operator overloading

Here is what you should expect to achieve by the end of the course:

  • Be able to design and implement classes with constructors, destructors, and properly protected data.
  • Be able to manage memory correctly, using dynamic allocation, deep copies and destructors.
  • Be able to reuse and extend code through composition, inheritance and polymorphism.
  • Be able to write natural, readable code by overloading operators for your own classes.

Tools

C++ Logo
C++
We will learn object-oriented programming in C++!
Visual Studio Logo
Visual Studio
This is the IDE (Integrated Development Environment) you will use for programming in C++. While you are allowed to use other IDEs, this is the one we will use in the classroom and provide support for. [download] [Installation Guide]

Frequently Asked Questions

Studying for this course

How do you suggest I study for this course? Make sure that you do the following every week:
  1. Read the lectures (from the Course Notes page) and make sure you understand them. Go to office hours and ask questions if you have difficulty understanding something.
  2. Type and run every example yourself. Do not only read the code. Change it, break it, and see what happens.
  3. Solve the weekly worksheet over the weekend, then at the beginning of the following week resolve any issues you faced.
This requires good time management. If you manage to follow the read (during the week), solve (over the weekend), ask (at the beginning of the following week) cycle, you should be in good shape!
I forgot a lot from Structured Programming. Am I going to be lost? No. That is exactly why Week 1 is a revision. Go through it slowly, and if a topic still feels weak, use the Structured Programming notes. Pointers and functions matter the most, because Weeks 5 to 7 build on them.
I already know a lot of programming. This course is too easy for me. Great! This is good news, not bad news. This means that you can get good grades in the course and work more on improving your skills in programming. Here are a few notes.
  • Check the Resources page. There are exercises there to improve your skills.
  • Help others. Students might ask questions on social media groups. Your expertise is needed in answering student questions.
  • Be respectful of others. It can be easy to (unintentionally) put others off by making them feel inferior. Be conscious about how you answer and ask questions during lectures, or when students seek your help!
I understand the lectures and examples, but I struggle to write my own classes. Understanding a class someone else wrote is very different from designing one from scratch. Here is how to bridge that gap:
  • Start from the main function: Write the code you wish you could write (Date d(7, 10, 2023); d.print();), then build the class that makes it work.
  • Trace with pen and paper: Draw each object as a box with its data members, and follow the program line by line, especially for constructors and destructors.
  • Embrace the Struggle: Getting stuck on a new question is the most important part of learning. Don't rush to the answer key immediately.