Lab 1080 - pi

Description

In this lab, you will compute an approximation for the number Pi, which is approximately 3.14159265358979323.

There are many ways to calculate the value for Pi other than by just typing it in or using a built-in constant. In this lab, your program will follow a simple algorithm:

Pick two positive integers at random. The probability that they are relatively prime is six over Pi squared.

Numbers are relatively prime if they share no common factor other than the number 1. Example: 9 and 20 are relatively prime (even though neither of them are prime themselves -- that does not matter). The numbers 16 and 36 are not relatively prime because 4 will divide into 16 and 36 evenly.

Assignment
This lab is an exercise in being able to go from an algorithm to a working program. Write a class CalculatePi that has these methods:

You will also need to write a test program. Your calculated value using this algorithm should be accurate to at least 0.001 of the actual value of Pi.


Copyright © 2010 by Asylum Computer Services LLC Return to CS Labs