Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,233 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,802 people online right now. Registration is fast and FREE... Join Now!




Function Definations

 
Reply to this topicStart new topic

Function Definations, using Functions need?..

fry_o9
5 Mar, 2007 - 08:56 PM
Post #1

New D.I.C Head
*

Joined: 14 Feb, 2007
Posts: 7


My Contributions
The gravitational attractive force between two bodies with masses m1 and m2 separated by a distance d is given by:
F=Gm1m2/d2
where g is the universal gravitational constant:
G=6.673*10-8 cm3/g.sec2)

write a function definition that takes arguements forthe masses of two bodies and between them,
and that returns the gravitational force between them. since you will use above formula, the gravitational force will be in dynes. one dyne equals a (g.cm/sec2).

embed your function definintion in a complete program that computes the gravitaional force between two objects give suitable inputs.



wat wud be the structure of the Function?????....

need help...
User is offlineProfile CardPM
+Quote Post

horace
RE: Function Definations
6 Mar, 2007 - 03:22 AM
Post #2

D.I.C Addict
Group Icon

Joined: 25 Oct, 2006
Posts: 573



Thanked: 4 times
Dream Kudos: 50
My Contributions

break the complete progam into logical sections that you can build in sequence
(1) start by writing a program to read m1, m2 and d and write then out to check they are OK
(2) when that works add code to calculate F and check that works
(3) when that works put the code to calculate F into a function

by implementing the code and testing a logical section at a time (or even line by line) you find errors as you go along and can fix then one by one. If you attempt to write the whole program at one go you can up with dozens of errors and never get it working.
User is offlineProfile CardPM
+Quote Post

qdoom
RE: Function Definations
6 Mar, 2007 - 03:24 AM
Post #3

D.I.C Head
**

Joined: 31 Aug, 2006
Posts: 82


My Contributions
If you want more information about functions (what are they, how do you use them etc.), I suggest you'd check out these links:

http://www.cprogramming.com/tutorial/lesson4.html

http://www.functionx.com/cpp/Lesson05.htm
http://www.functionx.com/cpp/Lesson06.htm

If you'll still think, that you need help after that - don't hesitate to ask.
User is offlineProfile CardPM
+Quote Post

fry_o9
RE: Function Definations
19 Mar, 2007 - 08:10 PM
Post #4

New D.I.C Head
*

Joined: 14 Feb, 2007
Posts: 7


My Contributions
is ds right??..
CODE

#include<math.h>

double grav_force(double m1_par, double m2_par, double d_par);

main()
{
double m1, m2, d, f;
clrscr();

cout<<" mass 1: ";
cin>> m1;
cout<<" mass 2: ";
cin>> m2;
cout<<" distance: ";
cin>> d;

f=grav_force(m1, m2, d);

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(9);

cout<<" Gravitational force: "<<f;

getche();
}

double grav_force(double m1_par, double m2_par, double d_par)
{
double g, f, d2, ans;

g=6.673*pow(10,-8);
ans=g*m1_par*m2_par;
d2=pow(d_par, 2);
f=ans/d2;

return(f);
}


QUOTE(qdoom @ 6 Mar, 2007 - 04:24 AM) *

If you want more information about functions (what are they, how do you use them etc.), I suggest you'd check out these links:

http://www.cprogramming.com/tutorial/lesson4.html

http://www.functionx.com/cpp/Lesson05.htm
http://www.functionx.com/cpp/Lesson06.htm

If you'll still think, that you need help after that - don't hesitate to ask.


User is offlineProfile CardPM
+Quote Post

ajwsurfer
RE: Function Definations
20 Mar, 2007 - 11:17 AM
Post #5

D.I.C Regular
Group Icon

Joined: 24 Oct, 2006
Posts: 292



Thanked: 2 times
Dream Kudos: 50
My Contributions
Yes
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 03:34PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month