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 in C or C++ that takes a number series of size n (n...
Write a program in C or C++ that takes a number series of size n (n integers) as input from the user, push all the numbers to the stack, and reverse the stack using recursion. Please note that this is not simply popping and printing the numbers, but the program should manipulate the stack to have the numbers stored in reverse order. In addition to the provided header file, the students can use the following function to print the content...
Program is to be written in C++ using Visual studios Community You are to design a...
Program is to be written in C++ using Visual studios Community You are to design a system to keep track of either a CD or DVD/Blu-ray collection. The program will only work exclusively with either CDs or DVDs/Blu-rays since some of the data is different. Which item your program will work with will be up to you. Each CD/DVD/Blu-ray in the collection will be represented as a class, so there will be one class that is the CD/DVD/Blu-ray. The CD...
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.
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.
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
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 using a Scanner that asks the user for a number n between 1...
Write a program using a Scanner that asks the user for a number n between 1 and 9 (inclusive). The program prints a triangle with 2n - 1 rows. The first row contains only the square of 1, and it is right-justified. The second row contains the square of 2 followed by the square of 1, and is right justified. Subsequent rows include the squares of 3, 2, and 1, and then 4, 3, 2 and 1, and so forth...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT