CS 70

Stubs and Interface

  • LHS Cow speaking

    While there is no starter code this week (!), your code (and test) structure will be very similar to Homework 5's.

  • RHS Cow speaking

    If you can't remember how to do something, we suggest that you look at your submission from last week!

Create Placeholder Files

Without starter code, you will need to create and outline the class definitions yourself.

You will be submitting four code files for your homework this week:

  • treestringset.cpp
  • treestringset.hpp
  • treestringset-test.cpp
  • Makefile

You should create placeholder (empty) files for each of them now. (And maybe add them to your repo as a starting point.)

Define Class Interfaces

In treestringset.hpp, define the interface for the TreeStringSet and TreeStringSet::ConstIter, classes as well as your TreeStringSet::Node struct. Use the Specification to identify the names of the public member functions for each class, as well as the using statements that your ConstIter class will need to include. Note that you may end up adding more private member functions and private data members later on.

Structure of a Header File

You can look back at your code for Homework 5 for a reminder of how to structure a header file, but here are some reminders:

  • Don't forget the include guard!
  • To use various C++ types, you need their corresponding header files. For example,
    • To use std::string, you need to include <string>.
    • To use streams like std::ostream, you need to include <iostream>.
    • To use size_t, you need to include <cstddef>.

Create Stubs for Public Member Functions

For each of the public member functions of TreeStringSet and TreeStringSet::ConstIter, create a function stub in treestringset.cpp. Remember that a function stub will have the right signature (parameter and return types), and will initially throw an exception to say it isn't implemented yet. We will walk through implementing each of the member functions in later steps of this assignment.

For now, it's also a good idea to put the following lines at the top of your treestringset.cpp file, just after the includes, to ensure that your stubs compile without warnings:

#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-private-field"
// FIXME: Remove these lines when all the functions are implemented

Create the main() Function for Testing

Set up your treestringset-test.cpp file with the right includes and a main() function that is ready to call and summarize the tests you'll write in later steps. You may want to look back at the previous homework to see what's needed to use the TestingLogger library.

As a quick hint, the library is installed on the CS 70 server, so all you need to do to use it in your code is to put

#include <cs70/testinglogger.hpp>

in the right places.

Create a Makefile

Write your Makefile such that running make generates an executable called treestringset-test.

Because you're using the TestingLogger library code in your program, you'll need to make sure that the linking step(s) in your Makefile include the necessary invocations to include the library in your linked files. The key is to add

-ltestinglogger

in the appropriate places.

Compile Your Code

At this point, you should be able to compile your code using make, but you will probably get some compiler warnings related to your stub code (e.g., unused variable warnings), which you will be fixing later in the assignment.

You must fix any compiler errors before moving on to the next step.

To Complete This Part of the Assignment…

You'll know you're done with this part of the assignment when you've done all of the following:

(When logged in, completion status appears here.)