Question

Posted this a few hours ago. Can anyone help with this? IN C++ Perform the following:...

Posted this a few hours ago. Can anyone help with this? IN C++ Perform the following: Read 10 bowlers with 3 scores each into 1 string array and 1 numeric array(2 dimension double array) Sort the data by individual bowlers averages, Don't forget to sort their names also. Calculate the average across and store in your existing array. Calculate the average down and store in your existing array. Print out the contents of both arrays. This will print the averages across and down also. Search for a bowler (bowler named keith) print his 3 scores and averages. Instead of sorting by name, i need to sort by the averages of the individual bowlers...the average that was calculated across in the original problem. I would like to do it using bubble sort. I should print out all of the bowlers with their averages across and down and sorted by the averages that print out across. Here is the code i have so far but this sorts by name.

#include //to use cout and cin and endl// allows using cout without std::cout
#include // to use string data type
#include //to use strlen, strcmp, strcpy
#include    //for pow function,sqrt,abs
#include // for set precision, setw,
#include //for file input
#include // to use assert to disable place before #define NDEBUG
#include //for random numbers, exit function
#include //time function used for rand seed
#include // for toupper, tolower
#include
#include
#include

using namespace std;
/*
*
*/
void bubblesort(string array[],int length,double scores2[][5],int length2);
int main(int argc, char** argv)
{
ofstream text ("bowleravg.txt");
ifstream infile;
string bowlers2[12];
double scores [12][5];
int pos=0;
int c=0,r=0;
infile.open("C:\\Data\\bowlers2.txt");
if(!infile)
{
    cout<<"can not open the input file."<     text<<"can not open the input file."<<"\r\n";
    cout<<"this program will terminate."<     text<<"this program will terminate."<<"\r\n";
    return 1;
}
//read from file into arrays
cout<<"***********************************************************************************"< text<<"***********************************************************************************"<<"\r\n";
cout<<"Peanuts League"<

for (int r=1;r<=10;r++)
    {//top of r
   getline(infile,bowlers2[r]);
   pos=bowlers2[r].find_first_of('\r');
   bowlers2[r].erase(pos,2);
for(c=1;c<=3;c++)
    {//top of c
   infile>>scores[r][c];
    }//bottom of c
    infile.ignore(100,'\n');
    }//bottom of r
   infile.close();
  
//calculate average across (bowler average)
for(r=1;r<=10;r++)
    {//top of outside loop
    for (c=1;c<=3;c++)
    {//top of inside loop
        scores [r][4]=scores[r][4]+scores[r][c];
    }//bottom of inside loop
    scores[r][4]=scores[r][4]/3.0;
    }//bottom of outside loop
  
//average down
for (c=1;c<=3;c++)
{//top of outside loop
   for(r=1;r<=10;r++)
{//top of inside loop
      scores[11][c]=scores[11][c]+scores[r][c];
}//bottom of inside loop
scores[11][c]=scores[11][c]/10.0;
    }//bottom of outside loop
  
//print out average down
bowlers2[11]="TTl. Bowling Avg.";

for(int r=1;r<=11;r++)  
{//top of outside loop
    cout<     text<     cout<     text<     for (int c=1;c<=4;c++)
    {//top of c loop to print out scores
        if(c<=3)
          cout<         else
          cout<         if(r==11&&c==4)
            break;
        if(r==11)
            cout<       text<         cout<         text<        cout<         text<     }//bottom of c loop to print out scores
      cout<       text<<"\r\n";
}//bottom of outside loop

//find the low score
double lowest = 301.0;
string lowname = "";
cout< text< for (r=1;r<=10;r++)
{
    if (scores [r][4]     {
        lowest = scores[r][4];
        lowname = bowlers2[r];    
    }
}
cout< text<<"\r\n";
cout<<"***************************************************************************"< text<<"***************************************************************************"<<"\r\n";
cout<<"The lowest score of "<

//find the high score
double highest = -1.0;
string highname = "";
for (r=1;r<=10;r++)
{
    if (scores [r][4]>highest)
    {
        highest = scores [r][4];
        highname = bowlers2[r];
    }
}
cout< text<<"\r\n";
cout<<"The highest score of "< text<<"The highest score of "<

//find Hallmark and print his average
cout< text<<"\r\n";
bool flag=false;

for (r=1;r<=10;r++)
{
if (bowlers2[r]=="keith hallmark")
{
   cout<

bubblesort(bowlers2,11,scores,11);//to call the bubblesort
cout<<"After bubblesort\n\n";

for(int r=1;r<=11;r++)  
{  
    cout<     text<     cout<     text<    
    for (int c=1;c<=4;c++)
    {//top of c loop to print out scores
        if(c<=3)//top of if else
          cout<           else
          cout<         if(r==11&&c==4)//to exlude
            break;
        if(r==11)
            cout<       text<         cout<         text<        cout<         text<     }//bottom of c loop to print out scores
   
      cout<       text<<"\r\n";
}
return 0;
}

void bubblesort(string array[],int length,double scores2[][5],int length2)//to sort the array
{
    int i=0,j=0,z=0;
    string temp;
    double itemp=0.0;
    bool test=true;//in case it is already sorted
    for(i=length-1;i>0;i--)//top of outer loop
    {
        test=true;
        for(j=0;j         {//top of inner loop
            if (array[j]>array[j+1])//comparing adjacent rows in the array
            {//top of if
                temp=array[j];
                array[j]=array[j+1];
                array[j+1]=temp;
                for(z=1;z<5;z++)
                {
                   itemp=scores2[j][z];
                   scores2[j][z]=scores2[j+1][z];
                   scores2[j+1][z]=itemp;
                }
                test=false;
            }//bottom of if
        }//bottom of inner loop
        if (test)break;
    }//bottom of outer loop
}//bottom of bubble sort

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The program that you've written is logically correct and should work. The sorting must be performed on the averages of the players.

Add a comment
Know the answer?
Add Answer to:
Posted this a few hours ago. Can anyone help with this? IN C++ Perform the following:...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • IN C++ PLEASE -------Add code to sort the bowlers. You have to sort their parallel data...

    IN C++ PLEASE -------Add code to sort the bowlers. You have to sort their parallel data also. Print the sorted bowlers and all their info . You can use a bubble sort or a shell sort. Make sure to adjust your code depending on whether or not you put data starting in row zero or row one. Sort by Average across, lowest to highest. The highest average should then be on the last row.. When you sort the average, you...

  • Can anyone help me with my C++ assignment on structs, arrays and bubblesort? I can't seem...

    Can anyone help me with my C++ assignment on structs, arrays and bubblesort? I can't seem to get my code to work. The output should have the AVEPPG from highest to lowest (sorted by bubbesort). The output of my code is messed up. Please help me, thanks. Here's the input.txt: Mary 15 10.5 Joseph 32 6.2 Jack 72 8.1 Vince 83 4.2 Elizabeth 41 7.5 The output should be: NAME             UNIFORM#    AVEPPG Mary                   15     10.50 Jack                   72      8.10 Elizabeth              41      7.50 Joseph                 32      6.20 Vince                  83      4.20 ​ My Code: #include <iostream>...

  • C++ how can I fix these errors this is my code main.cpp #include "SpecialArray.h" #include <...

    C++ how can I fix these errors this is my code main.cpp #include "SpecialArray.h" #include <iostream> #include <fstream> #include <string> using namespace std; int measureElementsPerLine(ifstream& inFile) {    // Add your code here.    string line;    getline(inFile, line);    int sp = 0;    for (int i = 0; i < line.size(); i++)    {        if (line[i] == ' ')            sp++;    }    sp++;    return sp; } int measureLines(ifstream& inFile) {    // Add your code here.    string line;    int n = 0;    while (!inFile.eof())    {        getline(inFile,...

  • Am I getting this error because i declared 'n' as an int, and then asking it...

    Am I getting this error because i declared 'n' as an int, and then asking it to make it a double? This is the coude: #include "stdafx.h" #include <iostream> #include <fstream> #include <string> #include <algorithm> #include <vector> using namespace std; void sort(double grades[], int size); char calGrade(double); int main() {    int n;    double avg, sum = 0;;    string in_file, out_file;    cout << "Please enter the name of the input file: ";    cin >> in_file;   ...

  • hello there. can you please help me to complete this code. thank you. Lab #3 -...

    hello there. can you please help me to complete this code. thank you. Lab #3 - Classes/Constructors Part I - Fill in the missing parts of this code #include<iostream> #include<string> #include<fstream> using namespace std; class classGrades      {      public:            void printlist() const;            void inputGrades(ifstream &);            double returnAvg() const;            void setName(string);            void setNumStudents(int);            classGrades();            classGrades(int);      private:            int gradeList[30];            int numStudents;            string name;      }; int main() {          ...

  • Hi! 1. I need some help with sorting string in a text file. My goal is...

    Hi! 1. I need some help with sorting string in a text file. My goal is to 1 shift left strings for string.length time. I was able to do that successfully. However, I am also trying to sort, using insertion sort , the resulting shifts. I store all shifts in a vector (or is it better to use an array?!) , and try to sort them that way, but my output is just the shifted strings but not sorted. Can...

  • I want to change this code and need help. I want the code to not use...

    I want to change this code and need help. I want the code to not use parallel arrays, but instead use one array of struct containing the data elements, String for first name, String for last name,Array of integers for five (5) test scores, Character for grade. If you have any idea help would be great. #include #include #include #include using namespace std; const int NUMBER_OF_ROWS = 10; //number of students const int NUMBER_OF_COLUMNS = 5; //number of scores void...

  • I need to update this C++ code according to these instructions. The team name should be...

    I need to update this C++ code according to these instructions. The team name should be "Scooterbacks". I appreciate any help! Here is my code: #include <iostream> #include <string> #include <fstream> using namespace std; void menu(); int loadFile(string file,string names[],int jNo[],string pos[],int scores[]); string lowestScorer(string names[],int scores[],int size); string highestScorer(string names[],int scores[],int size); void searchByName(string names[],int jNo[],string pos[],int scores[],int size); int totalPoints(int scores[],int size); void sortByName(string names[],int jNo[],string pos[],int scores[],int size); void displayToScreen(string names[],int jNo[],string pos[],int scores[],int size); void writeToFile(string...

  • #include<stdio.h> #include<stdio.h> int main(){ int i; //initialize array char array[10] = {“Smith”, “Owen”, “Kowalczyk”, “Glass”, “Bierling”,...

    #include<stdio.h> #include<stdio.h> int main(){ int i; //initialize array char array[10] = {“Smith”, “Owen”, “Kowalczyk”, “Glass”, “Bierling”, “Hanenburg”, “Rhoderick”, “Pearce”, “Raymond”, “Kamphuis”}; for(int i=0; i<8;i++){ for(int j=0; j<9; j++){ if(strcmp(array[j],array[j+1])>0){ char temp[20]; strcpy(temp,array[j]); strcpy(array[j],array[j+1]); strcpy(array[j+1],temp); } } } printf(“---------File Names---------\n”); for(inti=0; i<9; i++){ printf(“\t%s\n”,array[i]); } printf(-------5 Largest Files according to sorting----\n”); for(int i=0;i>=5;i--) { printf(“\t%s\n”,array[i]); } return0; } Consider the "sort" program (using with void* parameters in the bubblesort function) from the week 10 "sort void" lecture. Modify it as follows...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT