Thus, you can divide the box
and cylinder
class
definitions into two files: a header file and a source-code file:
// containers class definitions (h extension) // box class definition: class box { public: double height, width, length; // Prototypes: box ( ) box (double, double, double) double volume ( ) }; // cylinder class definition class cylinder { public: double radius, length; // Prototypes: cylinder ( ) cylinder (double, double) double volume ( ) }; // Containers source-code file (cxx extension) #include "containers.h" const double pi = 3.14159; box::box ( ) { } box::box (double h, double w, double l) { height = h; width = w; length = l; } double box::volume ( ) { return height * width * length; } cylinder::cylinder ( ) { } cylinder::cylinder (double r, double l) { radius = r; length = l; } double cylinder::volume ( ) { return pi * radius * radius * length; }
You can, of course, divide the railroad-car class definitions into header and function files as well.