Question: I need help adding the following functions to my completed code in C++. I have also included my code and the txt file needed to

I need help adding the following functions to my completed code in C++. I have also included my code and the txt file needed to run the program.

The program needs to include the following functions:

  1. Sort by quarterback's last name in ascending order
  2. Sort by quarterback rating in descending order
  3. Add a new quarterback using keyboard input. This updates the array of structs and adds one to the number of quarterback
  4. Save the quarterback information from the array of structs to the data file
  5. Call these functions in the main driver and have them function correctly

My Code: #include #include #include using namespace std;

struct quarterback { string firstname, lastname; int attempts, completions, yards_passing, touchdowns, interceptions; }; int readData(ifstream &inFile, quarterback *array); double computePercentage(quarterback qb); double quarterbackRating(quarterback qb); void displayData(quarterback array[], int count);

int main() { string filename="football-in.txt"; ifstream infile(filename.c_str()); quarterback array[100]; int count=readData(infile,array); infile.close(); displayData(array,count); return 0; } //////FUNCTION: readData // purpose: read data from a file named "football-in.txt

// Incoming:data from the file /// Outgoing: nothing // Return: nothing int readData(ifstream &infile, quarterback *array) { string input; int index=0; while(infile>>input) { quarterback qb; qb.firstname=input; infile>> qb.lastname >> qb.attempts >> qb.completions >> qb.yards_passing >> qb.touchdowns >> qb.interceptions; array[index]=qb; index++; } return index; }

//////FUNCTION: computePercentage // purpose: compute the quarteback percentage by dividing completions by attempts // Incoming: qb.attempts, qb.completions, qb.attempts /// Outgoing: nothing // Return: percentage double computePercentage(quarterback qb) { double percent=0; if(qb.attempts>0) { percent=(double)qb.completions/qb.attempts; } return percent; }

//////FUNCTION: quarterbackRating // purpose:compute the quarterback rating using the formula // Incoming:qb.completetions, yards-passing, touchdowns, attempts, interceptions /// Outgoing: nothing // Return: quarterback rating double quarterbackRating(quarterback qb) { if(qb.attempts==0) { return 0; } double rating=0; rating=(double)(3.0*qb.completions+qb.yards_passing+10*qb.touchdowns)/(qb.attempts+8*qb.interceptions); return rating; }

//////FUNCTION: displayData // purpose: send data to the screen and format it // Incoming:data from the file /// Outgoing: nothing // Return: nothing void displayData(quarterback array[], int count) { cout<

txt file: "football-in.txt"

Dan

Marino

22 14 219 2 2

Terry

Bradshaw

33 21 302 1 0

Roger

Staubach

24 12 244 0 1

thanks in advance

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!