Question

In: Computer Science

This assignment is to give you practice using struts, arrays, and sorting. (Objective C++ and please...

This assignment is to give you practice using struts, arrays, and sorting. (Objective C++ and please have a screenshot of output)

In competitive diving, each diver makes dives of varying degrees of difficulty. Nine judges score each dive from 0 through 10 in steps of 0.5. The difficulty is a floating-point value between 1.0 and 3.0 that represents how complex the dive is to perform. The total score is obtained by discarding the lowest and highest of the judges’ scores, adding the remaining scores, and then multiplying that total by the degree of difficulty. Write a program to score each of the dives, using the following input and output specifications, and determine the winner of the competition.

Input:

Create the file m7dive.txt for input and the output must go to an output file named mp7output.txt.

The first line contains an integer for the number of divers in the competition and subsequent lines contain:
Diver’s name (10 characters max, no blanks included), difficulty (double), and judges’ ratings (nine doubles). There is one line of data for each diver.

Example file:

2
Anne 2.0 9.0 8.5 8.5 8.5 9.0 9.0 8.0 9.5 9.5
Sarah 1.6 7.5 7.0 8.0 8.0 8.0 8.5 8.5 8.5 9.0

Output:

The name and difficulty, followed by the scores sorted into increasing order, in tabular form with appropriate headings along with the earned total points for that diver.

Example for sample output of the input file data above

NAME DIFF SORTED SCORES         POINTS
Anne 2.0 8.0 8.5 8.5 8.5 9.0 9.0 9.0 9.5 9.5 124.0
Sarah 1.6 7.0 7.5 8.0 8.0 8.0 8.5 8.5 8.5 9.0 91.2

The winner is Anne with the points of 124.0


At the end of the table, print out the name of the winner of the competition (the person with the highest points) and his/her final score.

Hint: You must use functions to modularize your program. Here is the full data of your input file mp7dive.txt, please send the output to an output file mp7output.txt.

The first line is 7 which is the number of divers in the file. The rest of the lines are as described above.

7
Anne          2.0   8.5  8.5  9.0   9.0   9.0   9.5  8.5  8.0  9.5
Sarah         1.6   7.5  8.5  8.0   8.0   7.0   9.0  8.5  8.5  8.0
Deborah   2.3   9.0  9.0   9.5  10.0 10.0 9.5  9.5   9.5  9.5
Kathryn     2.4   9.0  9.0  9.0   9.5   9.5    9.5  9.0  8.0  8.5
Jacquelin   2.7   9.0  9.0  9.5   9.5   9.0    8.5  8.5  8.5  9.5
Elizabeth   2.9   8.0  8.0  7.5   8.5   8.5    8.0  8.0  7.5  8.5
Tina           2.5   8.5  8.5  8.5   8.5   8.5    8.5  8.5  8.5   8.5

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// m7dive.txt

7
Anne 2.0 8.5 8.5 9.0 9.0 9.0 9.5 8.5 8.0 9.5
Sarah 1.6 7.5 8.5 8.0 8.0 7.0 9.0 8.5 8.5 8.0
Deborah 2.3 9.0 9.0 9.5 10.0 10.0 9.5 9.5 9.5 9.5
Kathryn 2.4 9.0 9.0 9.0 9.5 9.5 9.5 9.0 8.0 8.5
Jacquelin 2.7 9.0 9.0 9.5 9.5 9.0 8.5 8.5 8.5 9.5
Elizabeth 2.9 8.0 8.0 7.5 8.5 8.5 8.0 8.0 7.5 8.5
Tina 2.5 8.5 8.5 8.5 8.5 8.5 8.5 8.5 8.5 8.5

____________________________

#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
using namespace std;

struct Diver
{
string name;
double diffScore;
double scores[9];
};

// Function Declarations
void readData(ifstream& dataIn,struct Diver divers[],int size);
void calcAvgs(struct Diver divers[],int size,double tots[]);
void sort(struct Diver divers[],int size);
void display(struct Diver divers[],double tots[],int size);
int findWinner(double tots[],int size);
int main() {
   int size;
   //Declaring variables
ifstream dataIn;
   dataIn.open("m7dive.txt");
   //checking whether the file name is valid or not
if(dataIn.fail())
{
   cout<<"** File Not Found **";
return 1;
}
else
{
   dataIn>>size;
   // Creating array dynamically
struct Diver* divers = new Diver[size];
double* tots=new double[size];
readData(dataIn,divers,size);
calcAvgs(divers,size,tots);
sort(divers,size);
display(divers,tots,size);
int indx=findWinner(tots,size);
cout<<"The Winner is "<<divers[indx].name<<endl;
}
  
   return 0;
}
void readData(ifstream& dataIn,struct Diver divers[],int size)
{
   //Reading the data from the file
for(int i=0;i<size;i++)
   {
      dataIn>>divers[i].name>>divers[i].diffScore;
      for(int j=0;j<9;j++)
      {
          dataIn>>divers[i].scores[j];
           }
       }
      
      
dataIn.close();
}
void calcAvgs(struct Diver divers[],int size,double tots[])
{
   double min,max,avg=0.0,sum=0;

  
   for(int i=0;i<size;i++)
   {
           sum=0;
       min=divers[i].scores[0];
   max=divers[i].scores[0];
  
       for(int j=0;j<9;j++)
       {
       if(min>divers[i].scores[j])  
       {
           min=divers[i].scores[j];
       }
       if(max<divers[i].scores[j])
       {
           max=divers[i].scores[j];
       }
      
       sum+=divers[i].scores[j];
       }
  
  
       sum-=(min+max);
      
       tots[i]=sum*divers[i].diffScore;
      
   }

}
void sort(struct Diver divers[],int size)
{
   double temp;
   for(int i=0;i<size;i++)
   {
           //This Logic will Sort the Array of elements in Ascending order
  
   for (int k = 0; k < 9; k++)
{
for (int m = k + 1; m < 9; m++)
{
if (divers[i].scores[k] > divers[i].scores[m])
{
temp = divers[i].scores[k];
divers[i].scores[k] = divers[i].scores[m];
divers[i].scores[m] = temp;
}
}
}
   }
}
void display(struct Diver divers[],double tots[],int size)
{
  
   //setting the precision to two decimal places
   std::cout << std::setprecision(1) << std::fixed;
  
   for(int i=0;i<size;i++)
   {
       cout<<setw(10)<<left<<divers[i].name<<setw(5)<<right<<divers[i].diffScore;
       for(int j=0;j<9;j++)
       {
           cout<<setw(5)<<right<<divers[i].scores[j];
       }
       cout<<setw(8)<<right<<tots[i]<<endl;
      
   }
}
int findWinner(double tots[],int size)
{
   double max=tots[0];
   int pos=0;
   for(int i=0;i<size;i++)
   {
       if(max<tots[i])
       {
           max=tots[i];
           pos=i;
       }
   }
   return pos;
}

_______________________________

Output:

___________________________

mp7output.txt (Output file)

_______________Could you plz rate me well.Thank You


Related Solutions

05 Prepare : Checkpoint A Objective This assignment will give you practice writing event handling methods...
05 Prepare : Checkpoint A Objective This assignment will give you practice writing event handling methods to advance a ship in two dimensional space. Overview After completing (or while completing) the preparation material for this week, complete the following exercise. For this exercise, you will create a class that models a ship flying around in a 2-D plain (containing an x and y coordinate). A game class is provided to you that will help you call methods to advance and...
The objective of this homework is to give you experience using inheritance with C++. You will...
The objective of this homework is to give you experience using inheritance with C++. You will use the provided employee base class and implement two derived classes, salaried employee and hourly employee. For this assignment, you will use the base class Employee, which is implemented with the files Employee.h and Employee.cpp. A test file, test.cpp, is also provided for your use, as you choose to use it. Each employee object has a user id; a first and last name; a...
Question Objective: The objective of this lab exercise is to give you practice in programming with...
Question Objective: The objective of this lab exercise is to give you practice in programming with one of Python’s most widely used “container” data types -- the List (commonly called an “Array” in most other programming languages). More specifically you will demonstrate how to: Declare list objects Access a list for storing (i.e., writing) into a cell (a.k.a., element or component) and retrieving (i.e., reading) a value from a list cell/element/component Iterate through a list looking for specific values using...
Assignment Overview IN C++ This assignment will give you practice with numerical calculations, simple input/output, and...
Assignment Overview IN C++ This assignment will give you practice with numerical calculations, simple input/output, and if-else statements. Candy Calculator [50 points] The Harris-Benedict equation estimates the number of calories your body needs to maintain your weight if you do no exercise. This is called your basal metabolic rate or BMR. The calories needed for a woman to maintain her weight is: BMR = 655 + (4.3 * weight in pounds) + (4.7 * height in inches) - (4.7 *...
Objective: The purpose of this programming assignment is to practice using STL containers. This problem is...
Objective: The purpose of this programming assignment is to practice using STL containers. This problem is selected from the online contest problem archive (Links to an external site.), which is used mostly by college students world wide to challenge their programming ability and to prepare themselves for attending programming contests such as the prestige ACM International Collegiate Programming Contest (Links to an external site.). For your convenience, I copied the description of the problem below with my note on the...
using c++ 10. Sorting Orders Write a program that uses two identical arrays of eight integers....
using c++ 10. Sorting Orders Write a program that uses two identical arrays of eight integers. It should display the contents of the first array, then call a function to sort it using an ascending order bubble sort, modified to print out the array contents after each pass of the sort. Next the program should display the contents of the second array, then call a function to sort it using an ascending order selection sort, modified to print out the...
This is a C++ assignment The necessary implementations: Use arrays. Write some functions. Practice processing lists...
This is a C++ assignment The necessary implementations: Use arrays. Write some functions. Practice processing lists of values stored in an array. Write a modular program. Sort an array. Requirements to meet: Write a program that asks the user to enter 5 numbers. The numbers will be stored in an array. The program should then display the numbers back to the user, sorted in ascending order. Include in your program the following functions: fillArray() - accepts an array and it's...
This is a C++ assignment The necessary implementations: Use arrays. Write some functions. Practice processing lists...
This is a C++ assignment The necessary implementations: Use arrays. Write some functions. Practice processing lists of values stored in an array. Write a modular program. Sort an array. Requirements to meet: Write a program that asks the user to enter 5 numbers. The numbers will be stored in an array. The program should then display the numbers back to the user, sorted in ascending order. Include in your program the following functions: fillArray() - accepts an array and it's...
Program Assignment 1 C++ please Instructions This assignment will require the use of three arrays, which...
Program Assignment 1 C++ please Instructions This assignment will require the use of three arrays, which will be used in parallel. Create a program that keeps track of the sales of BBQ sauces for a company. The company makes several different types of sauces, Original, Sticky Sweet, Spicy, Sweet Heat, Hickory Bourbon and Smokey Mesquite. One array will contain the names of the different BBQ sauces. This array will be initialized from a text file with the 6 different names....
Objective: The goal of this lab is to practice (ragged) 2D arrays and simple recursion (in...
Objective: The goal of this lab is to practice (ragged) 2D arrays and simple recursion (in two separate parts). You are not allowed to use any of the built-in classes for this lab. If you find yourself needing to import anything at the top of your class, you are doing it wrong. Part A a) Create a class method called printArray2D that accepts a 2D integer array and prints out the values formatted such that each value occupies 4 spaces...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT