
Pass by reference
Ok, I am really stuck, and need major help. Ths assignment i am working on is as follows:
Its american idol. Design a function getJudgeData that asks the user for a judge's score, stores it in a reference parameter variable, and validates it. This function should be called by your function main() once for each of the 5 judges.
I have my class built i am just working on the main.cpp file...
I would REALLY appiciated ANY help. I am having trouble passing it by reference by using the Class Stat. I cant get the getJudgeData to put the data and store it into the class. Does anybody have ANY suggestions PLEASE? I can post the class if you need to see it I want to take the s.getNum(); and store the scores into there.
Code:
#include <iostream>
#include "Stat.h"
using namespace std;
void getJudgeData(int &);
double calcScore();
int main()
{
int score1 = 0, score2 = 0, score3=0, score4=0, score5=0;
Stat s;
cout << "This program assignment number 4 was created by Jeremy Rice" << endl;
cout<< "The Next American Idol!!!"<<endl;
cout<< "Please enter your scores below!"<<endl;
cout<<"Judge #1 what is your score"<<endl;
getJudgeData(score1);
cout<<"Judge #2 what is your score"<<endl;
getJudgeData(score2);
cout<<"Judge #3 what is your score"<<endl;
getJudgeData(score3);
cout<<"Judge #4 what is your score"<<endl;
getJudgeData(score4);
cout<<"Judge #5 what is your score"<<endl;
getJudgeData(score5);
system("pause");
return 0;
}
void getJudgeData(int &score)
{
Stat s;
s.getNum("");
}
// The average is the min and max subtracted
// the remaining three numbers are calculated for average
/*double calcScore()
{
Stat s;
int average = 0;
average(s.getSum  s.getMin  s.getMax)/3;
}
*/

Sorry, but I don't understand the problem. You're having trouble passing by reference? Looks relatively fine so far to me.

What does Stat look like (show us the stat.h header file)? What is its purpose?
Code:
void getJudgeData(int &score)
{
Stat s;
s.getNum("");
}
// The average is the min and max subtracted
// the remaining three numbers are calculated for average
/*double calcScore()
{
Stat s;
int average = 0;
average(s.getSum  s.getMin  s.getMax)/3;
}
*/
Those are locals, they get destroyed once the functions they are used in are finished. If your Stat class needs to get passed around to the getJudgeData function they will need to be declared in a broader scope, such as main... and depending on what you are trying to do, you may need one of them, or one for each judge's score. That's also not the way to set the average variable. Finally, those functions do not either return a value or do anything with the passed in reference.

Yeah the double calc function i am not working on atthe moment, mainly on the getJudgeData heres the stat.h file.
What i want to do is use the stat class to keep track of the 5 judges scores. I cant modify my stat class any further, he has a copy now and said if its modified i get a 0... lol gay.
Code:
// FILENAME: Stat.h
//
// CLASS PROVIDED: Stat
#ifndef STAT_H
#define STAT_H
#include <string>
using namespace std;
class Stat {
// ATTRIBUTES /////////////////////////////////////////////////////////
private:
int thenum; // last integer entered
unsigned count; // number of integers entered so far
int sum; // sum of all integers entered so far
long prod; // product of all integers entered so far
int min; // minimum of all integers entered so far
int max; // maximum of all integers entered so far
unsigned evens; // count of evens of all integers entered so far
unsigned odds; // count of odds of all integers entered so far
// OPERATIONS /////////////////////////////////////////////////////////
public:
Stat( );
//  default constructor
void setNum ( int newNum );
//  sets the last integer entered to newNum
void getNum ( string prompt );
//  displays prompt and reads in another integer
void reset ( );
//  resets all statistical values
int getNum ( );
//  returns the last integer entered
unsigned getCount ( );
//  returns the number of integers entered so far
int getSum ( );
//  returns the sum of all integers entered so far
long getProd ( );
//  returns the product of all integers entered so far
int getMin ( );
//  returns the minimum of all integers entered so far
int getMax ( );
//  returns the maximum of all integers entered so far
float getAverage ( );
//  returns the average of all integers entered so far
unsigned getEvens ( );
//  returns the number of even integers entered so far
unsigned getOdds ( );
//  returns the number of odd integers entered so far
};
#endif

these are the requirements of the getJudgeData function:
Design and implement a function void getJudgeData() that asks the user for a judge's score, stores it in a reference parameter variable, and validates it. This function should be called by your function main() once for each of the 5 judges.
Use the Stat class to keep track of the five judges' scores. Do NOT modify the Stat class  you should be able to use it as is!