Question
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
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. Here is the code i have. This sorts by name but need it to sort by the averages across from least to greatest and print out like i have but sorted by average instead of name.
#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."< for (int r=1;r<=10;r++) {//top of r getline(infile,bowlers2[r]); pos=bowlers2[r].find_first_of(' '); bowlers2[r].erase(pos,2); for(c=1;c<=3;c++) {//top of c infile>>scores[r][c]; }//bottom of c infile.ignore(100,' '); }//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< //find the low score double lowest = 301.0; string lowname = ""; cout< //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< //find Hallmark and print his average cout< for (r=1;r<=10;r++) { if (bowlers2[r]=="keith hallmark") { cout< bubblesort(bowlers2,11,scores,11);//to call the bubblesort cout<<"After bubblesort "; for(int r=1;r<=11;r++) { cout< 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;jarray[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 The text file includes the following: Linus too good 100 23 210 Charlie brown 1 2 12 Snoopy 300 300 100 Peperment Patty 223 300 221 Pig Pen 234 123 212 Red Headed Girl 123 222 111 Marcey 1 2 3 keith hallmark 222 300 180 anna hallmark 222 111 211 roxie hallmark 100 100 2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started