simple c++ library help  | |
November 16th, 2004, 02:29 AM
|
#1 (permalink)
| | Member
Join Date: Nov 2004
Posts: 56
|
this is the problem
Write a C++ program that reads the radius and height of a sphere in centimeters (real) from an input file (prog6b.inp), calculates the surface area and volume of the sphere and prints the input values plus the calculated values to an output file (prog6b.out).
Processing:
Program 6 is to read the radius and height of the sphere from prog6b.inp.
A function should be called to calculate the surface area of the sphere.
(surface area = 4*PI * radius2)
A function should be called to calculate the volume of the sphere.
(volume = 1/3 * PI * radius2 * height
Place the two functions in a library called sphere.
i wrote these notes in class,
a library has 3 files:
Client  which includes)
1.documentation
2.# include *.h
3.function call
Header  which includes)
1.documentation
2.protoypes
Implementation  includes)
1.documentation
2.# include
3.function definition
now i have this information and i know what it is, i just dont know what to do with it, like how to make it a library. I'm using dev c++ v4.o
thanks
sirhc |
| |
November 17th, 2004, 02:30 PM
|
#2 (permalink)
| | Ultimate Member
Join Date: Sep 2003 Location: Philadelphia
Posts: 1,484
|
Ok the client is the program where you include your header file. The header file is connected to the implementation file.
The header file might contain a prototype or a header, something like this:
int add(int x, int y);
The implemenation is where you flesh out your functions like this
int add(int x, int y)
{
return x+y;
}
You can have anything in the implementation file but only the functions declared in the header file can be imported into other files(ie client files).
What you need is to first write and debug the functions as you would in any ordinary program with one file. Then once youre sure the foos work you copy the code into a
hdr.c file which is you implementation file. Then you write a hdr.h file with just the prototypes (only the first line of a function without the {} and stuff between them, followed by a ";".
Then you go #include "hdr.h" and write another file. Becuase theyre in your hdr.c file which you included in your main program file you dont need to rewrite the foos, just use them as if they were there.
BTW, this is from memory, might be a few syntax errors. |
| |
November 17th, 2004, 03:06 PM
|
#3 (permalink)
| | Space for Sale! :p
Join Date: Oct 2001 Location: La Isla del Encanto
Posts: 5,836
|
Are you planning to learn something?
Or just pass the class and forget about everything?
I suggest you read the material (as it seems this is for a class assignment) provided and try to tackle the program by yourself.
Provide the code you have so at least we don't have to give you everything that way and just help you in tough spots!
__________________
boo!
|
| |
November 17th, 2004, 03:12 PM
|
#4 (permalink)
| | Member
Join Date: Nov 2004
Posts: 56
|
there is no material, just the notes we take in class, no text, i just forgot what the prof had told us to do with the files, and i'm not asking for the whole thing, just the part about the library. thanks elmers, that stuff u replied with does ring a bell. |
| |
November 17th, 2004, 07:03 PM
|
#5 (permalink)
| | Ultimate Member
Join Date: Sep 2003 Location: Philadelphia
Posts: 1,484
| |
| | | Thread Tools | Search this Thread | | | | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |