Overview
This week we will take time to reinforce and deepen our understanding of how to create objects in C++.
UPDATE: The next CPE practice session will be Saturday, December 14, between 11 am and 5 pm. The planned Saturday, December 7 session has been cancelled!
Project: Have a Little Class!
Motivation
The learning objectives of this project are:
- to gain practice separating C++ objects into their three parts: header file, source file, and testing program.
- to practice with the use of doctest for the last of these parts.
Process
- Meet your new partner. This is a paired project, and the psuedorandomly selected pairs for it are for 1B: Noah and Eleanor, Conrad and Alex, Gabriel and Dylan, Jake and Donovan, Alessandra and Toby, Grant and Udval, Evan and Zach, Fatima and Sean, Nikita and Rockwell, with poor Luis having to work alone. For 4B we have: Rohoboth and Alex, Blu and Gabe, Abi and Jack, Yuri and Anupama, and Colin and Hisham.
- Come up with an idea for an object you could implement in C++. Think of
the two objects we've met thus far:
Point
andTime
. Keep your object simple for this project. - Assuming your object is
MyObject
, create three files:MyObject.h
,MyObject.cpp
, andtest_myobject.cpp
. The first of these will hold your object definition and member function prototypes, and the second the member function definitions. -
In the third file, start out with this:
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #include <doctest.h> #include "MyObject.h" using namespace std; TEST_CASE("Test can create and render MyObject") { MyObject myobj(); CHECK(myobj.to_string() == "This is MyObject"); }
Fill in the header and source files so that this first test passes.
To help stimulate your thinking, here are the OO projects from last year.
I leave it open ended where you take it from here. Keeping the learning goals in mind, add more tests and then more features to your object.
This project is due by 11:59 pm on Saturday, December 7th so that I can have the day on Sunday to evaluate your work.