| | |
Changing from reference to address (pointer?)
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.
In case you were wondering, yes, I do hate you.
![]() |
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
Views: 1672 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C++
6 algorithm api array arrays assignment beginner binary c++ c++borland c/c++ calculator char class classes code compile compiler constructor conversion convert count delete dll dynamic encryption error file files filestream form forms fstream function functions game givemetehcodez graph graphics gui homework iamthwee input int integer lazy linker list loop math matrix member memory network newbie news number object objects opengl operator output parameter pointer pointers problem program programming project qt random read recursion recursive reference return search server sort spoonfeeding string strings struct student studio template templates text time tree variable vc++ vector video visual win32 window windows winsock wxwidgets






