Question: C++ Include cmath and absolute value Make sure the formula goes with the samples. Write a formula used in the National Football League. The program
C++
Include cmath and absolute value
Make sure the formula goes with the samples.
Write a formula used in the National Football League. The program will display the passer rating for each quarterback, and then prints a message detailing who's rating was the best, and what the difference between the ratings was.
Your program should do the following:
Welcome the user as seen in the sample runs below.
Ask the user for Player A's statistics
Ask the user for Player B's statistics
The 5 statistics needed to calculate a passer rating are: Passing Attempts, Passing Completions, Passing Yards, Touchdowns, and Interceptions.
This part will feel a bit long with the cout/cin queries to the user, but it is necessary for our program.
You may assume all of these user entries are valid integer values.
Calculate the passer rating for each Player by passing in the statistics for each player to the getPasserRatingfunction you'll write in addition to main()
Determine whether Player A or Player B had a better game (who's passer rating is better), and print the difference between the two ratings (note: the difference should never print as a negative value).
Print the message "Player X had a perfect passer rating!" if either of the players passer ratings are 158.33 or more.
All NFL Passer Ratings should be printed to 1 decimal place.
Function: getPasserRating
Write a function named getPasserRating.
This function should take in the 5 pieces of data required to calculate the passer rating as parameters.
This functions' job is to calculate and return the passer rating back to main() as a double.
Note that this function calculates the passer rating for ONE QUARTERBACK at a time. That means, if you want to calculate the rating for TWO quarterbacks, you'll have to call this function two times, once for each quarterback's statistics.
Make sure you have both a declaration (one line above main()) and a definition (the chunk/block of code that actually defines how the function runs) in your code for full points.
This function should not do anything other than calculate and return the passer rating of one quarterback, based on the parameters sent in.
NO COUT or CIN should occur from within this function. That all happens in main().
NFL Passer Rating Calculation:
a = (comp/att - .3) *5
b= (yds/ATT -3) * 0.25
c= (yds/ATT) * 20
d= 2.375 - (INT/ATT *25)
ATT = Number of passing attempts
COMP = Number of completions
YDS = Passing yards
TD = Touchdown passes
INT = Interceptions
If the result of any calculation is greater than 2.375, it is set to 2.375.
If the result is a negative number, it is set to zero.
If any are negative, set it to 0.
Then, the above calculations are used to complete the passer rating:
Passer Rating (a+b+c+d/6) * 100
Make sure to see the special conditions above... if the result of a, b, c, or d is greater than 2.375, set it to 2.375. If any are negative, set it to 0.
For this assignment, you can use the variable names a, b, c, d while doing your calculations for passer rating as shown in the formulas above.
Sample Runs
(user input is underlined, to distinguish it from output) Remember your output format should look EXACTLY like mine. For this assignment, if you'd like to change the player names from Player A and Player B, that's fine. You can have fun with those names.
Sample run 1
Welcome to the NFL Quarterback Passer Rating Calculator!
Enter single game information for Player A:
Attempts: 1
Completions: 0
Passing Yards: 0
Touchdowns: 0
Interceptions: 1
Enter single game information for Player B:
Attempts: 10
Completions: 10
Passing Yards: 200
Touchdowns: 3
Interceptions: 0
Player A's single game passer rating: 0.0
Player B's single game passer rating: 158.3
Player B was better than Player A by a difference of 158.3
Player B had a PERFECT passer rating.
Sample run 2
Welcome to the NFL Quarterback Passer Rating Calculator!
Enter single game information for Player A:
Attempts: 15
Completions: 14
Passing Yards: 250
Touchdowns: 3
Interceptions: 0
Enter single game information for Player B:
Attempts: 30
Completions: 25
Passing Yards: 310
Touchdowns: 3
Interceptions: 1
Player A's single game passer rating: 158.3
Player B's single game passer rating: 129.2
Player A was better than Player B by a difference of 29.2
Player A had a PERFECT passer rating.
Sample run 3
Welcome to the NFL Quarterback Passer Rating Calculator!
Enter single game information for Player A:
Attempts: 35
Completions: 29
Passing Yards: 295
Touchdowns: 3
Interceptions: 1
Enter single game information for Player B:
Attempts: 25
Completions: 18
Passing Yards: 195
Touchdowns: 2
Interceptions: 0
Player A's single game passer rating: 118.5
Player B's single game passer rating: 121.3
Player B was better than Player A by a difference of 2.8
Sample run 4
Welcome to the NFL Quarterback Passer Rating Calculator!
Enter single game information for Player A:
Attempts: 0
Completions: 0
Passing Yards: 0
Touchdowns: 0
Interceptions: 0
Enter single game information for Player B:
Attempts: 1
Completions: 0
Passing Yards: 0
Touchdowns: 0
Interceptions: 1
Player A's single game passer rating: 0.0
Player B's single game passer rating: 0.0
Player A and B have the same rating!
Sample run 5
Welcome to the NFL Quarterback Passer Rating Calculator!
Enter single game information for Player A:
Attempts: 29
Completions: 23
Passing Yards: 285
Touchdowns: 3
Interceptions: 2
Enter single game information for Player B:
Attempts: 1
Completions: 1
Passing Yards: 15
Touchdowns: 1
Interceptions: 0
Player A's single game passer rating: 113.4
Player B's single game passer rating: 158.3
Player B was better than Player A by a difference of 45.0
Player B had a PERFECT passer rating.
Sample run 6
Welcome to the NFL Quarterback Passer Rating Calculator!
Enter single game information for Player A:
Attempts: 1
Completions: 1
Passing Yards: 10
Touchdowns: 1
Interceptions: 0
Enter single game information for Player B:
Attempts: 1
Completions: 1
Passing Yards: 10
Touchdowns: 1
Interceptions: 0
Player A's single game passer rating: 147.9
Player B's single game passer rating: 147.9
Player A and B have the same rating!
Program Requirements/Rules
You may ONLY HAVE ONE return statement in each function (this includes main()).
Functions that you write in our course assignments should have BOTH a declaration and a definition.
No global variables
All input and output must be done with streams, using the library iostream
You may only use the iostream, iomanip, and cmath libraries
This program will calculate the NFL passer rating for 2 quarterbacks using the real.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
