Академический Документы
Профессиональный Документы
Культура Документы
5.0
10.0
6.3
To input this data you'll have to declare a file input stream pointer, assign it to your input file and
read the data from the file until you reach the EOF. You'll most likely want to use the fscanf
function for this read. The structure of this statement would look like below
fscanf(spInput, "%d %f", &loop_counter, &rad);
You will need to loop again to print the output but, rather than loop for a set number of times,
you'll need to loop over the number of rows of data in the input file. For example, for the input file
above you would still loop and print output for three circles, but that would be driven by the
number of rows in the input file rather than a hard coded counter variable.
When you open the input file make sure you check that the file opened correctly and the stream
point is properly created. You might use a statement like the following to accomplish this:
if ((spInput = fopen("input.txt", "r") == NULL)
printf("Could not open input file!\n");
Also notice that we are opening this file in read mode ("r").
Continue using the if else statement from your last assignment inside the loop. However
generalize the statement so that it will work for all radii. It should have the following form:
// Calculate and print circumference and area for the circle.
printf("Circle %d radius: \t\t%6.2f\n", loop_counter, rad);
if (rad == 5)
{
printf("Circle %d circum: \t\t%6.2f\n", loop_counter, calcCircum(rad));
printf("Circle %d area:
\t\tNot Calculated\n\n", loop_counter);
}
else if (rad == 10)
{
printf("Circle %d circum: \t\tNot Calculated\n", loop_counter);
printf("Circle %d area:
\t\t%6.2f\n\n", loop_counter, calcArea(rad));
}
else
{
printf("Circle %d circum: \t\tNot Calculated\n", loop_counter);
printf("Circle %d area:
\t\tNot Calculated\n\n", loop_counter);
}
Please note you will only need to include one such if statement because it is generalized
to work for all loops.
Your name
xx000012345
xx@ltu.edu
Name of Program.c
MM-DD-YY
The Instructors description of the programming
The Students description of how the program works
I have neither given nor received unauthorized aid in
completing this work, nor have I presented someone
work as my own!