Question: ------------------------------------------------ Lab 5.c /* LAB 5, functions that return more than one value */ /* Given the radius, find the area and the circumference */

 ------------------------------------------------ Lab 5.c /* LAB 5, functions that "return" more thanone value */ /* Given the radius, find the area and thecircumference */ /* of a circle */ #include "lab5.h" int main(void) {double radius; /* radius of a circle */ double area; /* areaof the circle */ double cir; /* circumference of the circle */FILE * data_in; /* input file pointer */ FILE * data_out; /*

------------------------------------------------

Lab 5.c

/* LAB 5, functions that "return" more than one value */

/* Given the radius, find the area and the circumference */

/* of a circle */

#include "lab5.h"

int main(void)

{

double radius; /* radius of a circle */

double area; /* area of the circle */

double cir; /* circumference of the circle */

FILE * data_in; /* input file pointer */

FILE * data_out; /* output file pointer */

/* Open the two required files */

data_in = fopen(IN_FILE, "r");

if (data_in == NULL)

{

printf("Error on fopen file %s ", IN_FILE);

exit(EXIT_FAILURE);

}

data_out = fopen(OUT_FILE, "w");

if (data_out == NULL)

{

printf("Error on fopen file %s ", OUT_FILE);

exit(EXIT_FAILURE);

}

/* Print headers */

fprintf(data_out, " Your name here. Lab 5. ");

fprintf(data_out, " Radius Area Circumference ");

fprintf(data_out, "-------- -------- --------------- ");

/* Loop thru the values to compute the answers */

while ((fscanf(data_in, "%lf", &radius))== 1)

{

compute(radius, &area, &cir);

fprintf(data_out,"%7.2f %8.2f %11.2f ",

radius, area, cir);

}

fprintf(data_out, " ");

fclose(data_in);

fclose(data_out);

return EXIT_SUCCESS;

}

/*-----------------------------------------------------------*/

---------------------------------------------------------

lab 5.dat

3.7

6.8

4.0

5.6

12.7

45.6

---------------------------------------------------------

lab 5.h

//Lab 5 header file

#include

#include

#include

#define IN_FILE "lab5.dat"

#define OUT_FILE "lab5.out"

/* function prototype */

void compute(double radius, double *area, double *cir);

PROBLEM (1) Write a function that finds both the area and the circumference of a circle. Your function must use pointer notation (the address operator &, and the indirection operator *"), and will be a file separate (compute.c) from the other code. (2) You will also be required to create a working makefile. The function prototype is: /*Function to compute the area and the circumference */ /* of a circle */ void compute (double radius, double *area, double *cir); You will need the file lab5.c as your main/driver program for the function. This main program will set things up, read the values from the file, and print the output sentences. You will also need lab5.h and lab5.dat. THE FORMULAS (in algebraic notation)(must be translated to C notation) (1) area of a circle (2) circumference of a circle a Pl * radius c-2* PI radius

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!