???????????????? ????????????????? ????????????????? About: -Learn to define and
ID: 3731176 • Letter: #
Question
????????????????
?????????????????
?????????????????
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: 5 judges, each awards a score between 0-10 to a performer. Scores, such as 8.25, are allowed. Performer will be judged in 3 catagories - dancing skill, performance, and interpretion of the music. Highest and lowest of the judge's socre will be dropped in each catoregory, then the average score for that catagory will be taken. 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:
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.
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:
Test Case #1 Output:
Test Case #2 Input:
Test Case #2 Output:
******C++ CODE *********
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.78Explanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
//function prototypes
void getJudgeData(double[],string);
double findLowest(double[]);
double findHighest(double[]);
bool checkScore(double);
double calcScore(double[]);
int main() {
cout<<fixed<<setprecision(2);
double judgeScoreDancing[5],judgeScorePerformance[5],judgeScoreMusic[5];
//Call getJudgeData to get 5 judgs' scores for catagory "Dancing Skill"
getJudgeData(judgeScoreDancing,"Dancing Skill");
cout<<" Drop the highest: "<<findHighest(judgeScoreDancing);
cout<<" Drop the lowest: "<<findLowest(judgeScoreDancing);
cout<<" Dancing Skills Score: ";
//Call calcScore on above 5 scores to get the average of "Dancing Skill"
cout<<calcScore(judgeScoreDancing);
//Call getJudgeData to get 5 judgs' scores for catagory "Performance"
getJudgeData(judgeScorePerformance,"Performance");
cout<<" Drop the highest: "<<findHighest(judgeScorePerformance);
cout<<" Drop the lowest: "<<findLowest(judgeScorePerformance);
cout<<" Performance Skills Score: ";
//Call calcScore on above 5 scores to get the average of "Performance"
cout<<calcScore(judgeScorePerformance);
//Call getJudgeData to get 5 judgs' scores for catagory "Music Interpretion"
getJudgeData(judgeScoreMusic,"Music Interpretation");
cout<<" Drop the highest: "<<findHighest(judgeScoreMusic);
cout<<" Drop the lowest: "<<findLowest(judgeScoreMusic);
cout<<" Music Interpretation Skills Score: ";
//Call calcScore on above 5 scores to get the average of "Music Interpretion"
cout<<calcScore(judgeScoreMusic);
//Compute the total score, then ouput.
cout<<" Final score = "<<(calcScore(judgeScoreDancing)+calcScore(judgeScorePerformance)+calcScore(judgeScoreMusic));
return 0;
}
void getJudgeData(double judgeScore[5],string category)
{
int i;
double score;
cout<<" Enter five judge scores for "<<category<<" : ";
for(i=0;i<5;i++)
{
cin>>score;
if(checkScore(score))// validation
judgeScore[i] = score;
}
}
double findLowest(double judgeScore[5])
{
int i;
double lowest = 10.0;
for(i=0;i<5;i++)
{
if(judgeScore[i]<lowest)
lowest = judgeScore[i];
}
return lowest;
}
double findHighest(double judgeScore[5])
{
int i;
double highest = 0.0;
for(i=0;i<5;i++)
{
if(judgeScore[i]> highest)
highest = judgeScore[i];
}
return highest;
}
bool checkScore(double score)
{
if(score >= 0.0 && score <= 10.0)
return true;
else
return false;
}
double calcScore(double judgeScore[5])
{
int i;
double sum = 0;
double highest = findHighest(judgeScore);
double lowest = findLowest(judgeScore);
for(i=0;i<5;i++)
{
if(judgeScore[i] != highest && judgeScore[i] != lowest)
sum = sum + judgeScore[i];
}
return sum/3;
}
Output:
Enter five judge scores for Dancing Skill :
Drop the highest: 9.15
Drop the lowest: 7.00
Dancing Skills Score: 7.67
Enter five judge scores for Performance :
Drop the highest: 9.00
Drop the lowest: 7.25
Performance Skills Score: 8.36
Enter five judge scores for Music Interpretation :
Drop the highest: 9.36
Drop the lowest: 7.98
Music Interpretation Skills Score: 8.75
Final score = 24.78
Do ask if any query. Please upvote if the answer is helpful
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.