Need help with implementation , header and driver

Write a C++ console program in three parts. Header file, driver file and implementation file.

here is my code but i dont know what is implementation , header and driver .
//
#include <stdio.h>
#include <string.h>

void markMultiples(bool arr[], int a, int n)
{
int i = 2, num;
while ( (num = i*a) <= n )
{
arr[ num-1 ] = 1;
++i;
}
}

void Pnumbers(int n)
{
if (n >= 2)
{
bool arr[n];
memset(arr, 0, sizeof(arr));


arr[i] == 0 means i + 1 is prime
arr[i] == 1 means i + 1 is not prime */
for (int i=1; i<n; ++i)
{
if ( arr[i] == 0 )
{
printf("%d ", i+1);
markMultiples(arr, i+1, n);
}
}
}
}

int main()
{
int n = 30;
printf("Following are the prime numbers below %d\n", n);
Pnumbers(n);
return 0;
}
//
I don't know what is meant by "driver" in this context. The header is generally the "interface" and the source cpp file is generally the "implementation", however I have never heard the term "driver" used in the same context as these other terms. Perhaps you mean "client code"?
In this case I take "driver" to mean a test driver; a test driver app, a test driver function, etc. Normally just smart enough to set up the required parameters, call a function (or maybe a few) and report the return values. But could load some data from file, generate random test data, etc.

So you end up with your function Pnumbers plus its helper function markMultiples in the implementation file; the declaration of Pnumbers (but not markMultiples) in the header file; and main.cpp will just contain your test driver function (including input and output.)

In this case you will probably only need main() to drive your function. But the driver side of things could involve a set of functions which work together to call the function you're testing.

Andy
Last edited on
Topic archived. No new replies allowed.