Question: Recall in program # 1 , you controlled your loop using while ( ( c = getc ( fp ) ) ! = EOF )

Recall in program #1, you controlled your loop using while((c=getc(fp))!=EOF). 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 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 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 1 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 double/float division instead of an int division.
Population density = population / square mileage.
Pollution rating = pollution amount * population density /1112.2
Traffic rating = population density *1.7/ major highways
Crime rating = crime * population density /872.6
Expense rating = expense * population density /1617.1
Livability =100(Pollution rating + Traffic rating + Crime rating + Expense rating)/
13.81
The values 1112.2,1.7,872.6,1617 and 13.81 should all be constants defined using #define.
Do not hardcode any of the numbers in the actual assignment statements (aside from 100). 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:
1. the main function in a file by itself
2. the functions from 2,6 and 8 in an input_output file
3. the functions from 3,4,5 and 7 in a computation file
4. 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, cities1.txt and cities2.txt. Run your
program on cities1.txt to compare your results to those shown below. Once you have your program
running correctly, run it on cities2.txt, copy and paste the output to the bottom of your main.c file.
You do not need to submit your output from cities1.txt. 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 66.42389.14
Cincinnati 71.77449.88
Cleveland 52.67660.58
Columbus 51.29709.69
Dayton 65.77532.97
Toledo 60.64427.23
Of 6 cities, the average livability is 61.43
The most livable city is Cincinnati with a livability of 71.77
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 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!