Question

EGR 121 C++ This is an individual assignment. Evidence of copying will be submitted as a violation of the honor code to the Dean of the College of Engineering and the Dean of Students. We will use the law of gravity to find the attractive force between two objects 1. Write a program that generates 3 seeded random integers ranging from 1 to 100 for the values of mi, ma, and r. (You need to seed the random numbers) 2. G is the gravitational constant 6.674 x 101 N (m/Kg) 3. Calculate F. The units will be Newtons. Run the program five times to test. Make sure for each run the value for mi, m2, and r changes. Turn in the following on Blackboard: 1) Your SOURCE CODE (epp file ONLY, such as main.cpp, filename.cpp. It is NOT -sln or any other extensions) A Word document (no other type of document, not PDF, not Pages, etc) with the screenshots of your programs output running the program five times. 2)
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>

using namespace std;

int main() {
    srand(time(NULL));
    int m1 = 1 + (rand() % 100);
    int m2 = 1 + (rand() % 100);
    int r = 1 + (rand() % 100);
    double f = (6.674e-11 * m1 * m2) / (r * r);
    cout << "m1 = " << m1 << endl;
    cout << "m2 = " << m2 << endl;
    cout << "r  = " << r << endl;
    cout << "Force = " << f << " N" << endl;
    cout << "Force = " << setprecision(15) << fixed << f << " N" << endl;
    return 0;
}

m249 r = 30 w. Force = 3.12492e-10 N Force0.000000000312492 N Process finished with exit code

Add a comment
Know the answer?
Add Answer to:
EGR 121 C++ This is an individual assignment. Evidence of copying will be submitted as a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT