CS 70

The Train Implementation File

In this part of the assignment, you'll write function stubs for the Train member functions. Again, our goal is to get a correct skeleton of what the implementation will eventually look like without worrying about the implementation details at the moment.

Implementation Steps

Create the Train Implementation File and Stub Out Functions

Create a file named train.cpp, and then create stubs for each of the functions you declared in train.hpp for the Train class. You'll follow basically the same process you did for car.cpp; namely,

  1. Include the necessary header files.
  2. Write stub functions for all Train:: functions.
  3. Implement the operator<< function for Train objects, calling your Train's printToStream function.

Try Compiling Your Skeleton Train Class!

  • Hedgehog speaking

    Skeleton train? That's spooky!

  • Pumpy speaking

    Oh, hush…

  • LHS Cow speaking

    Ooh, looks like our dialogue got a little bit of… Pumpkin spice.

Before you try compiling, add the following temporary code to the top of car.cpp:

// Disable warnings that happen because our stubs don't do anything yet.
#pragma GCC diagnostic ignored "-Wunused-private-field"  // FIXME: Remove soon.
#pragma GCC diagnostic ignored "-Wunused-parameter"      // FIXME: Remove soon.

Now you should be able to compile your Train class, even though it doesn’t do anything yet.

clang++ -Wall -std=c++17 -c train.cpp -o train.o

If your code is correct, you shouldn't get any errors or warnings. If you do have errors or warnings, fix them before moving on.

Because the Train class uses the Car class (by including the car.hpp header file), you might need to go back and fix code in your Car class header file before everything compiles nicely.

  • RHS Cow speaking

    After completing this step, everything you've written should still compile!

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.)