Question: Recall in program # 1 , you controlled your loop using while ( ( c = getc ( fp ) ) ! = EOF )
Recall in program # you controlled your loop using whilecgetcfpEOF 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 mains
while loop, the code looks like whileinputEOF 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 loops 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. The idea is that main is
almost entirely a set of function calls. For instance, do not add to the number of cities in the loop
or use an if statement in the loop to determine if this city is more livable than the previous most
livable. After the loop, you will call the summary function.
Below are the formulas you will use for your various computations. All of the results should be
doubles or floats Keep in mind that population and square mileage are ints so you will need an
appropriate cast in the first equation to force a doublefloat division instead of an int division.
Population density population square mileage.
Pollution rating pollution amount population density
Traffic rating population density major highways
Crime rating crime population density
Expense rating expense population density
Livability Pollution rating Traffic rating Crime rating Expense rating
The values and should all be constants defined using #define.
Do not hardcode any of the numbers in the actual assignment statements aside from Create
useful names for these constants to promote readability in your program. If your names are not
good, provide comments to explain the role of each constant.
Organize your program in separate files as follows:
the main function in a file by itself
the functions from and in an inputoutput file
the functions from and in a computation file
a header file that includes all function prototypes, all #include statements aside from
the #include for your header file and all #define statements; there will be no C code
in your header file and the three c files will only have one #include for your header file
If you are confused about how to write your code, see the example programs on the sample code
website, particularly the payroll and craps examples.
NOTE: in Visual Studio after creating a project, in the right pane in the Solution Explorer window,
expand this and you will find entries for Header Files and Source Files also Resource
Files Right click on Source Files and select Add and then either New Item to create your
header file or Existing Item and add your c files. Load already written files if you have
written them elsewhere. Repeat this for Header Files to create or add your header file into the
project.
Along with this assignment description are two data files, citiestxt and citiestxt Run your
program on citiestxt to compare your results to those shown below. Once you have your program
running correctly, run it on citiestxt copy and paste the output to the bottom of your main.c file.
You do not need to submit your output from citiestxt What follows is my output. You should
get similar numbers and have your output formatted in a readable way although it does not have
to precisely match this version.
City Livability Pop Density
Akron
Cincinnati
Cleveland
Columbus
Dayton
Toledo
Of cities, the average livability is
The most livable city is Cincinnati with a livability of
Remember to comment your code well. Every function should have its own introductory comment
the main introductory comment should be in main.c for mains introduction, along with your
name Also command your prototypes to explain the role of each function you can use the same
comment for each of these as your function intro comments and comment the logic and usage of
variables, etc, like you did or should have for program
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
