C++- LAB #3 - Diving Competition Scoring a Diving Competition The names of diver
ID: 3840686 • Letter: C
Question
C++-
LAB #3 - Diving Competition Scoring a Diving Competition The names of divers and their scores for a dive are stored in a file called DIV1.txt. Each divers name is stored on 3 line followed by that diver's data for one dive. The data contains the difficulty factor of the dive and a score from each of 5 judges. Compute each diver's total score by throwing out his. her low and high scores (do not change the order of the scores), averaging the remaining three scores, and then multiplying this average by the difficulty factor Output each diver's name his her scores, and the total score for the dive arranged from the dim with the highest score to the lowest. Output is to be directed to a file The contents of DIV1.txt is to be: KNIFE JACK 1.3 6.0 5.1 6.3 5.9 6.5 WILLIAMSON FLIP A 1.4 3.5 4.1 4.7 7.2 3.3 SOMMER TODD 1.2 8.0 9.1 8.1 9.3 9.0 SWAN HIKE 1.1 4.3 2.1 9.5 6.2 7.0 Input: Assume a maximum of 50 divers Name of diver difficulty factor array for scores, and the total score for the dive should be members of a structure. The structure should contain a nested structure for difficulty factor, array of scores, and total score for dive. Each diver's structure needs to be an element of an array of structures. Processes: Computation of total score is to be handled in a separate function. A separate function should perform the sort using the bubble sort algorithm Output: Use a separate function for output. Output is to the deducted to a file. All functions need to include Pre and Post. Theme Issues: Array of strummersExplanation / Answer
The code is as follows:
#include<iostream.h>
#include<string>
#define no_of_judges 5
struct diver{
string name;
float sores[no_of_judges];
float total_score;
float diff_factor;
};
void main(){
ifstream infile;
ofstream outfile;
char str[255];
float diff_factor;
vector<diver> list;
sruct diver div;
float num;
float sum;
float min;
float max;
infile.open("DIV1.txt");
while (infile){
infile.getline(str,255);
if (infile){
div.name = new string(str);
}
if (infile >> diff_factor){
div.diff_factor = diff_factor;
}
for (int i = 0; i<no_of_judges; i++){
if (infile >> num){
div.scores[i] = num;
}
}
list.push_back(div);
}
infile.close();
for (int i = 0; i<list.size(); i++){
max = list.at(i).scores[0];
min = list.at(i).scores[0];
for (j = 0; j<no_of_judges; j++){
if (max < list.at(i).scores[j])
max = list.at(i).scores[j];
if (min > list.at(i).scores[j])
min = list.at(i).scores[j];
}
sum = 0;
for (j = 0; j<no_of_judges; j++){
if (list.at(i).scores[j]!= max && list.at(i).scores[j]!= min)
sum = sum + list.at(i).scores[j];
}
list.at(i).total_score = (sum/ (no_of_judges - 2)) * list.at(i).diff_factor;
}
for (int i = 0; i<list.size(); i++){ // Sorting divers from highest total score to lowest total_score)
for (int j = 0; j<list.size()-i-1; j++){
if (list.at(j).total_score < list.at(j+1).total_score){
div = list[j];
list[j] = list[j+1];
list[j+1] = div;
}
}
}
outfile.open("output.txt");
for (int i = 0; i<list.size(); i++){
outfile << list.at(i).name << endl;
for (int j = 0; j<no_of_judges; j++)
outfile << list.at(i).scores[j] << " ";
outfile << list.at(i).total_score << endl;
}
outfile.close();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.