Question

***C++ Code*** What this Assignment Is About: -Learn to define and call void & non-void functions...

***C++ Code***

What this Assignment Is About:

-Learn to define and call void & non-void functions

-Learn to use reference variables

Coding Guidelines for All Labs/Assignments (You will be graded on this)

-Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc).

-Keep identifiers to a reasonably short length.

-Use upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects).

-Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent.

-Use white space to make your program more readable.

-Use comments properly before or after the ending brace of classes, methods, and blocks to identify to which block it belongs.

1. Introduction

Dance Competiton has 5 judges, each of whom awards a score between 0 and 10 to a performer. Fractional scores, such as 8.25, are allowed. A performer will be judged in 3 catagories - dancing skill, performance and interpretion of the music. For each catagory, the highest and lowest of the judge's socre will be dropped, then the average of the remaining 3 scores will be the performer's score for that catagory. The sum of a performer's score in dancing skill, performance and music interpretion will be his/her final score in the competition. See below table for one example:

Program Components Judge 1 Judge 2 Judge 3 Judge 4 Judge 5 Lowest Highest Average
Dancing Skills 7.75 8.00 7.25 9.15 7.00 7.00 9.15 7.67
Performance 7.87 8.25 8.97 9.00 7.25 7.25 9.00 8.36
Interpretion of the music 7.98 8.25 8.75 9.25 9.36 7.98 9.36 8.75
Final Score 24.78

2. Functions

In this assignment, you're required to write a program that uses these rules to calculate and display a contestant's score. Your program MUST at least include the following functions, feel free to add any extra functions if necessary.

Function Name Description
main This is the main() function which we will start the program with, pseudo code for the main:

Call getJudgeData to get 5 judgs' scores for catagory "Dancing Skill"
Call calcScore on above 5 scores to get the average of "Dancing Skill"
Call getJudgeData to get 5 judgs' scores for catagory "Performance"
Call calcScore on above 5 scores to get the average of "Performance"
Call getJudgeData to get 5 judgs' scores for catagory "Music Interpretion"
Call calcScore on above 5 scores to get the average of "Music Interpretion"
Compute the total score, then ouput.
getJudgeData This function should allow the user to enter 5 judges' scores and store them in five reference variables. This function should also call checkScore function on each of the five scores to make sure they are all within the range 0 to 10. In case any of the five scores are out of range, show the following message on screen and ask the user to re-enter.

One or more of the judge scores are invalid.
Score must between 0 to 10.
Please re-enter scores:
findLowest This function should find and return the lowest of the 5 scores passed to it.
findHighest This function should find and return the highest of the 5 scores passed to it.
checkScore This function takes one score as an input parameter and returns true if it's valid (within the range of [0, 10]), otherwise it should return false.

calcScore
This function should take 5 scores as input parameters, calculate and return the average of the 3 scores that remain after dropping the highest and lowest scores the performer received. i.e. this function should call findLowest, findHighest functions.

Note:

-Except for main(), for all above functions, you need to decide its header first, this includes the return data tye and formal parameter list. For formal parameter list, you will need to decide the number, data type of each parameter, etc.

-Don't forget to declare the functions first.

-For function getJudgeData and use of reference variable, check the e-Textbook we posted on Blackboard pp.348 Section 6.13 "Using Reference Variables as Parameters", or study this reference variable sample code.

-All output scores should be formatted with 2 decimal digits.

3. Sample run

User input is in bold.

Sample run #1

Enter five judge scores for Dancing Skills: 7.75 8.00 7.25 9.15 7.00

Drop the highest:        9.15
Drop the lowest:         7.00
Dancing Skills Score:    7.67

Enter five judge scores for Performance: 7.87 8.25 8.97 9.00 7.25

Drop the highest:        9.00
Drop the lowest:         7.25
Performance Score:       8.36

Enter five judge scores for Music: 7.98 8.25 8.75 9.25 9.36

Drop the highest:        9.36
Drop the lowest:         7.98
Music Score:             8.75

Final score = 24.78

Sample run #2

Enter five judge scores for Dancing Skills: 5.6 7.82 7.15 8.17 6.75

Drop the highest:       8.17
Drop the lowest:        5.60
Dancing Skills Score:   7.24

Enter five judge scores for Performance: 6.75 11.2 8.25 9.35 4.25

One or more of the judge scores are invalid.
Score must between 0 to 10.

Please re-enter scores: 6.75 9.20 8.25 9.35 4.25

Drop the highest:       9.35
Drop the lowest:        4.25
Performance Score:      8.07

Enter five judge scores for Music: 7.25 -1.20 7.52 7.67 6.98

One or more of the judge scores are invalid.
Score must between 0 to 10.

Please re-enter scores: 7.25 7.20 7.52 7.67 6.98

Drop the highest:       7.67
Drop the lowest:        6.98
Music Score:            7.32

Final score = 22.63

4. Misce. Programming Requirements

-Your program must also meet the specifications stated as below:

-See the sample output file at the end of the specification.

-Pick and use identifiers which are self-descriptive. One-letter variable names should not be used. As an example, if you were referring to the ticket price, the variable needed might be declared as double price; instead of double x;

Test Case #1 Input:

5.75 8.25 7.75 8.50 9.10
6.75 7.15 7.87 8.29 9.20
7.20 7.88 8.50 8.95 8.75

Test Case #1 Output:

Enter five judge scores for Dancing Skills: 

Drop the highest:       9.10
Drop the lowest:        5.75
Dancing Skills Score:   8.17

Enter five judge scores for Performance: 

Drop the highest:       9.20
Drop the lowest:        6.75
Performance Score:      7.77

Enter five judge scores for Music: 

Drop the highest:       8.95
Drop the lowest:        7.20
Music Score:            8.38

Final score = 24.31

Test Case #2 Input:

5.6 7.82 7.15 8.17 6.75
6.75 11.2 8.25 9.35 4.25
6.75 9.20 8.25 9.35 4.25
7.25 -1.20 7.52 7.67 6.98
7.25 7.20 7.52 7.67 6.98

Test Case #2 Output:

Enter five judge scores for Dancing Skills:
 
Drop the highest:       8.17
Drop the lowest:        5.60
Dancing Skills Score:   7.24

Enter five judge scores for Performance: 

One or more of the judge scores are invalid.
Score must between 0 to 10.

Please re-enter scores: 

Drop the highest:       9.35
Drop the lowest:        4.25
Performance Score:      8.07

Enter five judge scores for Music: 

One or more of the judge scores are invalid.
Score must between 0 to 10.

Please re-enter scores: 

Drop the highest:       7.67
Drop the lowest:        6.98
Music Score:            7.32

Final score = 22.63

***C++ Code***

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

#include <iostream>

using namespace std;

void getJudgeData(float &a, float &b, float &c, float &d, float &e);
float findLowest(float a, float b, float c, float d, float e);
float findHighest(float a, float b, float c, float d, float e);
float calcScore(float a, float b, float c, float d, float e);
bool checkScore(float a, float b, float c, float d, float e);

int main()
{
  
float judgeOne;
float judgeTwo;
float judgeThree;
float judgeFour;
float judgeFive;
  
cout<<"Enter five judges score for Dancing skills: ";
getJudgeData(judgeOne,judgeTwo,judgeThree,judgeFour,judgeFive);
float dancingAvg = calcScore(judgeOne,judgeTwo,judgeThree,judgeFour,judgeFive);
cout<<endl<<"Dancing skill score: "<<dancingAvg;
  
cout<<endl<<endl<<endl<<"Enter five judges score for Performance: ";
getJudgeData(judgeOne,judgeTwo,judgeThree,judgeFour,judgeFive);
float performanceAvg = calcScore(judgeOne,judgeTwo,judgeThree,judgeFour,judgeFive);
cout<<endl<<"Performance score: "<<performanceAvg;
  
  
cout<<endl<<endl<<endl<<"Enter five judges score for Music: ";
getJudgeData(judgeOne,judgeTwo,judgeThree,judgeFour,judgeFive);
float musicAvg = calcScore(judgeOne,judgeTwo,judgeThree,judgeFour,judgeFive);
cout<<endl<<"Music score: "<<musicAvg;
  
float finalScore = dancingAvg+performanceAvg+musicAvg;
cout<<endl<<endl<<"Final score is: "<<finalScore;

return 0;
}

bool checkScore(float a, float b, float c,float d, float e)
{
bool flag = false;
if(a>10 || a<0 || b<0 || b>10 || c>10 || c<0 || d<0 || d>10 || e<0 || e>10)
{
flag = true;
}
return flag;
}

void getJudgeData(float &a, float &b, float &c, float &d, float &e)
{
cin>>a>>b>>c>>d>>e;
while(checkScore(a,b,c,d,e))
{
cout<<"One or more of the judge score are invalid"<<endl;
cout<<"Score must between 0 to 10"<<endl;
cout<<"Please re-enter scores: ";
cin>>a>>b>>c>>d>>e;
}
  
}
float findLowest(float a, float b, float c, float d, float e)
{
float lowestArray[5] = {a,b,c,d,e};
float lowest = lowestArray[0];

for(int i=1;i<5;i++)
{
if(lowestArray[i]<lowest)
{
lowest = lowestArray[i];
}
}
  
return lowest;
}

float findHighest(float a, float b, float c, float d, float e)
{
float highestArray[5] = {a,b,c,d,e};
float highest = highestArray[0];

for(int i=1;i<5;i++)
{
if(highestArray[i]>highest)
{
highest = highestArray[i];
}
}
  
return highest;
}

float calcScore(float a, float b, float c, float d, float e)
{
float lowest = findLowest(a,b,c,d,e);
float highest = findHighest(a,b,c,d,e);
cout<<endl<<endl<<"Drop the highest: "<<highest;
cout<<endl<<"Drop the lowest: "<<lowest;
float sum = a+b+c+d+e-lowest-highest;
float average = (float)sum/3;
  
return average;
}
  

Output:

a) With valid inputs

Enter five judges score for Dancing skills: 7.75 8.00 7.25 9.15 7.00 Drop the highest: 9.15 Drop the lowest: 7 Dancing skill

b) With invaid inputs and then valid input

Enter five judges score for Dancing skills: 5.6 7.82 7.15 8.17 6.75 Drop the highest: 8.17 Drop the lowest: 5.6 Dancing akillEnter five judges score for Music: 7.25 -1.20 7.52 7-67 6.98 One or more of the judge score are invalid Score must between 0

Add a comment
Know the answer?
Add Answer to:
***C++ Code*** What this Assignment Is About: -Learn to define and call void & non-void functions...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please Write in C++ (10-30) @ 11:55pm 1.9 HW7 This homework assignment gives you the opportunity...

    Please Write in C++ (10-30) @ 11:55pm 1.9 HW7 This homework assignment gives you the opportunity to practice functions, functions that call other functions, reference variables, logical statements (what is meant by logical statement is a statement such as if, if/else if, switch), and input validation, HW7 (Graded out of 100) A talent competition has 5 judges, each of whom awards a score between 0 and 10 for each performer. Fractional scores, such as 8.3, are allowed. A performer's final...

  • Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that...

    Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...

  • Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate...

    Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate the number of test scores the user enters; have scores fall into a normal distribution for grades -Display all of the generated scores - no more than 10 per line -Calculate and display the average of all scores -Find and display the number of scores above the overall average (previous output) -Find and display the letter grade that corresponds to the average above (overall...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT