Question

In: Computer Science

Using newtons gravitation laws, design a program in C++ that determine the position of n=3 number...

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?

Solutions

Expert Solution

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.......


Related Solutions

Write a program to reverse each integer number on array (size 3) using while loop. C++...
Write a program to reverse each integer number on array (size 3) using while loop. C++ Input: 3678 2390 1783 Output: 8763 0932 3871
Design a program using a flowchart or pseudocode that accepts a person’s loyalty card number and...
Design a program using a flowchart or pseudocode that accepts a person’s loyalty card number and amount spent in the store last month. Display the data only if the customer is a high spender – a person who spent more than $1000 in the store. A program that accepts customer info continuously until a sentinel value is entered and displays a list of high spenders.
DESIGN A FLOWCHART IN FLOWGORITHM AND WRITE THE PSEUDOCODE Number Analysis Program Design a program that...
DESIGN A FLOWCHART IN FLOWGORITHM AND WRITE THE PSEUDOCODE Number Analysis Program Design a program that asks the user to enter a series of 20 numbers. The program should store the numbers in an array and then display the following data: The lowest number in the array. The highest number in the array. The total of the numbers in the array. The average of the numbers in the array. PLEASE AND THANK YOU
A powerful contribution of the 1st and 2nd laws is to determine the design feasibility of...
A powerful contribution of the 1st and 2nd laws is to determine the design feasibility of a process/device/system. Please determine the feasibility of the following flow device: a steady-state flow device in which the inlet is steam at 300and 5 bar, the outlet is saturated steam at 100 and 1 bar, the device is adiabatic and produces approximately 500 kJ per kilogram of steam passed through the device.
Create a c program that takes 1 parameter, a number using that number, dynamically allocate a...
Create a c program that takes 1 parameter, a number using that number, dynamically allocate a memory so you store that number of integers write integers in order starting from 1 until you fill all that memory print the address and values of the first and the last integer stored in the memory
write a program in c++ to design a tuning circuit for a given frequency bond using...
write a program in c++ to design a tuning circuit for a given frequency bond using a variable capacity to determine the value of an inductance required for a given frequency range
IN C++ Write a program to find the number of comparisons using binarySearch and the sequential...
IN C++ Write a program to find the number of comparisons using binarySearch and the sequential search algorithm as follows: Suppose list is an array of 1000 elements. 3 Search list for some items as follows: a. Use the binary search algorithm to search the list. (You may need to modify the algorithm given in this chapter to count the number of comparisons.) b. Use the binary search algorithm to search the list, switching to a sequentialsearch when the size...
IN C++ Write a program to find the number of comparisons using binarySearch and the sequential...
IN C++ Write a program to find the number of comparisons using binarySearch and the sequential search algorithm as follows: Suppose list is an array of 1000 elements. 2 Use any sorting algorithm to sort list.
In C++ Write a program to find the number of comparisons using binarySearch and the sequential...
In C++ Write a program to find the number of comparisons using binarySearch and the sequential search algorithm as follows: Suppose list is an array of 1000 elements. 5.1 Use a random number generator to fill list.
DESIGN A FLOWCHART IN THE APPLICATION FLOWGORITHM Exercise called: Number Analysis Program Design a program that...
DESIGN A FLOWCHART IN THE APPLICATION FLOWGORITHM Exercise called: Number Analysis Program Design a program that asks the user to enter a maximum of 20 numbers. The program should store the numbers in an array and then display the following data: 1-The lowest number in the array. 2-The highest number in the array. 3-The total of the numbers in the array. 4-The average of the numbers in the array. PLEASE AND THANK YOU
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT