Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed
image text in transcribed
#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
*/
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 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 film. 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 ip in the id tield and the scores in the fields for scores. If the read is successful and all values are valid, the function returns true. Otherwiselt returns folse. The function named getID receives a pointer parametar that points to a TestScores data structure that represents a contestant's doto. It returns the of the contestant. The function named getAverageScore receives a pointer parameter that points to a Testscores dota 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 show at the bottom. You must use the formatting constants defined in the source file to format the heading The function named prints.cores receiven a pointer parameter that points to a TestScores data structure that represents a contestants data. It displays the ID, the scores of the contestant and the average occording 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 lavaldScore receives ascenIt checks to see if the score is valid and returns a bool value. A valid score is between 0,0 and 10.0 mclusive. 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 ond maximum scores The function named compareContestants receives two parameters each represents a contestant's dato. I determines the winner and returns the winner's 10 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, detine two Testscores variables. call the rood Toetscores function for each of the verboties so that the variables are loaded with the data, if the first call returns fole, on the error message as follows First contestant's dota invold. If the second coll return false, lue the error message as follows Second contestant's doto invalid. both calls return true, make the following calls and print the final result, Col printheading to print the heading CollprintScores to print the first contestant's data Col printScores to print the second contestant's data Cal compareContestants to determine the winner. Print the result of the contest 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. The output format is shown below. 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# S1 S3 S4 Average 11 20 10.0 9.4 9.3 9.5 9.6 9.9 9.3 9.0 9.6 9.4 The winner of the contest between contestant 11 and contestant 20 is contestant 11

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel 2024 In 7 Days

Authors: Alan Dinkins

1st Edition

B0CJ3X98XK, 979-8861224000

More Books

Students also viewed these Databases questions

Question

What is human nature?

Answered: 1 week ago