Question: Write a program dealing with cylinders to compute the top area and the volume using an input data file and an output file. /* Figure

Write a program dealing with cylinders to compute the top area and the volume using an input data file and an output file.

/* Figure the area of the top of a cylinder */ /* and the volume of a cylinder */

#include #include #include

//#define FILE_IN "lab4.dat" #define FILE_IN "lab4sample.dat"

int main(void) { printf("Error on opening the input file "); printf("Error on opening the output file ");

fprintf(data_out, " Cyl. ");

fprintf(data_out, " Cylinder %1d", count); fprintf(data_out, " The radius is: %9.3f", radius); fprintf(data_out, " The height is: %9.3f", height); fprintf(data_out, " The top area is: %9.3f", area); fprintf(data_out, " The volume is: %9.3f ", vol); count++; fprintf(data_out, " ");

}

Write a program dealing with cylinders to compute the top area and

lab4sample.dat x 5.0 2 40.0 lab4.dat x 2.0 15.0 lab4sample.dat x lab4.dat X i 4.0 3.0 7.0 14.5 3 30.0 2.0 30.0 10.0 Ln: 3 Col: 1 Sel: 010 Unix (LF) UTF-8 INS Ln: 1 Col: 1 Sel: 010 Windows (CRLF) UTF-8 INS INPUT/OUTPUT DESCRIPTION: The test data will be a file called lab4sample.dat. Use it to verify the correctness of your program. It has only two sets of data. The final data will be a file called lab4.dat. It has 4 sets of data. Each line or record of the file will consist of two numbers: the radius and the height of the cylinder. Use an fscanf statement in a while loop to repeatedly get each set of values. The output will be a file, lab4.out. The output of the sample data will be a model to follow. FORMULAS The area of the top of the cylinder = M PL* radius * radius The volume of the cylinder = M_PL * radius * radius * height VIEWING OUTPUT When you run the program, the whole thing is going to lab4.out. Open that file to see your output. ALGORITHM DEVELOPMENT: Open the data file lab4sample.dat or lab4.dat Do the appropriate error checking Open the output file lab4.out Do the appropriate error checking Print your name and assignment (use fprintf) Set the count to one while ((fscanf(..., &radius, &height)) == 2) //Fill in the details for the "..." | Compute the area and volume of the cylinder. print the cylinder count, radius, height, area, and volume as in the Defined Output Appearance. |_ Increment count by one Close the two files Note: All numeric variables are to be type double, except for the type int variable count. The input file name, which will be changed, ought to be in a #define statement. The file will come with two #define statements, for the test file and the final file. Just move the // from in front of one #define statement to the other #define statement. The fprintf statements use variable names. Make variable names agree....or change the variable names in fprintf statements. The file pointer name also needs to agree... FOR THE VALUE OF PI, use M_PI from math.h (which we already have included). DEFINED OUTPUT APPEARANCE (using lab4sample.out): Cylinder 1 The radius is: 5.000 The height is: 2.000 The top area is: 78.540 The volume is: 157.080 Cylinder 2 The radius is: The height is: The top area is: The volume is: 40.000 15.000 5026.548 75398.224 DATA FILES: There are two data files: lab4sample.dat - Use it to verify the correctness of your program. It has two sets of data. lab4.dat - It has 4 sets of data

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 Databases Questions!