Question

In C++: PART 2 -- Write a program that reads the following data file of NFL...

In C++:

PART 2 -- Write a program that reads the following data file of NFL quarterbacks,
and...
create a data structure to represent the data (dob, name, wins, losses, and salary)
create an analysis class that will contain the list or vector of quarterbacks,
and will analyze it as follows:

print out the list of quarterbacks (from highest to lowest salary, AND from most
wins to least wins). NOTE, there may be more than one least or one most.
and decide who is the highest paid quarterback, and
and decide who is the lowest paid quarterback.


quarterbacks.txt
----------------
11 15 1980 Aaron Rodgers 198 20 34000000
10 22 1979 Matt Ryan 193 35 28000000
8 4 1977 Drew Brees 191 27 29000000
4 7 1975 Russell Wilson 195 23 27000000
7 4 1978 Eli Manning 191 28 28000000

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

If you have any doubts, please give me comment...

#include <iostream>

#include <fstream>

#include <vector>

#include <string>

using namespace std;

struct quarterback

{

    int dob_month;

    int dob_day;

    int dob_year;

    string fname;

    string lname;

    int wins;

    int losses;

    long salary;

};

int main()

{

    vector<quarterback> data;

    ifstream inFile;

    inFile.open("quarterbacks.txt");

    if (inFile.fail())

    {

        cout << "Unable to open file" << endl;

        return -1;

    }

    quarterback temp;

    while (!inFile.eof())

    {

        inFile >> temp.dob_month >> temp.dob_day >> temp.dob_year >> temp.fname >> temp.lname >> temp.wins >> temp.losses >> temp.salary;

        data.push_back(temp);

    }

    inFile.close();

    int size = data.size();

    for (int i = 0; i < size; i++)

    {

        for (int j = i + 1; j < size; j++)

        {

            if (data[i].salary < data[j].salary || (data[i].salary == data[j].salary && data[i].wins < data[j].wins))

            {

                temp = data[i];

                data[i] = data[j];

                data[j] = temp;

            }

        }

    }

    cout<<"List of quarterbacks is: "<<endl;

    for(int i=0; i<size; i++){

        cout<<data[i].dob_day<<"/"<<data[i].dob_month<<"/"<<data[i].dob_year<<"\t"<<data[i].fname<<", "<<data[i].lname<<"\t"<<data[i].wins<<"\t"<<data[i].losses<<"\t"<<data[i].salary<<endl;

    }

    cout<<"\nHighest paid quarter back is "<<data[0].fname<<", "<<data[0].lname<<endl;

    cout<<"Lowest paid quarter back is "<<data[size-1].fname<<", "<<data[size-1].lname<<endl;

    return 0;

}

Add a comment
Know the answer?
Add Answer to:
In C++: PART 2 -- Write a program that reads the following data file of NFL...
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
  • Using MiniTab, create a Probablity Prob Graph with this: TABLE 6E.6 2008 NFL Quarterback Rating Data Yards per Rati...

    Using MiniTab, create a Probablity Prob Graph with this: TABLE 6E.6 2008 NFL Quarterback Rating Data Yards per Rating Team AttemptPoints Player 105.5 SD 8.39 Philip Rivers ChadPennington MIA 7.67 97.4 7.66 96.9 Kurt Warner ARI NO 7.98 96.2 Drew Brees 95 7.21 Peyton Manning IND 7.53 93.8 Aaron Rodgers GB HOU 8.01 92.7 Tuat DAL766 Jeff Garcia 7.21 90.2 NE blat 7.16 89.4 Matt Ryan 7.93 87.7 haun 7.10 87.5 Seneca Wallace 6.33 NYG6.76 86.4 Manning Donovan McNabb 6.86...

  • The following table presents data on the ratings of quarterbacks for the 2008 National Football League...

    The following table presents data on the ratings of quarterbacks for the 2008 National Football League season (The Sports Network) Player Team Yards per Attempt Rating Points Philip 8.39 105.5 Rivers SD MIA 7.67 97.4 Chad Pennington 7.66 Warner 96.9 Kurt ARI 7.98 Drew Brees NO 96.2 7.21 Peyton Manning IND 95.0 Rodgers GB 7.53 Aaron 93.8 Matt Schaub 8.01 92.7 HOU Tony 91.4 7.66 Romo DAL Garcia 7.21 90.2 Jeff ТВ 89.4 Cassel 7.16 Matt NE ATL 7.93 Matt...

  • Write a program that will accept from the user a text file containing hurricane data along...

    Write a program that will accept from the user a text file containing hurricane data along with an output filename. The data consists of the year, the number of storms, the number of hurricanes, and the damage in millions of US Dollars. The first line contains the word “Years” followed by the first year listed and the last year listed separated by tabs. The following lines contain the data separated by tabs. A sample text file is available in this...

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