seperating interface and implemention with normal functions
- by ace
this seems like it should be pretty simple, im probably leaving something simple out.
this is the code im trying to run. it is 3 files, 2*cpp and 1*header.
-------------lab6.h
ifndef LAB6_H_INCLUDED
define LAB6_H_INCLUDED
int const arraySize = 10;
int array1[arraySize];
int array2[arraySize];
void generateArray(int[], int );
void displayArray(int[], int[], int );
void reverseOrder(int [],int [], int);
endif // LAB6_H_INCLUDED
-----------------lab6.cpp
include
using std::cout;
using std::endl;
include
using std::rand;
using std::srand;
include
using std::time;
include
using std::setw;
include "lab6.h"
void generateArray(int array1[], int arraySize)
{
srand(time(0));
for (int i=0; i<10; i++)
{
array1[i]=(rand()%10);
}
}
void displayArray(int array1[], int array2[], int arraySize)
{
cout<<endl<<"Array 1"<<endl;
for (int i=0; i<arraySize; i++)
{
cout<<array1[i]<<", ";
}
cout<<endl<<"Array 2"<<endl;
for (int i=0; i<arraySize; i++)
{
cout<<array2[i]<<", ";
}
}
void reverseOrder(int array1[],int array2[], int arraySize)
{
for (int i=0, j=arraySize-1; i<arraySize;j--, i++)
{
array2[j] = array1[i];
}
}
------------and finally main.cpp
include "lab6.h"
int main()
{
generateArray(array1, arraySize);
reverseOrder(array1, array2, arraySize);
displayArray(array1, array2, arraySize);
return 0;
}