Search for question
Question

In this assignment, you are to use multiple functions and multiple files. If a function is to compute

and return a single value, it can do so using a return statement where you would call the function

using an assignment statement like x = compute (a, b, c) ;. If the function is required to

compute and/or input multiple values, you must pass these values through the parameter list, using

the proper form of parameter passing (deciding when to use & and when not to). The primary purpose

of this assignment is to test your understanding of parameter passing; doing so incorrectly/improperly

(including passing parameters as addresses when this is not necessary) will result in a loss of points

on your grade. Remember strings are already addresses so would not need &.

Your program will predict the outcome of football (American football) games. It will input data of

football teams for upcoming games from file and use this data to compute rankings of the matchup

between the two teams and then use these rankings to compute a predicted score differential (who

wins and by how much). Your program will also maintain running totals for a summary of the number

of teams and the number of home teams predicted to win. Details follow below.

Your program will be broken into functions as described later. In main, declare your variables

(remember in C you have to declare all variables before any executable instruction), initializing any

variables necessary. Open the input file (fopen). Iterate for each game (a game is described by one

row of input in the file) by inputting the data for the game, doing the proper computations, outputting

the result and updating running totals.

Each game, or row of the file, comprises the following values, each separated by a space: home team

name (a string of no more than 20 characters) HTO HTD HTS HTH HTC visiting team name VTO

VTD VTS VTR. These values listed as abbreviations are all int values. These are, in order, home

team (HT) or visiting team (VT) offensive strength (O), defensive strength (D), special teams strength

(S), home strength for the home team (S) or road strength for the visiting team (R) and home field

advantage (C for crowd noise). These values range from 1 (worst) to 10 (best).

Use an input function which will be called from your while loop. The input function will input the

entire line, using a single fscanf to input 11 variables (home team name, HTO, HTD, HTS, HTH,

HTC, visiting team name, VTO, VTD, VTS, VTR, in that order). Do not input the line character-by-

character or as one long string and then parse the results as those approaches involve too much work.

fscanf returns the result of the input (how many items were input, or EOF if you have reached the

end of the file). Use the return value to control the while loop: while (getInput (...) !=EOF)

{...} where getInput uses return fscanf (...);. In this way, getInput returns the int

value returned by the fscanf and the while loop tests this condition to determine whether to

continue iterating or not. If you are confused about this, talk to your instructor./nThere are two separate sets of computation to perform, each in a separate function. First, use the 9

input int values to compute five relative strengths of both teams. These formulas are given on the next

page. These relative strengths are all doubles. Second, take these five strength values and compute

the difference between the home team and visiting team scores. A positive number will mean the

home team wins by that amount and a negative number means the visiting team wins by that amount.

A 0 will be interpreted as the home team winning by 1 point. This is described in more detail later.

The computation function for these five values will require that you pass the computed values as

parameters (note: some students try to avoid this by using global variables, variables declared outside

of the functions, do not do this). Once main receives these five values, it will pass them on to a

second computation function to compute the score difference. As this function returns a single value,

this function can use a return statement (although you can also have the computed value returned

via the parameter the parameter list, your choice). To compute the five strength values, you may but

do not need to call five additional functions, each of which computes and returns one value. This is

unnecessary but could be useful experience.

The five strength values are computed as shown below. This is followed by the computation for the

scoring difference using the five strength values. Italicized items are constants to be declared using

#define statement. All of these constants' values are shown below the computations.

OFFENSIVE_FACTOR - VTD

HTD + 2 - VTO OFFENSIVE_FACTOR

SPECIAL TEAMS_FACTOR - VTS

Home scoring strength = HTO

• Visiting scoring strength =

• Special teams impact = HTS

Home field advantage = HTH +

HTC

HOME_FIELD_ADVANTAGE - VTS

• Visiting road strength = HTO HTD * HTH OVERALL_FACTOR - VTO

* VTD * VTR

difference = Home scoring strength OFFENSIVE WEIGHT +

Visiting scoring strength * DEFENSIVE WEIGHT + Special teams

impact SPECIAL WEIGHT + Home field advantage HOME WEIGHT +

Visiting road strength * OVERALL WEIGHT

*

OFFENSIVE_FACTOR = 1.15

. SPECIAL TEAMS FACTOR 1.22

DEFENSIVE WEIGHT = 0.24

. SPECIAL WEIGHT = 0.17/nYour program will be divided into four files, described below. You may name the files whatever you

like. The names listed here are more to identify what they do.

o main.c: contains #include for your header file and the main function only

o compute.c: contains the computational functions and #include for your header file

o

o io.c: contains your input, output and summary functions along with #include for your

header file (note: that summary does contain two computations but we will consider it I/O)

header.h: #define and #include statements (at a minimum, you need ,

you may want others include ) and your function prototypes (each of which should

be commented, as explained in class); do not #include your header file in your header file;

the only #include in your .c files should be for this header file; the .h file will contain no

code or variables and do not #include any .c files; remember to add #define

_CRT_SECURE_NO_WARNINGS before #include if using Visual Studio

Fig: 1

Fig: 2

Fig: 3