Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program that has at least two functions that can be called to calculat

ID: 3911030 • Letter: W

Question

Write a C program that has at least two functions that can be called to calculate defensive and offensive statistics. Return the calculated statistical information within a structure. Call these functions from a main function using the example information below. Don't prompt for any values.

Defense team:

Shots on Goal = 5

Goals Scored = 2

Games won in Goal = 1

Games Lost in Goal = 1

Offense Team:

Scoring Attempts (shots on goal) = 7

Goals Scored = 3

Team Games Won = 3

Team Games Lost = 4

These combinations of formulas below can be used to determine the Defense and Offense statistics.

Defense

Goalie Games Won Percentage = Games Won / (Games Won + Games Lost)

Goalie Saves = Shots on Goal - Goal Scored

Saves Percentage = Goalie Saves / Shots on Goal

Saves Ratio = Shots On Goal / Goalie Saves

Offense

Scoring Percentage = (Scoring Attempts - Goals Scored) / Scoring Attempts

Scoring Ratio = Shots On Goal / Goals Scored

Games Won Percentage = Team Games Won / (Team Games Won + Team Games Lost)

Explanation / Answer

As per the definitions given above here is the code to create and return the defensive and offensive statistics structures. All the explanations are given as comments. Here the datatype for percentages and ratios is float. Finally the output is printed from the structures.

Just paste this in file.cpp and compile and run it.

#include<stdio.h>

//Structure to store the defence statistics with relevant variable types

struct defence{

float won_percentage;

int goalie_saves;

float saves_percentage;

float saves_ratio;

};

//Structure to store the offence statistics with relevant variable types. Used float because they all are ratios and percentages.

struct offence{

float scoring_percentage;

float scoring_ratio;

float games_won_percentage;

};

//Function to calculate defensive statistics according to the given information and returning the structure

struct defence calculate_defensive_statistics(int def_shots_on_goal,int def_goal_scored,int def_games_won_in_goal,int def_games_lost_in_goal)

{

struct defence temp;

temp.won_percentage = (float)def_games_won_in_goal/(def_games_won_in_goal+def_games_lost_in_goal);

temp.goalie_saves = def_shots_on_goal - def_goal_scored;

temp.saves_percentage = (float)temp.goalie_saves/def_shots_on_goal;

temp.saves_ratio = (float)def_shots_on_goal/temp.goalie_saves;

return temp;

}

//Function to calculate offensive statistics according to the given information and returning the structure

struct offence calculate_offensive_statistics(int off_shots_on_goal,int off_goal_scored,int off_games_won,int off_games_lost)

{

struct offence temp;

temp.scoring_percentage = (float)(off_shots_on_goal - off_goal_scored)/off_shots_on_goal;

temp.scoring_ratio = (float) off_shots_on_goal/off_goal_scored;

temp.games_won_percentage = (float)off_games_won/(off_games_won+off_games_lost);

return temp;

}

int main()

{

int def_shots_on_goal = 5,def_goal_scored = 2,def_games_won_in_goal = 1, def_games_lost_in_goal=1;

int off_shots_on_goal = 7,off_goal_scored = 3,off_games_won = 3, off_games_lost = 4;

//Calling the functions

struct defence temp1 = calculate_defensive_statistics(def_shots_on_goal,def_goal_scored,def_games_won_in_goal,def_games_lost_in_goal);

struct offence temp2 = calculate_offensive_statistics(off_shots_on_goal,off_goal_scored,off_games_won,off_games_lost);

//Printing the outputs called from above

printf("Defensive Statistics: ");

printf("Won Percentage: %f Goalie_saves: %d Saves Percentage: %f Saves Ratio: %f",temp1.won_percentage,temp1.goalie_saves,temp1.saves_percentage,temp1.saves_ratio);

printf(" Offensive Statistics: ");

printf("scoring_percentage: %f scoring_ratio: %f games_won_percentage: %f ",temp2.scoring_percentage,temp2.scoring_ratio,temp2.games_won_percentage);

}

Hope this helps.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote