1. circle problem

Hello all,
I have tried unsuccessfully to create program using a header file, implemenation file, document file, and driver program that compute the area of a circle given only the radius. I was told to use the header file for the function header only and the implementation file for the actual code. Can someone explain to me what I did wrong. Here is the code;
Code:
```/* area.h provides an interface for a library of the area of a circle.
***************************************************************/
#include <cmath>
#include <iostream>

const double PI = 3.14159;

double area(double radius, const double PI)
{
}```
implementation file.cpp
Code:
```/* area.cpp converts a given radius of a circle to the area of a circle.
*  using function area() that is stored in the library area.
*
*  Input: Radius of a circle
*  Output: Area of a circle
**************************************************************/

#include <iostream>
using namespace std;
#include "area.h"
#include <cmath>

int main()
{

cout << "This program converts a given radius of a circle\n"
<< "to the area of a circle.\n";

cout << "A radius length of: " << radius <<"," << "\nusing the correct equation converts to an area of: "
<< area1 << endl;
}```
driver
Code:
```/*driver.cpp test the functions and constants in area.h .
*
*********************************************************/

#include<iostream>
using namespace std;
#include "area.h"
#include <cmath>

double area(double radius, const double PI);

int main()
{
cout << "2 => " << area(2, PI) << "\n";
cout << "4 => " << area(4, PI) <<"\n";
}```
It works the way that I made it, however, i was told to I was told to use the header file for the function header only and the implementation file for the actual code. I am lost.

2. Understand that the header/implementation/driver distinction is really of importance for larger programs. Headers and implementation are generally seperated for compiling efficiency.

You appear to be confused on terms. Here is a very bare-bones 3-file program which converts between temperature formats.

Code:
```// Header files should only contain function prototypes.
float farenheit_to_celcius (float celcius);```
This is the implementation file.
Code:
```#include "f2c.hpp"
// The implementation file contains the functions which are prototyped in the header.

// Convert from farenheit temperature to Celcius.
float farenheit_to_celcius (float farenheit) {
return (farenheit - 32) * 5.0 / 9.0;
}```
This is the driver.
Code:
```#include <iostream>
#include "f2c.hpp"
// The driver function is the one that actually -uses- the functions prototyped in the header.

int main (void) {
float celcius;
float farenheit;

std::cin >> farenheit;

celcius = farenheit_to_celcius (farenheit);

std::cout << celcius;

return 0;
}```
Note that we have two .cpp files which rely on each other. We have to compile them together, using this command (assuming you are using linux)
Code:
`\$ g++ main.cpp f2c.cpp`

3. You don't need to define PI, cmath has M_PI; and that it's more accurate than your pi... (not that it -really- matters, it just seems you didn't realize it.)

4. Some compilers provide M_PI, although it's non-standard.

5. M_PI is not standard. You might want to #define PI yourself. As for accuracy . . . http://3.141592653589793238462643383...om/index1.html

In an old project of mine I used
Code:
```#undef PI
#define PI 3.14159265358979323846264338327950288419716939937510582097494459230\
781640628620899862803482534211706798214808651328230664709384460955058223172535\
940812848111745028410270193852110555964462294895493038196442881097566593344612\
847564823378678316527120190914564856692346034861045432664821339360726024914127\
3724587006606315588174881520920962829254091715364367892590360011330530548820466```
but that's rediculous. Did you know that with 39 digits of pi you can calculate the circumference of the universe, accurate to the width of a hydrogen atom? http://www.straightdope.com/classics/a3_357.html

6. Code:
```#include <cmath>

const double Pi = 4.*atan(1.);```

7. I think that would be std::atan() unless there was a using directive involved.

8. Yes, I keep forgetting that. Using gcc, it doesn't complain when I forget to put in the std::. I think I read something about the <c*> include files putting everything in both the global and std namespaces for now, or is it just gcc doing that?

9. I appreciate u explaining it to me. I was unsure as to why i would compile the 2 .cpp together when one is user activated by inputing a radius and the other had fixed values i didnt know that I could do that thanks again.

Originally Posted by QuestionC
Understand that the header/implementation/driver distinction is really of importance for larger programs. Headers and implementation are generally seperated for compiling efficiency.

You appear to be confused on terms. Here is a very bare-bones 3-file program which converts between temperature formats.

Code:
```// Header files should only contain function prototypes.
float farenheit_to_celcius (float celcius);```
This is the implementation file.
Code:
```#include "f2c.hpp"
// The implementation file contains the functions which are prototyped in the header.

// Convert from farenheit temperature to Celcius.
float farenheit_to_celcius (float farenheit) {
return (farenheit - 32) * 5.0 / 9.0;
}```
This is the driver.
Code:
```#include <iostream>
#include "f2c.hpp"
// The driver function is the one that actually -uses- the functions prototyped in the header.

int main (void) {
float celcius;
float farenheit;

std::cin >> farenheit;

celcius = farenheit_to_celcius (farenheit);

std::cout << celcius;

return 0;
}```
Note that we have two .cpp files which rely on each other. We have to compile them together, using this command (assuming you are using linux)
Code:
`\$ g++ main.cpp f2c.cpp`