Question: *****Please solve in C++ please, and use the code format below. The program reads data about two contestants from the keyboard and displays the scores
*****Please solve in C++ please, and use the code format below.
The program reads data about two contestants from the keyboard and displays the scores and the winner of the two contestants. The program uses a data structure called TestScores for storing the scores of a contestant and a set of functions related to the data structure for processing the scores of contestants. The data structure, TestScores, contains an int variable for the contestant's ID and 4 double fields for the scores given to the contestant. Each ID must be a positive integer. Each score must fall in the range from 0.0 to 10.0 inclusive.
Your job is to complete the program according to the following description and the description of each function in the source file.
First, complete everything that is required of you at the top of the file. Then complete the code for all the related functions and the main function.
Below are description of the related functions.
The function named readTestScores receives a pointer parameter that points to a TestScores data structure to be filled with a contestant's data. The function reads the contestant's ID and 4 double numbers from the keyboard and stores the ID in the id field and the scores in the 4 fields for scores. If the read is successful and all values are valid, the function returns true. Otherwise it returns false.
The function named getID receives a pointer parameter that points to a TestScores data structure that represents a contestant's data. It returns the ID of the contestant.
The function named getAverageScore receives a pointer parameter that points to a TestScores data structure that represents a contestant's data. It returns the average of the contestants scores.
The function named printHeading. It prints the heading of the report according the the format shown at the bottom. You must use the formatting constants defined in the source file to format the heading.
The function named printScores receives a pointer parameter that points to a TestScores data structure that represents a contestant's data. It displays the ID, the scores of the contestant and the average according to the format shown at the bottom. You must use the formatting constants defined in the source file to format the ID and the other values.
The function named isValidScore receives a score. It checks to see if the score is valid and returns a bool value. A valid score is between 0.0 and 10.0 inclusive. This function can be called whenever test scores are stored in a TestScores object. You must use the constants defined in the source file for the minimum and maximum scores.
The function named compareContestants receives two parameters each represents a contestant's data. It determines the winner and returns the winner's ID of those two contestants.
Test the data structure and the related functions by writing code in a main function as follows.
In the main function, define two TestScores variables. Call the readTestScores function for each of the variables so that the variables are loaded with the data.
If the first call returns false, issue the error message as follows,
First contestant's data invalid.
If the second call returns false, issue the error message as follows,
Second contestant's data invalid.
If both calls return true, make the following calls and print the final result.
Call printHeading to print the heading.
Call printScores to print the first contestant's data.
Call printScores to print the second contestant's data.
Call compareContestants to determine the winner.

#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
*/
If the input from the keyboard is 11 10.0 9.3 9.6 9.3 20 9.4 9.5 9.9 9.0 The output must look as follows S2 P# 51 53 S4 Average 11 10.0 9.3 9.6 9.9 9.3 9.0 9.6 9.4 20 9.4 9.5 The winner of the contest between contestant 11 and contestant 20 is contestant 11. If both contestants scored the same, print "Both contestants scored the same." Your code may be tested with a different set of input data. And it may be tested with invalid data to see if the error message is shown correctly
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
