Sunday, May 8, 2016

Gravitational Force Calculator

A simple c++ program to calculate the force between two massive bodies.


#include<iostream>
using namespace std;
int main ()
{
  double d;
  double T;
  double r;
  double M1;
  double M2;
  double Fg;
  double a1;
  double a2;
  const double G = 0.000000000066741;
  cout << "Welcome to the first version of Gravitational Force Calculator.";
  cin.get();
  cout << "This program was made by Eduardo Monteiro.";
  cin.get();
  cout << "Insert the masses of the two objects and them insert the distance between the barycenters of the objects. The gravitational constant is considered 0.000000000066741.";
  cin.get();
  cout << "Mass of point particle 1 (Kilograms) =";
  cin >> M1;
  cin.get();
  cout << "Mass of point particle 2 (Kilograms) =";
  cin >> M2;
  cin.get();
  cout << "Distance between barycenters (Meters) =";
  cin >> r;
  cin.get();
  d = r*r;
  T = M1*M2/d;
  Fg = T*G;
  Fg = M1*a1;
  Fg = M2*a2;
  cout << "Gravitational Force ="<< Fg << endl;
  cout << "Acceleration of particle 1="<< a1 << endl;
  cout << "Acceleration of particle 2=" << a2 << endl;
  cin.get();
  system("PAUSE");
}

No comments:

Post a Comment