| | |
Changing from reference to address (pointer?)
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Feb 2005
Posts: 154
Reputation:
Solved Threads: 0
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:
Function Call:
Function:
My problem comes when i have now being asked to do the following:
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:
Function Call:
Function:
**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!
Prototype:
C++ Syntax (Toggle Plain Text)
void doStatsRef(int [], int, double&, double&, int&, int&, double&);
Function Call:
C++ Syntax (Toggle Plain Text)
doStatsRef(exam1Array, count, meanVal, medianVal, highVal, lowVal, stdDev);
Function:
C++ Syntax (Toggle Plain Text)
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.
Prototype:
C++ Syntax (Toggle Plain Text)
void doStatsAddr(int [], int, double *, double *, int *, int *, double *);
Function Call:
C++ Syntax (Toggle Plain Text)
doStatsAddr(exam1Array, count, &meanVal, &medianVal, &highVal, &lowVal, &stdDev);
Function:
C++ Syntax (Toggle Plain Text)
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.
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.
![]() |
Similar Threads
- Passing pointer address... Doubt!!!! (C)
- pointer to a refernce (C++)
- changing mac address (Networking Hardware Configuration)
- Service Settings Keep Reverting to wrong IP Address (Windows NT / 2000 / XP)
- Pointers (Part II) (C)
- parameters (C++)
- pointer (C)
Other Threads in the C++ Forum
- Previous Thread: Array Length
- Next Thread: i am confused
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






