NFL passer rate

QUESTION

NFL Passer Rating Calculator

Filename: passrate.cpp 

This program will calculate the NFL passer rating for 2 quarterbacks using the real 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. The program will then allow the user to repeat this process, if they choose.

Your program should do the following:

  • Welcome the user as seen in the sample runs below.
  • Ask the user for Player A’s statistics , then ask the user for Player B’s statistics. (See sample runs).
    • 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.
    • You do NOT have to account for impossible stat entries: example: 0 passing attempts and 10 touchdowns? How’s that possible?
    • You do not have to account for other impossibilities like -20 passing yards.
    • You also may assume that at least onepair of players will be analyzed. 
  • Calculate the passer rating for each Quarterback by passing in the statistics for each player to the getPasserRating function. The return value from this function should be the the rating for that Quarterback.
  • 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.3 or more. It will help you to here to check if the passer rating is >= 158.3, not just == 158.3
  • All NFL Passer Ratings should be printed to 1 decimal place.
  • Ask the user if they would like to repeat the process, and enter another pair of QB’s to evaluate. 
    • If they select Y or y, restart the process (the loop) of asking for player A and B’s stats, and calculate their ratings again.
    • If they select N or n, print out how many pairs of QB’s were analyzed, and allow the program to exit.
      • Notice, if ONE PAIR of QBs was analyzed, your output should read “You compared 1 pair of players”.
      • If you analyze more than one pair of players, make sure your output reads: “You compared 2 pairs of players”.
    • If they give an invalid character option here, print an error message and allow the program to exit.

Required Functions:    

1) welcomeMessage

  • Write a function named welcomeMessage
  • This function should take in no parameters
  • This function should return no data back to where it was called. 
  • The job of this function is solely to print out the welcome message and information about what a perfect passer rating requires:
Welcome to the NFL Quarterback Passer Rating Calculator!
A perfect passer rating (158.3) requires at least:
77.5% completion percentage
12.5 yards per attempt
11.875% touchdown % per attempt
No interceptions
  • Call this before you begin your overall loop asking for player stats.

2) getPasserRating

  • Write a function named getPasserRating
  • This function should take in the 5 pieces of data required to calculate the passer rating as its parameters.
  • This functions’ job is to calculate and return the passer rating back to main() as a double.
  • You’ll be calling this function at least twice within your loop, once for each QB.
  • 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, passing in QB1’s stats for the first call and QB2’s stats the second.
  • This function should not do anything other than calculate and return back the passer rating of one quarterback based on the parameters that were sent in. 
  • NO COUT or CIN should occur from within this function. That all happens in main() and within your welcomeMessage function.

NFL Passer Rating Calculation:

a=left({{text{COMP}} over {text{ATT}}}-.3right)times 5

{displaystyle b=left({{text{YDS}} over {text{ATT}}}-3right)times 0.25}

c=left({{text{TD}} over {text{ATT}}}right)times 20

d=2.375-left({{text{INT}} over {text{ATT}}}times 25right)

where

ATT = Number of passing attemptsCOMP = Number of completionsYDS = Passing yardsTD = Touchdown passesINT = Interceptions

Then,

If the result of any individual calculation (a,b,c,d) is greater than 2.375, it is set to 2.375.
If the result of any individual calculation (a,b,c,d) is a negative number, it is set to zero.

Then,

complete the passer rating calculation:

{text{Passer Rating}}=left({a+b+c+d over 6}right)times 100

  • 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. Your wording can differ a bit. 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!
A perfect passer rating (158.3) requires at least:
77.5% completion percentage
12.5 yards per attempt
11.875% touchdown % per attempt
No interceptions

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.

Would you like to compare another pair of players? (Y or N): n
You compared 1 pair of players.

Sample run 2

Welcome to the NFL Quarterback Passer Rating Calculator!
A perfect passer rating (158.3) requires at least:
77.5% completion percentage
12.5 yards per attempt
11.875% touchdown % per attempt
No interceptions

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.

Would you like to compare another pair of players? (Y or N): Y

Enter single game information for Player A:
Attempts: 5
Completions: 5
Passing Yards: 5
Touchdowns: 5
Interceptions: 5

Enter single game information for Player B:
Attempts: 4
Completions: 4
Passing Yards: 4
Touchdowns: 4
Interceptions: 4

Player A's single game passer rating: 79.2
Player B's single game passer rating: 79.2
Player A and B have the same rating!

Would you like to compare another pair of players? (Y or N): N
You compared 2 pairs of players.

Sample run 3

Welcome to the NFL Quarterback Passer Rating Calculator!
A perfect passer rating (158.3) requires at least:
77.5% completion percentage
12.5 yards per attempt
11.875% touchdown % per attempt
No interceptions

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

Would you like to compare another pair of players? (Y or N): n
You compared 1 pair of players.

Sample run 4

Welcome to the NFL Quarterback Passer Rating Calculator!
A perfect passer rating (158.3) requires at least:
77.5% completion percentage
12.5 yards per attempt
11.875% touchdown % per attempt
No interceptions

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!

Would you like to compare another pair of players? (Y or N): n
You compared 1 pair of players.

Sample run 5

Welcome to the NFL Quarterback Passer Rating Calculator!
A perfect passer rating (158.3) requires at least:
77.5% completion percentage
12.5 yards per attempt
11.875% touchdown % per attempt
No interceptions

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.

Would you like to compare another pair of players? (Y or N): Z
Invalid entry. Exiting program...

Sample run 6

Welcome to the NFL Quarterback Passer Rating Calculator!
A perfect passer rating (158.3) requires at least:
77.5% completion percentage
12.5 yards per attempt
11.875% touchdown % per attempt
No interceptions

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!

Would you like to compare another pair of players? (Y or N): n
You compared 1 pair of players.

Sample Run 7

Welcome to the NFL Quarterback Passer Rating Calculator!
A perfect passer rating (158.3) requires at least:
77.5% completion percentage
12.5 yards per attempt
11.875% touchdown % per attempt
No interceptions

Enter single game information for Player A:
Attempts: 10
Completions: 10
Passing Yards: 200
Touchdowns: 3
Interceptions: 0

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: 158.3
Player B's single game passer rating: 158.3
Player A and B have the same rating!

Player A had a PERFECT passer rating.
Player B had a PERFECT passer rating.

Would you like to compare another pair of players? (Y or N): n
You compared 1 pair of players.

Get your college paper done by experts

Do my question How much will it cost?

Place an order in 3 easy steps. Takes less than 5 mins.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *