Changing from reference to address (pointer?)

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Feb 2005
Posts: 154
Reputation: tones1986 is an unknown quantity at this point 
Solved Threads: 0
tones1986 tones1986 is offline Offline
Junior Poster

Changing from reference to address (pointer?)

 
0
  #1
Nov 6th, 2007
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:
  1. void doStatsRef(int [], int, double&, double&, int&, int&, double&);

Function Call:
  1. doStatsRef(exam1Array, count, meanVal, medianVal, highVal, lowVal, stdDev);

Function:
  1. void doStatsRef(int examArray[], int size, double& mean, double &median,
  2. int& high, int &low, double& stdDev)
  3. {
  4.  
  5. int copyArray[MAX_SIZE],
  6. i;
  7.  
  8. // copies exam array from main into local exam array
  9. for (i = 0; i < size; i++)
  10. copyArray[i] = examArray[i];
  11.  
  12. // Sorts the new local array
  13. sortArray(copyArray, size);
  14.  
  15. //Finds the median and mean of array
  16. meanAndMedianRef(copyArray, size, mean, median);
  17.  
  18. //Finds the high and low test scores
  19. hiAndLowRef(copyArray, size, high, low);
  20.  
  21. // Calculates the standard deviation
  22. stdDevRef(copyArray, size, stdDev);
  23. }

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:
  1. void doStatsAddr(int [], int, double *, double *, int *, int *, double *);

Function Call:
  1. doStatsAddr(exam1Array, count, &meanVal, &medianVal, &highVal, &lowVal, &stdDev);

Function:
  1. void doStatsAddr(int examArray[], int size, double *mean, double *median,
  2. int *high, int *low, double *stdDev)
  3. {
  4.  
  5. int copyArray[MAX_SIZE],
  6. i;
  7.  
  8. // copies exam array from main into local exam array
  9. for (i = 0; i < size; i++)
  10. copyArray[i] = examArray[i];
  11.  
  12. // Sorts the new local array
  13. sortArray(copyArray, size);
  14.  
  15. //Finds the median and mean of array
  16. meanAndMedianAddr(copyArray, size, &mean, &median);
  17.  
  18. /**
  19. //Finds the high and low test scores
  20. hiAndLowAddr(copyArray, size, high, low);
  21.  
  22. // Calculates the standard deviation
  23. stdDevAddr(copyArray, size, stdDev);
  24. **/
  25. }

**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!
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 717
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Changing from reference to address (pointer?)

 
0
  #2
Nov 6th, 2007
>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.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC