Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,537 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,526 people online right now. Registration is fast and FREE... Join Now!




American Idol Program help

 
Reply to this topicStart new topic

American Idol Program help

jrice528
30 Oct, 2007 - 08:25 AM
Post #1

New D.I.C Head
*

Joined: 29 Sep, 2007
Posts: 31


My Contributions
I have been working on this for about a week and I am stuck. Its an american idol program, where 5 judges score contestants. I have the classes all figured out, my teacher said to not modify it any further to just work on my main.cpp

I am to make 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.
There are other issues with the main.cpp but i am mostly working on the function right now. I need help to pass it by reference. This is what I have. How would I pass the scores by reference? If needed I can also post the stat.h and stat.cpp files. Any help is REALLY appiciated cause I could use all the help i could get.

CODE
#include <iostream>
#include "Stat.h"

using namespace std;

void getJudgeData();
double calcScore();


int main()
{
    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;

// asking for the scores from each judge
//using the function getJudgeData


getJudgeData();



system("pause");
    return 0;
}

void getJudgeData()
{
     Stat s;
    s.getNum("Please enter your score Judge #1 ");
    s.getNum("Please enter your score Judge #2 ");
    s.getNum("Please enter your score Judge #3 ");
    s.getNum("Please enter your score Judge #4 ");
    s.getNum("Please enter your score Judge #5 ");

}

// 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;
}

User is offlineProfile CardPM
+Quote Post

Amadeus
RE: American Idol Program Help
30 Oct, 2007 - 08:40 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,349



Thanked: 51 times
Dream Kudos: 25
My Contributions
Assuming your variable to hold the score is called score, then
CODE

void getJudgeData(int &score);


http://www.cplusplus.com/doc/tutorial/functions2.html
User is offlineProfile CardPM
+Quote Post

jrice528
RE: American Idol Program Help
30 Oct, 2007 - 09:34 AM
Post #3

New D.I.C Head
*

Joined: 29 Sep, 2007
Posts: 31


My Contributions
Ok is this the correct way to pass it by refercen then?

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 &scoreRef)
{
     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;
}
*/

User is offlineProfile CardPM
+Quote Post

MikeRaines
RE: American Idol Program Help
30 Oct, 2007 - 10:38 AM
Post #4

D.I.C Head
**

Joined: 30 Oct, 2007
Posts: 76



Thanked: 1 times
My Contributions
Hi Jrice,

Amadeus is correct, your going to need to declare a score variable and reference that in your function

i.e
CODE

double score=0;

void getJudgeScore(int &score)
{
    double x;
    //inputs and calculations
    score = x;
    return
}


When passing by reference, any changes that occure to the score value happen on a global aspect. Thus changing the value of score in your main, without returning any values.

This is useful when a function needs to change many values at one time, since return can be limited in that aspect.

Hope This was helpful.
User is offlineProfile CardPM
+Quote Post

jrice528
RE: American Idol Program Help
30 Oct, 2007 - 04:21 PM
Post #5

New D.I.C Head
*

Joined: 29 Sep, 2007
Posts: 31


My Contributions
Ok I been working on this most of the day and i believe i got the getJudgeData to work. My last problem is to use a function double calcScore() and find the average. As you can see i got the getJudgeData number to work with my stat class, if i didnt have to use the calcScore function I wouldnt have aproblem, i just dont know how to put the scores into the calcScore() function to get the average.

CODE
#include <iostream>
#include "Stat.h"

using namespace std;

void getJudgeData(int &);
double calcScore();

int main()
{
    Stat s;
    int score1 = 0, score2 = 0, score3=0, score4=0, score5=0;
    

    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<< "Enter contestant #1's scores!"<<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);
s.setNum(score1);
s.setNum(score2);
s.setNum(score3);
s.setNum(score4);
s.setNum(score5);

cout<<"Talent score for contestant #1 is: "<<calcScore()<<endl;



system("pause");
    return 0;
}

void getJudgeData(int &getNum)
{
     Stat s;
    cin>> getNum;
     return;
}

// remove the highest and lowest scores
//calculate average from remaning three

double calcScore()
{
       Stat s;
       cout<<(s.getSum()- s.getMin()- s.getMax()) / 3<<endl;
}


the .cpp file is
CODE
#include <iostream> // for cin, cout
#include "Stat.h"

using namespace std;

Stat::Stat(  ){
    reset( );
}

void Stat::setNum ( int newNum ){
    thenum = newNum;
//  update data members
    if( count==0 ) // first integer entered
        min = max = thenum;
    count++;
    sum  = sum+thenum;
    prod = prod*thenum;
    if( thenum<min )
        min = thenum;
    if( thenum>max )
        max = thenum;
    if( thenum%2==0 )
        evens++;
    else
        odds++;
}

void Stat::getNum ( string prompt ){
    int someInt;
    cout << prompt;
    cin  >> someInt;
    setNum( someInt );
}

void Stat::reset (  ){
    count = 0;
    sum   = 0;
    prod  = 1;
    evens = 0;
    odds  = 0;
}

int Stat::getNum (  ){
    return thenum;
}

unsigned Stat::getCount (  ){
    return count;
}

int Stat::getSum (  ){
    return sum;
}

long Stat::getProd (  ){
    return prod;
}

int Stat::getMin (  ){
    return min;
}

int Stat::getMax (  ){
    return max;
}

float Stat::getAverage (  ){
    return (1.0 * sum) / count;
}

unsigned Stat::getEvens (  ){
    return evens;
}

unsigned Stat::getOdds (  ){
    return odds;
}

User is offlineProfile CardPM
+Quote Post

MikeRaines
RE: American Idol Program Help
30 Oct, 2007 - 04:51 PM
Post #6

D.I.C Head
**

Joined: 30 Oct, 2007
Posts: 76



Thanked: 1 times
My Contributions
I don't exactlly understand what your issue is.

Are you required to use that calcScore functoin as is? What exactlly are you still having issues with, you probobly explained it, but I don't quite understand.
User is offlineProfile CardPM
+Quote Post

jrice528
RE: American Idol Program Help
30 Oct, 2007 - 05:36 PM
Post #7

New D.I.C Head
*

Joined: 29 Sep, 2007
Posts: 31


My Contributions
Yeah,I am required to use the calcScore function.

I am having trouble of taking the calcScore function and calculating the average... I cant seem to implement the Stat class and use the variables in the calc function.

If i had
CODE
cout<<(s.getSum()- s.getMin()- s.getMax()) / 3<<endl;"


I would have no trouble ofgettin the average i just cant seem to put that into the calc function... here is the requirment of the calcscore function:

Design and implement a function double calcScore() that calculates and returns the average of the three scores that remain after dropping the highest and lowest scores a performer received. This function should be called once for each contestant by your function main(), and it should be passed the Stat object that contains the 5 scores from the judges.

User is offlineProfile CardPM
+Quote Post

MikeRaines
RE: American Idol Program Help
30 Oct, 2007 - 06:09 PM
Post #8

D.I.C Head
**

Joined: 30 Oct, 2007
Posts: 76



Thanked: 1 times
My Contributions
The first problem I notice is that you need to be declaring a Stat in your main.

Then you can pass your judge scores into your Stat class.

The assignment asks you to pass a Stat into your calc function ie.

CODE

double calcScore(Stat s)
{
       cout<<(s.getSum()- s.getMin()- s.getMax()) / 3<<endl;
}

//used as

int main()
{
.
.
     Stat s;
     s.addJudgeScore(score1);
     .
     .
     .
     s.addJudgeScore(score5);
     calcScore(s);
.
.
.
}


Your stat class needs to hold those scores in an array or some other format.
then your getMax and getMin's need to return the proper values, along with the getSum.

From what I can see your function wasn't working because by declaring Stat s; inside your function you create a new empty class with no score values existing.

Hope This is Helpful

This post has been edited by MikeRaines: 30 Oct, 2007 - 06:10 PM
User is offlineProfile CardPM
+Quote Post

jrice528
RE: American Idol Program Help
30 Oct, 2007 - 06:34 PM
Post #9

New D.I.C Head
*

Joined: 29 Sep, 2007
Posts: 31


My Contributions
Oh wow thank you so much! I been workin on it all day and it was somethin small, thank you!!!!
User is offlineProfile CardPM
+Quote Post

jrice528
RE: American Idol Program Help
30 Oct, 2007 - 06:56 PM
Post #10

New D.I.C Head
*

Joined: 29 Sep, 2007
Posts: 31


My Contributions
Ok i do have one question, this is the code now, i was wondering how i would loop that? from the 'is there another contestant (y/n) how would i loop that until ididnt want to enter anymore contestants? You guys have helped me out a ton already and i am really thankful wouldnt of got this far without yourg help.

CODE
#include "Stat.h"
#include <iostream>
using namespace std;

void getJudgeData(int &);
double calcScore(Stat s);

int main()
{
    Stat s;
    
    int score1 = 0, score2 = 0, score3=0, score4=0, score5=0;
    int x = 1;
    int winner;


    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<< "Enter contestant #"<<x<< " scores!"<<endl;
  cout<<"Judge #1 what is your score: ";
               getJudgeData(score1);
               s.setNum(score1);
  cout<<"Judge #2 what is your score: ";
               getJudgeData(score2);
               s.setNum(score2);
  cout<<"Judge #3 what is your score: ";
               getJudgeData(score3);
               s.setNum(score3);
  cout<<"Judge #4 what is your score: ";
               getJudgeData(score4);
               s.setNum(score4);
  cout<<"Judge #5 what is your score: ";
               getJudgeData(score5);
               s.setNum(score5);
  
  cout<<"Talent score for contestant #"<<x<<" is: ";
                calcScore(s);
                x++;
  cout<<"Is there another contestant? (Y/N)"<<endl;
  
  
    system("pause");
    return 0;
}



void getJudgeData(int &getNum)
{
     Stat s;
    cin>> getNum;
     return;
}

double calcScore(Stat s)
{
        
cout<<(s.getSum()- s.getMin()- s.getMax()) / 3 <<endl;
      
}


User is offlineProfile CardPM
+Quote Post

MikeRaines
RE: American Idol Program Help
30 Oct, 2007 - 07:59 PM
Post #11

D.I.C Head
**

Joined: 30 Oct, 2007
Posts: 76



Thanked: 1 times
My Contributions
Glad I could help,

The way I would go about doing, what I think you're asking, is just a simple while loop.

i.e
CODE

int main()
{
   bool loop=true;
   while(loop)
   {
      Stat s;
      .
      .
      .
      .
      .
      .
      //end of current main
      char x;
      cout<<"Another contestent? y/n: ";
      cin>>x;
      if(x=='y')
      {
            loop=false;
       }
    }
    return 0;    
}


That will repeat your main untill a 'y' is entered in the final cin, but remember due to the ascii values 'y' and 'Y' are not the same thing. If you want it to exit on both you will have to take that into consideration.


Hope This is Helpful
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 09:12PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month