c++ program questoin

A particular talent competition has 5 judges, each of whom awards a score
between 0 and 10 to each performer. Fractional scores, such as 8.3, are allowed.
A performer’s final score is determined by dropping the highest and lowest score
received, then average the three remaining scores. Write a program that uses this
method to calculate a contestant’s score. It should include the following functions:

Void getJudgeData() should ask the user for a judge’s score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the five judges.

Void calcScore() should calculate and display the average of the three scores that remain after dropping the highest and lowest scores the performer received. This function should be called just once by main and should be passed the five scores. The last two functions should be called by calcScore(), which uses the returned information to determine which of the scores to drop.

Int findLowest() should find and return the lowest of the five scores passed to it.

Int findHighest() should find and return the highest of the five scores passed to it.

Input validation: Do not accept judge scores lower than 0 or higher than 10

Sure! Here's a C++ program that fulfills the requirements:

```cpp
#include <iostream>

// Function prototypes
void getJudgeData(double& score);
void calcScore(double scores[]);
int findLowest(double scores[]);
int findHighest(double scores[]);

int main() {
double scores[5];

// Get scores from each judge
for (int i = 0; i < 5; i++) {
std::cout << "Enter judge " << i + 1 << "'s score: ";
getJudgeData(scores[i]);
}

// Calculate and display final score
calcScore(scores);

return 0;
}

void getJudgeData(double& score) {
std::cin >> score;

// Validate the score
while (score < 0 || score > 10) {
std::cout << "Invalid score. Enter a score between 0 and 10: ";
std::cin >> score;
}
}

void calcScore(double scores[]) {
int lowest = findLowest(scores);
int highest = findHighest(scores);
double sum = 0;

// Calculate the sum of the three remaining scores
for (int i = 0; i < 5; i++) {
if (i != lowest && i != highest) {
sum += scores[i];
}
}

// Calculate and display the average
double average = sum / 3;
std::cout << "Final score: " << average << std::endl;
}

int findLowest(double scores[]) {
int lowestIndex = 0;

// Find the index of the lowest score
for (int i = 1; i < 5; i++) {
if (scores[i] < scores[lowestIndex]) {
lowestIndex = i;
}
}

return lowestIndex;
}

int findHighest(double scores[]) {
int highestIndex = 0;

// Find the index of the highest score
for (int i = 1; i < 5; i++) {
if (scores[i] > scores[highestIndex]) {
highestIndex = i;
}
}

return highestIndex;
}
```

Feel free to ask if you have any questions about the code!

Here's a step-by-step guide to writing a C++ program that follows the given requirements:

Step 1: Start by including the necessary headers:

```cpp
#include <iostream>
#include <limits>
```

Step 2: Declare the function prototypes:

```cpp
void getJudgeData(double& score);
void calcScore(double scores[]);
int findLowest(double scores[]);
int findHighest(double scores[]);
```

Step 3: Implement the `getJudgeData()` function:

```cpp
void getJudgeData(double& score) {
do {
std::cout << "Enter a judge's score (between 0 and 10): ";
std::cin >> score;

if (score < 0 || score > 10) {
std::cout << "Invalid score. Please try again." << std::endl;
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
} while (score < 0 || score > 10);
}
```

Step 4: Implement the `calcScore()` function:

```cpp
void calcScore(double scores[]) {
int lowestIndex = findLowest(scores);
int highestIndex = findHighest(scores);

double sum = 0;

for (int i = 0; i < 5; i++) {
if (i != lowestIndex && i != highestIndex) {
sum += scores[i];
}
}

double average = sum / 3;

std::cout << "The performer's final score is: " << average << std::endl;
}
```

Step 5: Implement the `findLowest()` function:

```cpp
int findLowest(double scores[]) {
int lowestIndex = 0;

for (int i = 1; i < 5; i++) {
if (scores[i] < scores[lowestIndex]) {
lowestIndex = i;
}
}

return lowestIndex;
}
```

Step 6: Implement the `findHighest()` function:

```cpp
int findHighest(double scores[]) {
int highestIndex = 0;

for (int i = 1; i < 5; i++) {
if (scores[i] > scores[highestIndex]) {
highestIndex = i;
}
}

return highestIndex;
}
```

Step 7: In the `main()` function, create an array to store the judge's scores and call the necessary functions:

```cpp
int main() {
double scores[5];

for (int i = 0; i < 5; i++) {
getJudgeData(scores[i]);
}

calcScore(scores);

return 0;
}
```

That's it! You've implemented a program that calculates a contestant's score according to the given rules.

Sure! Here's an example of how you can implement the required functions in C++ to calculate a contestant's score based on the given rules:

```cpp
#include<iostream>

void getJudgeData(double &score) {
do {
std::cout << "Enter the judge's score (between 0 and 10): ";
std::cin >> score;
} while (score < 0 || score > 10);
}

int findLowest(double scores[]) {
int lowestIndex = 0;
for (int i = 1; i < 5; i++) {
if (scores[i] < scores[lowestIndex]) {
lowestIndex = i;
}
}
return lowestIndex;
}

int findHighest(double scores[]) {
int highestIndex = 0;
for (int i = 1; i < 5; i++) {
if (scores[i] > scores[highestIndex]) {
highestIndex = i;
}
}
return highestIndex;
}

void calcScore(double scores[]) {
int lowestIndex = findLowest(scores);
int highestIndex = findHighest(scores);

double sum = 0;
for (int i = 0; i < 5; i++) {
if (i != lowestIndex && i != highestIndex) {
sum += scores[i];
}
}

double average = sum / 3;
std::cout << "Final score: " << average << std::endl;
}

int main() {
double scores[5];

for (int i = 0; i < 5; i++) {
getJudgeData(scores[i]);
}

calcScore(scores);

return 0;
}
```

Explanation:

- The `getJudgeData` function asks the user for a judge's score, checks if it is within the valid range (0-10), and stores it in the respective element of the `scores` array.
- The `findLowest` function iterates through the `scores` array and returns the index of the lowest score.
- The `findHighest` function iterates through the `scores` array and returns the index of the highest score.
- The `calcScore` function first calls `findLowest` and `findHighest` to determine the lowest and highest scores. Then, it calculates the sum of the three remaining scores by skipping the lowest and highest scores. Finally, it calculates the average and displays it as the final score.
- In the `main` function, it initializes an array `scores` to hold the scores of the five judges. It then calls `getJudgeData` for each judge to input their scores. Finally, it calls `calcScore` passing the `scores` array to calculate and display the contestant's final score.

Make sure to compile and run the program, and then you can input the judge's scores to get the final result.