Programming and Graphics

(Kiana) #1

6.13 Header files and projects 183


6.12.2. Endow the runners with an additional integer field expressing their
birth year.


6.12.3. Modify the code “runner” to count the number of countries entered.


6.13 Header files and projects.......................


We want to place the user-defined functions, class declarations, and class mem-
ber functions in separate source files that can be compiled individually and then
linked to form the executable.


Let us assume that a main function uses the “runner” class. In this case,
we generate the following three source files.


File “runnerfast.cc” contains the main function:

#include<iostream>
#include<string>
#include "clrunner.h"
using namespace std;

int main()
{
...
return 0;
}

where the three dots denote additional lines of code.


The header file “clrunner.h” contains the class definition:

#ifndef CLRUNNERH
#define CLRUNNERH

#include<iostream>
#include<string>
using namespace std;

class runner
{
public:
...
private:
...
};

#endif
Free download pdf