Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Part 3 : Determine primality Take a look at primes. h - you will be implementing the isPrime function. You can assume that the parameter
Part : Determine primality
Take a look at primes. you will be implementing the isPrime function. You can assume that the parameter is always
Now, implement the function in primes.cpp Your book has some pseudocode in Section 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 : Calcuate pi by throwing darts
Look at pih 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 :
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 So if you divide the number of darts that landed inside the circle by the total number of darts Area of square: thrown, you get an approximation of 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 and 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 picpp You can then run the tests in testPi.cpp using make testPi to compile and testPi to run.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started