Question

In C++ Create a program that uses only Selection Sort and Insertion Sort for the National...

In C++

Create a program that uses only Selection Sort and Insertion Sort for the National Football League list of current players

Inputting data from a text file named "NFLplayers.txt"

Only want the name of the player(first name then last name), their team name, and position they play. Example is: Patrick Mahomes, Chiefs, Quarterback

Output lists to a text file along with how long it took to go through the Selection Sort and Insertion Sort and how many iterations it took for each

Thanks.

Homework Answers

Answer #1

#include <iostream>
#include <string>
using namespace std;

int main(){
// String holding each name
string word;

// Temp value
string temp;

// Empty vector holding all names from file
vector<string> names;

// Read names from file LineUp.txt
ifstream in(NFLplayers.txt);
if(in.is_good()){
while(in.good()){
getline(in, word);
names.push_back(word);
}
in.close();
}else{
cout << "Unable to open file";
}

int size = names.size();

int i;

// Loop to sort vector name values
for( i = 1 ; i < size ; ++i){
// new value to be inserted into temp location
temp = names.at(i);

// index to the left of i
int k;

// sort names
for(k = i-1; k>=0 && names.at(k) > temp; k--){
names.at(k+1) = names.at(k);
}
names.at(k+1) = temp;
}

// Loop to print names
for (i = 0; i < size; i++)
cout << names.at(i) << endl;

return 0;
}

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
In C++ Create a program that uses only Selection Sort and Insertion Sort for the National...
In C++ Create a program that uses only Selection Sort and Insertion Sort for the National Football League list of current players Inputting data from a text file named "NFLplayers.txt" Only want the name of the player(first name then last name), their team name, and position they play. Example is: Patrick Mahomes, Chiefs, Quarterback Output lists to a text file along with how long it took to go through the Selection Sort and Insertion Sort and how many iterations it...
Answer these questions for the case study: Purple Innovation, Inc.: The Online to Offline Marketing Challenge...
Answer these questions for the case study: Purple Innovation, Inc.: The Online to Offline Marketing Challenge (a) Delineate what marketing data analytics and metrics were used by Purple Innovation, Inc to assess the effectiveness of their marketing actions and marketing campaigns. (There are many.) Within your answer, provide the type of analytics and /or metrics and for each one, and, for each one, an example of specific dollars, numbers, percentages that were provided in the case. (Be sure to include...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary rivals? How will the acquisition of Reebok by Adidas impact the structure of the athletic shoe industry? Is this likely to be favorable or unfavorable for New Balance? 2- What issues does New Balance management need to address? 3-What recommendations would you make to New Balance Management? What does New Balance need to do to continue to be successful? Should management continue to invest...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...