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 also have to move the names and scores, this is the reason you can't use a built-in sort.
This is the file-
jane doe 100 99 98
John smith 55 66 44
Keith Hallmark 100 100 100
Buggs Bunny 99 88 89
Charlie Brown 66 66 65
Road Runner 0 0 1
Sure S Slow 44 22 33
Here is the code I have so far...
#include <iostream> //to use cout and cin and endl// allows using cout without std::cout
#include <string> // to use string data type
#include <cstring> //to use strlen, strcmp, strcpy
#include <cmath> //for pow function,sqrt,abs
#include <iomanip> // for set precision, setw,
#include <fstream> //for file input
#include <cassert> // to use assert to disable place before #define NDEBUG
#include <cstdlib>//for random numbers, exit function
#include <ctime>//time function used for rand seed
#include <cctype> // for toupper, tolower
#include <algorithm>
#include <locale.h>
#include <stdio.h>
#include <iomanip>
#include <bits/stdc++.h>
#include <vector>
#include <sstream>
using namespace std;
struct my_facet : public std::numpunct<char>{
explicit my_facet(size_t refs = 0) : std::numpunct<char>(refs) {}
virtual char do_thousands_sep() const { return ','; }
virtual std::string do_grouping() const { return "\003"; }
};
int main()
{//top of main
locale global; //declare locale scope
locale withgroupings(global, new my_facet);
//declare locale variable name
locale was = cout.imbue(withgroupings); //imbue cout statements with locale
//variables
ifstream infile;//input file
//infile is any legal variable name
ofstream outfile;
infile.open("bowlers2.txt"); //output file
//outfile is any legal variable name
//we are just using the output file
outfile.imbue(withgroupings); //imbue outfile
//the file name and past are a string
if(!infile)
{
cout<<"File or path not found\n";
cout<<"This program will terminate\n";
return 1;//terminates the program
}
string bowlers2[20];//to hold the name
double scores[20][5];//tow dimension array
//I made this array double, because I will use one
//of the columns for the averages across
string mystring;
char linein[80];
int r =0;
int c =0;
int pos=0;
double highest = 0.0;
double lowest =0.0;
string highname;
string lowname;
r=1;
while(!infile.fail())
//for(r=1;r<=7;r++)
{//top of outside for
getline(infile,bowlers2[r]);
pos = bowlers2[r].find_first_of('\r');
if(pos>0)
bowlers2[r].erase(pos,2);
for(c=1;c<=3;c++)
{
infile>>scores[r][c];
}
infile.ignore(100,'\n');
//increment counter
r=r+1;//r++
}//bottom of while loop
infile.close();
//calculate number of bowlers
int num=r-2;
//print out the array
cout<<fixed<<setprecision(0);
for(r=1;r<=num;r++)
{
//print the name
cout<<setw(20)<<left<<bowlers2[r];
//print out the 3 scores
for(c=1;c<=3;c++)
{
cout<<setw(8)<<right<<scores[r][c];
}
cout<<endl;
}
//homework day 16
//average across
for(r=1;r<num;r++)
{
for(c=1;c<=3;c++)
{
scores[r][4]=scores[r][4]+scores[r][c];
}
scores[r][4]=scores[r][4]/3.0;
}
//print average across
cout<<"******************\n\n";
for(r=1;r<=num;r++)
{
cout<<setw(20)<<bowlers2[r];
cout<<setprecision(0);
for(c=1;c<=3;c++)
{
cout<<setw(8)<<scores[r][c];
}
cout<<setprecision(2)<<setw(10)<<scores[r][4]<<endl;
}
//find the highest average
highest=-1;
for(r=1;r<=num;r++)
{
if (scores[r][4]>highest)
{
highest=scores[r][4];
highname=bowlers2[r];
}
}
cout<<highest<<" "<<highname<<endl;
//find lowest average
lowest=301;//a number that should not exist in the real data
for(r=1;r<=num;r++)
{
if(scores[r][4]<lowest)
{
lowest=scores[r][4];
lowname=bowlers2[r];
}
}
cout<<lowest<<" "<<lowname<<endl;
//find a specific precision
cout<<"\n Please enter a name to search for-->";
getline(cin,highname);
cout<<"Searching for "<<highname<<".......";
bool myflag=false;
for(r=1;r<num;r++)
{
if(highname==bowlers2[r])
{
cout<<highname<<" "<<scores[r][4]<<endl;;;
myflag=true;
break;
}
}
if (!myflag)
cout<<"Name not found\n";
for(int passnum =10;passnum>=1;passnum--)
{
for(int i=1;i<passnum;i++)
{
if(bowlers2[i]>bowlers2[i+1])
{
swap(bowlers2[i],bowlers2[i+1]);
swap(scores[i][1],scores[i+1][1]);
swap(scores[i][2],scores[i+1][2]);
swap(scores[i][3],scores[i+1][3]);
}
}
}
}//end of main
#include <iostream> //to use cout and cin and endl// allows using cout without std::cout #include <string> // to use string data type #include <cstring> //to use strlen, strcmp, strcpy #include <cmath> //for pow function,sqrt,abs #include <iomanip> // for set precision, setw, #include <fstream> //for file input #include <cassert> // to use assert to disable place before #define NDEBUG #include <cstdlib> //for random numbers, exit function #include <ctime> //time function used for rand seed #include <cctype> // for toupper, tolower #include <algorithm> #include <locale.h> #include <stdio.h> #include <iomanip> #include <bits/stdc++.h> #include <vector> #include <sstream> using namespace std; struct my_facet : public std::numpunct<char> { explicit my_facet(size_t refs = 0) : std::numpunct<char>(refs) { } virtual char do_thousands_sep() const { return ','; } virtual std::string do_grouping() const { return "\003"; } }; void swap(string& a, string& b) { string t = a; a = b; b = t; } void swap(double& a, double& b) { double t = a; a = b; b = t; } double getLastToken(string &s) { int pos = s.find_last_of(" "); double d; stringstream ss(s.substr(pos+1)); ss >> d; s = s.substr(0, pos); return d; } int main() { //top of main locale global; //declare locale scope locale withgroupings(global, new my_facet); //declare locale variable name locale was = cout.imbue(withgroupings); //imbue cout statements with locale //variables ifstream infile; //input file //infile is any legal variable name ofstream outfile; infile.open("bowlers2.txt"); //output file //outfile is any legal variable name //we are just using the output file outfile.imbue(withgroupings); //imbue outfile //the file name and past are a string if (!infile) { cout << "File or path not found\n"; cout << "This program will terminate\n"; return 1; //terminates the program } string bowlers2[20]; //to hold the name double scores[20][5]; //two dimension array //I made this array double, because I will use one //of the columns for the averages across string mystring; char linein[80]; int r = 0; int c = 0; int pos = 0; double highest = 0.0; double lowest = 0.0; string highname; string lowname; r = 1; while (getline(infile, mystring)) { scores[r][3] = getLastToken(mystring); scores[r][2] = getLastToken(mystring); scores[r][1] = getLastToken(mystring); scores[r][4] = 0; bowlers2[r] = mystring; //increment counter r = r + 1; } //bottom of while loop infile.close(); //calculate number of bowlers int num = r - 1; //print out the array cout << fixed << setprecision(0); for (r = 1; r <= num; r++) { //print the name cout << setw(20) << left << bowlers2[r]; //print out the 3 scores for (c = 1; c <= 3; c++) { cout << setw(8) << right << scores[r][c]; } cout << endl; } //homework day 16 //average across for (r = 1; r <= num; r++) { for (c = 1; c <= 3; c++) { scores[r][4] = scores[r][4] + scores[r][c]; } scores[r][4] = scores[r][4] / 3.0; } //print average across cout << "******************\n\n"; for (r = 1; r <= num; r++) { cout << setw(20) << bowlers2[r]; cout << setprecision(0); for (c = 1; c <= 3; c++) { cout << setw(8) << scores[r][c]; } cout << setprecision(2) << setw(10) << scores[r][4] << endl; } //find the highest average highest = -1; for (r = 1; r <= num; r++) { if (scores[r][4] > highest) { highest = scores[r][4]; highname = bowlers2[r]; } } cout << highest << " " << highname << endl; //find lowest average lowest = 301; //a number that should not exist in the real data for (r = 1; r <= num; r++) { if (scores[r][4] < lowest) { lowest = scores[r][4]; lowname = bowlers2[r]; } } cout << lowest << " " << lowname << endl; //find a specific precision cout << "\n Please enter a name to search for-->"; getline(cin, highname); cout << "Searching for " << highname << "......."; bool myflag = false; for (r = 1; r <= num; r++) { if (highname == bowlers2[r]) { cout << highname << " " << scores[r][4] << endl; myflag = true; break; } } if (!myflag) cout << "Name not found\n"; for (int passnum = 0; passnum <= num; passnum++) { for (int i = 1; i < num-passnum; i++) { if (scores[i][3] > scores[i + 1][3]) { swap(bowlers2[i], bowlers2[i + 1]); swap(scores[i][1], scores[i + 1][1]); swap(scores[i][2], scores[i + 1][2]); swap(scores[i][3], scores[i + 1][3]); swap(scores[i][4], scores[i + 1][4]); } } } cout << "******************\n\n"; cout << "Sorted Scores: \n"; for (r = 1; r <= num; r++) { cout << setw(20) << bowlers2[r]; cout << setprecision(0); for (c = 1; c <= 3; c++) { cout << setw(8) << scores[r][c]; } cout << setprecision(2) << setw(10) << scores[r][4] << endl; } } //end of main
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.
IN C++ PLEASE -------Add code to sort the bowlers. You have to sort their parallel data...
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...
I need to add something to this C++ program.Additionally I want it to remove 10 words from the printing list (Ancient,Europe,Asia,America,North,South,West ,East,Arctica,Greenland) #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int> words); int main() { // Declaring variables std::map<std::string,int> words; //defines an input stream for the data file ifstream dataIn; string infile; cout<<"Please enter a File Name :"; cin>>infile; readFile(infile,words);...
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...
I need to make a few changes to this C++ program,first of all it should read the file from the computer without asking the user for the name of it.The name of the file is MichaelJordan.dat, second of all it should print ,3 highest frequencies are: 3 words that occure the most.everything else is good. #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int>...
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...
C++. I need to alter this code below to the current specifications. Console Progressing Complete!!! Specifications Included is an input file. Included is a function to aide, if needed Use the functions, enum, and namespace defined in Assignment 6. You will need to use a loop to read each student’s data You will need to load every homework grade into an array Calculate the homework average The homework average can be calculated while the array is loaded Move the printing...
I have 2 issues with the C++ code below. The biggest concern is that the wrong file name input does not give out the "file cannot be opened!!" message that it is coded to do. What am I missing for this to happen correctly? The second is that the range outputs are right except the last one is bigger than the rest so it will not output 175-200, it outputs 175-199. What can be done about it? #include <iostream> #include...
I wrote code in C++ that takes a text file containing information on different football players and their combine results, stores those players as a vector of objects of the class, and prints out those objects. Finally, I wrote a function that calculates the average weight of the players. MAIN.CPP: #include "Combine.h" #include using namespace std; // main is a global function // main is a global function int main() { // This is a line comment //cout << "Hello,...
The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib> #include <iomanip> #define MAX 1000 using namespace std; //Function to Add a new inventory item to the data into the array in memory void addItem(string desc[],string idNum[], float prices[], int qty[],int &num) { cout<<"Enter the names:"; cin>>desc[num]; cout<<"Enter the item number:"; cin>>idNum[num]; cout<<"Enter the price of item:"; cin>>prices[num]; cout<<"Enter the...