Question: Part 3 : Determine primality Take a look at primes. h - you will be implementing the isPrime function. You can assume that the parameter

Part 3: Determine primality
Take a look at primes. h- you will be implementing the isPrime function. You can assume that the parameter x is always 2.
Now, implement the function in primes.cpp. Your book has some pseudocode in Section 9.4 that you may find helpful.
Once you're finished (or you want to check your work), I've implemented several. tests in testPrimes.cpp. Compile with make testPrimes and run with ./testPrimes. These are the same tests that you will be graded against.
Part 4: Calcuate pi by throwing darts
Look at pi.h. You will be using the Point class (that l've already implemented for you) to implement the approximatePi function at the bottom.
You are going to randomly throw numDarts onto a square with an inscribed circle centered at (0,0) :
Several of your darts will land inside the circle, but some will miss Surprisingly, this game tells us something about !
The darts approximate area, and the ratio of the area of the circle to the area of the square is 4. So, if you divide the number of darts that landed inside the circle by the total number of darts Area of square: 22=4 thrown, you get an approximation of 4! All that's left is to turn that into an approximation of .
We're going to cheat and work only in the first quadrant (where the x and y coordinates are always nonnegative), but the ratio remains the same.
The Point class represents the coordinates where the dart landed. Do you see what method you might use to determine if the dart landed inside the circle?
Implement the approximatePi function in pi.cpp. You can then run the tests in testPi.cpp using make testPi to compile and ./testPi to run.
 Part 3: Determine primality Take a look at primes. h- you

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!