In: Computer Science
Using newtons gravitation laws, design a program in C++ that determine the position of n=3 number of bodies relative to each other, and outputs the results in a ongoing table that constantly updates as long as the simulation runs, and a pgPlot.
Implement the newtonian equations using the LEAPFROG Method.
Show how the you solved the equations.
Make sure to describe each section of your code to describe what
each part of your code is responsible for (i.e use //) to recieve
full marks?
Code:
#include <iostream>
#include<math.h>
using namespace std;
float LEAPFROG(float m1,float m2, float r){//pass the mass of
two objects and r=seperation in meters
float g = 6.67*pow(10.0,-11.0);//Universal Gravitational Constant =
6.67*10^-11 N-m^2/kg^2
double f = (g*m1*m2)/(r*r);//Gravitation force of attraction
between two objects in newton(N)
return f;
}
int main()
{
float m1,m2,r;
double f;
cout<<"Enter the value of two masses in Kg :
"<<endl;
cin>>m1>>m2;
cout<<"Enter the distance between two masses in meters :
"<<endl;
cin>>r;
f=LEAPFROG(m1,m2,r);//call the function
cout<<"The force of attraction between two masses =
"<<f<<" Newton ";
return 0;
}
Note:****I hope your happy with my answer****If you have any doubt please comment me*****Thank you.......