Question

You are working for a company that is responsible for determining the winner of a prestigious...

You are working for a company that is responsible for determining the winner of a prestigious international event, Men’s Synchronized Swimming. Scoring is done by eleven (11) international judges. They each submit a score in the range from 0 to 100. The highest and lowest scores are not counted. The remaining nine (9) scores are averaged and the median value is also determined. The participating team with the highest average score wins. In case of a tie, the highest median score, among the teams that are tied for first place, determines the winner.

Scoring data is be provided in the form of a text file. The scoring data for each team consists of two lines; the first line contains the team name; the second line contains the eleven (11) scores. You will not know ahead of time how many teams will participant. Your program will:

  • Prompt the user for the name and location of the scoring data file.
  • Process the sets of records in the file.
    • Read and store the team name in a string variable.
    • Read and store the scores in an array.
    • Display the team name followed by the complete set of scores on the next line.
    • Calculate and display to two decimal places the average of the nine qualifying scores, dropping the lowest and highest scores.
    • Determine and display the median value among the qualifying scores.
  • Display the count of the number of participating teams.
  • Display the winning team name and their average score. Indicate if they won by breaking a tie with a higher median score value.

A sample data file has been provided to allow you to test your program before submitting your work. Records in the sample data file look like this:

Sea Turtles

11 34 76 58 32 98 43.5 87 43 23 22

Tiger Sharks

85 55 10 99 35 5 65 75 8 95 22

The Angry Piranhas

30 10 80 0 100 40 60 50 20 90 70

The average score for the Sea Turtles was 46.5. The Angry Piranhas and the Tiger Sharks both had an average score of 50.0. The tiger sharks had a median value of 55.0, making them the winners of the competition.

You will define and use at least one function in your solution. As a suggestion, you should consider calling a function that sorts the array of judge’s score values into ascending order (lowest to highest). The advantage of doing this is that after being sorted, the lowest value is the first entry in your array and the highest value is the last entry in your array.

The average or arithmetic mean is a measure of central tendency. It is a single value that is intended to represent the collection of values. For this problem, you will only use nine of the values to determine the average. You will not include the highest score and the lowest score.

The median is another measure of central tendency. The median is often referred to as the middle value. In a set of values, half the values are less than the median and the other half are greater than the median. In a sorted array of five elements, the median is the third element. There are two values that are less then it and there are two values that are greater than it. In a sorted array of six values, the median is the simple average of the third and fourth values. In some cases, the median is a better representative value than the average.

You are encouraged to read the article entitled “Mixing getline with cin”.

To receive full credit for this programming assignment, you must:

  • Use the correct file name.
  • Submit a program that executes correctly.
  • Interact effectively with the user.

Grading Guideline:

  • Correctly name the file submitted. (5 points)
  • Create a comment containing the student’s full name. (5 points)
  • Document the program with other meaningful comments. (5 points)
  • Prompt the user for a file name and location. (10 points)
  • Open, read, and process all the data in the input file. (15 points)
  • Store the judge’s scores in an array. (10 points)
  • Correctly display the team name and all scores. (10 points)
  • Calculate and display the average score correctly. (10 points)
  • Calculate and display the median score correctly. (10 points)
  • Correctly count and display the number of competing teams. (10 points)
  • Correctly determine and display the winning team and score. (10 points)

Homework Answers

Answer #1
#include<iostream>
#include<fstream>
#include<string>
using namespace std;

// Function to swap two variables.
void swap(double *xp, double *yp)  
{  
    int temp = *xp;  
    *xp = *yp;  
    *yp = temp;  
}  
  
// A function to implement bubble sort  
void bubbleSort(double arr[], int n)  
{  
    int i, j;  
    for (i = 0; i < n-1; i++)      
      
    // Last i elements are already in place, so iterate till n-i-1 only. 
    for (j = 0; j < n-i-1; j++)  
        if (arr[j] > arr[j+1])  
            swap(&arr[j], &arr[j+1]);  
}  

int main(){
    string score_file;

    // Take input of score data file path
    cout<<"Enter the path of the scoring data file : ";
    cin>>score_file;

    ifstream infile(score_file);

    // Declare appropriate variables.
    int numberOfTeams = 0;
    string winning_team;

    double winning_average = 0;
    double winning_median = 0;

    bool isTie = false;

    // Read till end of file.
    while(!infile.eof()){

        // Taking input of team name and scores.
        string name;
        getline(infile, name);

        double scores[11];
        double totalScore = 0;
        for(int i=0;i<11;i++){
            infile>>scores[i];
            
        }
        infile.ignore();
        
       
       cout<<name<<endl;
        for(int i=0;i<11;i++){
            printf("%.2f ", scores[i]);
        }
        printf("\n");

        // Sorting the scores, and ignore first and last to calculate mean and median.
        bubbleSort(scores, 11);

        for(int i=1;i<10;i++){
            totalScore+=scores[i];
        }
        double median = scores[5];
        double average = totalScore/9;

       printf("Average score : %.2f\n", average);
       printf("Median score : %.2f\n", median);
        
        numberOfTeams++;

        // If current average is same as winning average, the winning team must
        if(average == winning_average){
                isTie = true;
            }
        // If average of current team is higher than winning average (or)
        // Average of current team is same as winning average but current team has higher median,
        // update the winner.
        if((average > winning_average) || (average == winning_average && median > winning_median)){

            if(average > winning_average){
                isTie = false;
            }

            winning_team = name;
            winning_average = average;
            winning_median = median;
        }
        cout<<"\n";
        
    }

    // Printing out relevant information.
    cout<<"Total number of participating teams : "<<numberOfTeams<<endl;
    
    cout<<"The winner is "<<winning_team<<" with average score "<<winning_average<<endl;

    if(isTie){
    cout<<"They won by breaking a tie with a higher median score."<<endl;
    }
}

Output is run on same data as provided in question.

Input file -

Please ensure that the input file is in the same format as I have run for the code to run correctly.

The code has been commented so you can understand the code better.

I would love to resolve any queries in the comments. Please consider dropping an upvote to help out a struggling college kid :)

Happy Coding !!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Programing lanugaue is C++ Plan and code a menu-driven modular program utilizing an array An input...
Programing lanugaue is C++ Plan and code a menu-driven modular program utilizing an array An input file has an unknown number of numeric values(could be empty too).Read the numbers from the input fileand store even numbers in one arrayand odd numbers in another array.Create menu options to Display count of even numbers, count of odd numbersand the sum values in each array Determine the average of each array Determine the median of each array Sort each array in ascending order(use...
Write a C++ program that reads data from a file, stores data in a one-dimensional array,...
Write a C++ program that reads data from a file, stores data in a one-dimensional array, and processes data as required. 1) Create a text file named “hw2data.txt” that contains student test scores in the range of 0~100. You can use the following sample data: 76.5 84 75 62 94.5 75.7 93 54 36.5 87.3 81.5 89.5 68 90 79.5 80 92.5 84 96 100 67.7 78 84.5 47 100 87.5 76.25 87 82.5 64 2) Read test scores from...
Design a solution that requests and receives student names and an exam score for each. Use...
Design a solution that requests and receives student names and an exam score for each. Use one-dimensional arrays to solve this. The program should continue to accept names and scores until the user inputs a student whose name is “alldone”. After the inputs are complete determine which student has the highest score and display that student’s name and score. Finally sort the list of names and corresponding scores in ascending order. When you are done, printout the Code and, also...
Topics Arrays Accessing Arrays Description Write a C++ program that will display a number of statistics...
Topics Arrays Accessing Arrays Description Write a C++ program that will display a number of statistics relating to data supplied by the user. The program will ask the user to enter the number of items making up the data. It will then ask the user to enter data items one by one. It will store the data items in a double array. Then it will perform a number of statistical operations on the data. Finally, it will display a report...
. Create a Matlab script that will load the file finc.mat and create a structure from...
. Create a Matlab script that will load the file finc.mat and create a structure from the appropriate with the following fields: • Company (string) • First_Name (string) • Last_Name (string) • Address (string) • Credit_Card_Number (Integer) • Account_Balance (Real) • Credit_Score (Real) • Transaction (Array) To the right of the field names above are the data type in parentheses. Your code should calculate and display the following: • The descriptive statistics discussed in class of the Credit Scores for...
Assignment #4 – Student Ranking : In this assignment you are going to write a program...
Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’...
C++ needs to output all of the name of the students not just first Write a...
C++ needs to output all of the name of the students not just first Write a program which uses an array of string objects to hold the five students' full names (including spaces), an array of five characters to hold each student's letter grade, a multi-dimensional array of integers to hold each of the five student's four test scores, and an array of five doubles to hold each student's average test score. The program will use a function to allow...
Write a Java program segment (not an entire program) that will summarize the season results for...
Write a Java program segment (not an entire program) that will summarize the season results for 5 players on one of TRU’s basketball teams. Each player played 10 games. Your program segment should ask the user for a player’s name, followed by the points that player scored in each of the 10 games (a total of 11 pieces of input). Your program will then produce the summary line shown below for that player.   Your program should get the data for...
language: JAVA the Problem Below are a series of problems you need to solve using recursive...
language: JAVA the Problem Below are a series of problems you need to solve using recursive methods. You will write a program that will read commands from an input file, with each command referring to one of the recursive problems to be executed. Each command will be followed (on the same line of input) by the respective parameters required for that problem. (15 points for main method) DescArrayCheck   Write a recursive method that checks whether an array of integers -...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this assignment must be submitted by the deadline on Blackboard. Submitting your assignment early is recommended, in case problems arise with the submission process. Late submissions will be accepted (but penalized 10pts for each day late) up to one week after the submission deadline. After that, assignments will not be accepted. Assignment The object of this assignment is to construct a mini-banking system that helps...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT