Okay folks. I am writing a c++ program that will take a text file filled with test scores. Test1, Test2 and FinalTest. There are 32 test scores to be processed. I finished this first assignment using pass by reference using things such as:

Prototype:

void doStatsRef(int [], int, double&, double&, int&, int&, double&);

Function Call:

doStatsRef(exam1Array, count, meanVal, medianVal, highVal, lowVal, stdDev);

Function:

void doStatsRef(int examArray[], int size, double& mean, double &median, 
                int& high, int &low, double& stdDev)
{

int copyArray[MAX_SIZE],
    i;

// copies exam array from main into local exam array
for (i = 0; i < size; i++)
   copyArray[i] = examArray[i];
   
// Sorts the new local array
sortArray(copyArray, size);

//Finds the median and mean of array
meanAndMedianRef(copyArray, size, mean, median);

//Finds the high and low test scores
hiAndLowRef(copyArray, size, high, low);

// Calculates the standard deviation
stdDevRef(copyArray, size, stdDev);
}

My problem comes when i have now being asked to do the following:

doStatsRef(), meanAndMedianRef(), hiAndLoRef(), stdDevRef() will be rewritten.

Write four equivalent functions that pass back all results by address. Name each of the functions with Addr in place of Ref. The function doStatsAddr() should call the ..Addr.. versions of the sub-functions.

To get this... i am working on just a section of my complete first assignment , which if i get working, i will implement throughout the rest of my code. Here is how i have done it (edited code from above - in new program/assignment)

Prototype:

void doStatsAddr(int [], int, double *, double *, int *, int *, double *);

Function Call:

doStatsAddr(exam1Array, count, &meanVal, &medianVal, &highVal, &lowVal, &stdDev);

Function:

void doStatsAddr(int examArray[], int size, double *mean, double *median, 
                int *high, int *low, double *stdDev)
{

int copyArray[MAX_SIZE],
    i;

// copies exam array from main into local exam array
for (i = 0; i < size; i++)
   copyArray[i] = examArray[i];
   
// Sorts the new local array
sortArray(copyArray, size);

//Finds the median and mean of array
meanAndMedianAddr(copyArray, size, &mean, &median);

/**
//Finds the high and low test scores
hiAndLowAddr(copyArray, size, high, low);

// Calculates the standard deviation
stdDevAddr(copyArray, size, stdDev);
**/
}

**Note the commented out parts, as you can see im only trying to work with one section/function of the program, get that working, then i can redo the others.

If you can see anything obviously wrong here, please help! If you need to see my entire code/program please let me know and I can PM it to you or post it here, although it would break rules because it is over 250 lines long.

Thanks in advance - i hope you can help.

Please understand i am new to C++ (obviously!) and i have already been told im an idiot by other people on other forums!

>i have already been told im an idiot by other people on other forums!
That wasn't very nice of them.

>If you can see anything obviously wrong here, please help!
I see something suspicious, though it may or may not be wrong.

>meanAndMedianAddr(copyArray, size, &mean, &median);
mean and median are already pointers, so you probably shouldn't be passing their addresses.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.