This program ensures that you are comfortable with the fundamental concepts from the first few weeks of CS 100. Specifically, you have the ability to read a set of instructions and generate a simple program that can perform the desired calculations. In addition, your program illustrates that you have a good understanding of how to properly construct a C program.
The Task
Write a C program that takes three inputs from the user. These three inputs must be entered in the order shown.
Size of a county in acres, an integer value. For example, the size of Tuscaloosa county is 864,600 acres.
Amount of rainfall received in inches, a real (double) value.
Percent of the county that received this rainfail, an integer value.
You may assume that all input entered is legal input and of the proper type. For example, You will never see a negative rainfall amount or the number of acres in a county that is a real number or a percentage that is less than zero or greater than 100.
Given these three inputs, your program should calculate and output the following three values:
The number of gallons of rain that fell on the county
The weight of this rain, in tons
The height of this water (in miles) if you poured it into a rectangle the size of a college football field. Recall that the playing surface for a college field is 120 yards (360 feet) by 53 and one-third yards (160 feet).
You may print additional values if you wish, but you must have these three values. Print the values in this order, each on a separate line, and identify what each value is.
Your program must use various conversion factors in order to generate this output. The values below might assist in your development efforts. If you are using any of these conversions, please use the precision shown below so that your answers are consistent with the expected output.
One acre is 43,560 square feet
One acre is 4840 square yards
One acre is 4046.85642 square meters
Gallons in a cubic foot = 7.48052
Gallons in a cubic yard = 201.974026
Gallons in a cubic meter = 264.172
One gallon weighs 8.3430 pounds
Where to Start
The first thing you should do is figure out how to solve the problem by hand. You can use the example of one inch of rain falling on all of Tuscaloosa County. The three inputs for this problem would be 864000 1.0 100 Check the Piazza discussion board if you want to confirm what the answer should be for this data set.
Next, set up a directory in which you will work. Run the following commands:
cd cs100
mkdir projects
cd projects
mkdir project0
cd project0
Name your program rain.c. Write the code necessary to read in the three input values and perform the required calculations. Print each of your answers (gallons, weight in tons, and height of the water on a football field) on a separate line.
Compliance Instructions
Compile your program, naming the executable rain. Make sure to use the -Wall option when compiling. Please note that you should have zero warnings in your compile. Points will be deducted for programs that compile yet generate warning messages.
You must have at least three functions in your program. At a minimum, we expect to see functions for the following tasks. You may define additional functions if you wish.
A function that reads an integer and returns the integer value to the calling routine. This function should take a character string as its one argument. Print that character string as user's prompt before reading the integer value. Call this function readInteger.
A function that reads a double and returns the double value to the calling routine. This function should take a character string as its one argument. Print that character string as user's prompt before reading the double value. Call this function readDouble.
A function that calculates the number of gallons of rain received. It takes three arguments (the number of acres in the county, the amount of rainfall received, and the percent of the county that received rain) and returns a double representing the number of gallons of rain. Make sure you give this function a meaningful (descriptive) name.
Generate a file named test.dat that contains a set of sample test data. It cannot be the same test data referenced above (864600 and 1.0 and 100). This is a set of test data that you have used to check your program. Recall that you can use this test data with your program via the command cat test.dat | ./rain
While the list below is not exhaustive, you will lose points on this assignment if:
Your program does not compile (loss of 90 percent of the possible points).
There is not a header block of comments at the start of your program explaining what it does.
There are not comments scattered throughout the program explaining the various operations.
You do not submit a test.dat file with test data that you used.
The program fails on one or more of the test data sets that we use in grading.
You do not follow the Style Guide found on the CS 100 website.
Checking Your Program
Before submitting your project, use FileZilla to move your project0 directory to cs-intro.ua.edu and then log into cs-intro to confirm your program is working properly on that system.
There are three test data sets on cs-intro that you can use to check your program, /home/instructor/p0data1.txt through /home/instructor/p0data3.txt (where instructor is one of cordes, mbrown or jzhang).
We urge you to use Piazza to confirm your answers. We encourage students to check other answers to confirm their correctness. Do not post any code, but posts such as the following are encouraged. Using 864,600 acres and 1.5 inches of rain on 85 percent of the county gave me an answer of xxx gallons. Do people agree?
Submission Instructions
When you are ready to submit your project, change to the project0 directory containing your assignment. Do an ls command. You should see something like this:
rain rain.c test.dat
Extra files are OK.
To submit your project, use either Windows Explorer (PC) or Finder (Mac) to find your project0 directory. Right click on the directory and compress this directory. For Windows, right click on the directory and then select Send to a compressed file. On a Mac, use a secondary click on the directory and select Compress filename.
Due Date
This project is due at 5:00pm on Friday, September 18. There are no late projects accepted.
This project is due at 5:00pm on Friday, September 18. There are no late projects accepted.
Sounds like you should have started sooner. We don't do peoples' homework here, but we do help people. It looks your instructor provided very thorough instructions, where exactly are you stuck? What have you done?