Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include using namespace std; // Constants for validating scores const double MIN_SCORE = 0.0; const double MAX_SCORE = 10.0; // Constants to be used
#include
#include
using namespace std;
// Constants for validating scores
const double MIN_SCORE = 0.0;
const double MAX_SCORE = 10.0;
// Constants to be used for output formatting
// The width of the ID column
const int COL1 = 4;
// The width of each of the score columns
const int COLS = 8;
// The TestScores data structure
struct TestScores {
int cid;
double score1;
double score2;
double score3;
double score4;
};
// Functions related to the TestScores data structure
bool readTestScores(TestScores *ptr);
int getID(const TestScores *ptr);
double getAverageScore(const TestScores *ptr);
bool isValidScore(double);
int compareContestants(const TestScores &, const TestScores &);
void printHeading();
void printScores(const TestScores *ptr);
//*****************************************************************************
//* Given a pointer to a TestScores data structure,
//* return the contestant's id contained in the data structure.
//*
//* Parameters
//* ptr - pointer to a TestScores struct
//*
//* Returns
//* The contestant's id.
//*****************************************************************************
int getID(const TestScores *ptr) {
return ptr->cid;
}
//*****************************************************************************
//* The function named readTestScores receives a pointer parameter that points
//* to a TestScores data structure to be filled with a contestant's data.
//*
//* It reads the contestant's ID and 4 double numbers from the keyboard and
//* stores the ID in the contestant's id field and the scores in the
//* 4 fields for scores.
//*
//* This function expects an integer and four double numbers from the keyboard.
//* The implementation can use the extraction operator (>>) of cin to get
//* the input from the keyboard.
//*
//* If the read is successful and the ID is > 0 and all scores are valid,
//* the function returns true.
//* Otherwise it returns false and the TestScores data structure is unchanged.
//*
//* Parameters
//* ptr - pointer to a TestScores struct
//*
//* Returns
//* true if successful or false otherwise.
//*****************************************************************************
bool readTestScores(TestScores *ptr) {
bool isValid = false;
// Read the description of the function above carefully and write your code
// with comments . . .
return isValid;
}
//*****************************************************************************
//* Get the average score of the contestant.
//*
//* Parameters
//* ptr - pointer to a TestScores struct
//*
//* Returns
//* The average score.
//*****************************************************************************
double getAverageScore(const TestScores *ptr) {
double average = 0.0;
// Write your code with comments . . .
return average;
}
//*****************************************************************************
//* Verify the given test score is in the valid range between
//* 0.0 and 10.0.
//*
//* Parameters
//*
//* score - The given test score.
//*
//* Returns
//* true if the test score is valid or false otherwise.
//*****************************************************************************
bool isValidScore(double score) {
bool isValid = true;
// Write your code with comments . . .
return isValid;
}
//*****************************************************************************
//* Compare two contestant's scores and determine the winner. The winner is
//* the contestant whose average score is higher. If the average scores are
//* equal, return 0.
//*
//* Parameters
//*
//* c1 - The first contestant's scores.
//* c2 - The second contestant's scores.
//*
//* Returns
//* The contestant's id who is the winner among the two contestants
//* or 0.
//*****************************************************************************
int compareContestants(const TestScores &c1, const TestScores &c2) {
int winner = 0;
// Write your code with comments . . .
return winner;
}
//*****************************************************************************
//* Print the report heading.
//*
//* Parameters
//*
//* Returns
//* void
//*****************************************************************************
void printHeading() {
// Write your commented code here . . .
}
//*****************************************************************************
//* Print the contestant's ID and test sccores.
//*
//* Parameters
//* ptr - pointer to a TestScores struct
//*
//* Returns
//* void
//*****************************************************************************
void printScores(const TestScores *ptr) {
// Write your commented code here . . .
}
int main() {
// Write your code with comments . . .
return 0;
}
/*
Test with the inputs as follows.
11 10.0 9.3 9.6 9.3
20 9.4 9.5 9.9 9.0
*/
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started