Question: This assignment will test your ability to write a C program that is made up of functions stored in different files. The main point for
This assignment will test your ability to write a C program that is made up of functions stored in
different files. The main point for this assignment is to demonstrate proper parameter passing. You
have to decide what parameters should be passed by copy versus passed as addresses, properly
dereferencing those parameters in your functions. Incorrect parameter passing or a lack of
demonstration that you know how to pass parameters properly will result in a low grade.
This program will compute city livability ratings based on various statistics. The input will come
from a text file. You will call an input function to read one city's information at one time from file,
using fscanf. After input, you will call various functions to perform computations on that city
to assign the city a rating. An output function will output to the console window the city's name,
rating and population density. An update function will keep track of values used to compute and
output the most livable city and the average city ranking.
Your program must be broken into the following functions. Each function, aside from main, will
be called from main. You must pass parameters appropriately.
main declare your variables, open the input text file, enter a while loop to call various
functions which will input one city's worth of data, compute various city ratings, compute
the city's livability, output the results and update running totals. After the loop, close the
input file and call a function to output summary information.
input this function will receive the FILE variable from main and use fscanf to input
a city's information. The information is in order, city name, population, square mileage,
pollution, crime, expense, number of highways; all values are ints except city name string
As you need to get all the input values back to main, the parameters must all be passed
appropriately. To control the while loop in main, return the result of fscanf which will
be the number of values successfully input This result will be EOF upon reaching the end
of file. This is described more completely below.
population density this function will receive the city's population and square mileage,
compute and return the population density a double or float This is one of two functions
that computes and returns a single value so you can return the computed value through a
return statement rather than as a parameter if desired.
compute this function uses the int values input for pollution, crime, expense and number
of highways plus the computed population density to compute four ratings: pollution rating,
traffic rating, crime per capita, expense per capita. As this function has to return four
values, you must pass these as parameters. The equations for these computations are given
on the next page.
livability compute and return the city's livability; as with population density, this is a
single computation that can but does not have to be returned via a return statement.
The equation for livability is given on the next page.
output output this city's name, livability value and population density, in a formatted
way. See the example output at the end of the assignment. All output must line up in
columns as shown.
update update running totals to be used in the summary function. Specifically, add to
the number of cities, add this city's livability to a total livability and determine if this city's
livability is the best so far by comparing it to the previous best city's livability. If this is the best so far, remember both this city's livability and its name. To remember the name,
copy this city's name a string into a string to store the best city's name. This should be
done using strcpy from string.h The instruction is strcpydestination
source; where destination and source are the two string variables. As multiple
variables are being updated, this function must return the changed or possibly changed
values through the parameter list.
summary compute the average livability rating total livability number of cities and
output the number of cities, the average livability and the city with the highest livability
along with its livability value.
Recall in program # you controlled your loop using while cgetc fpEOF In this
assignment, you will control your while loop in the same way but rather than calling getc, you
will call your own input function. That function will return the result of fscanf, which itself will
be the number of inputs. This value is EOF if you have reached the end of the file. From main's
while loop, the code looks like while input EOF where is the parameter
list. You will have to figure out how to pass these parameters. One of the parameters will be your
FILE variable.The while loop's body will contain all of your function calls to the various computation functions,output and update. DO NOT include any other code in the loop body
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
