This shows you the differences between two versions of the page.

— |
cs-142:pi [2015/01/07 08:53] (current) ryancha created |
||
---|---|---|---|

Line 1: | Line 1: | ||

+ | =Purpose= | ||

+ | The purpose of this lab is to create a program that performs a simple computation of the value $\pi$. | ||

+ | |||

+ | =Requirements= | ||

+ | [[image:pi.jpg|thumb]] | ||

+ | The value of $\pi$ can be computed according to the following formula: | ||

+ | $\frac{\pi}{4} = 1 - \frac{1}{3} + \frac{1}{5} - \frac{1}{7} + \frac{1}{9} - ...$ | ||

+ | Write a C++ program to compute $\pi$. Because the formula is an infinite series, you wont be able to compute $\pi$ exactly. Compute it with enough terms to arrive at the value 3.19419. (This is an estimated value, reached at 19 terms). You don't need to use a loop, but just add in as many terms as you need by making the expression longer. You may need to modify and run your program several times until you get the correct answer. | ||

+ | |||

+ | =Think before programming= | ||

+ | |||

+ | You may think that you don't know how to complete this lab, but you actually do. Write down the steps you would take to compute $\pi$ with a pencil and paper, then translate this into computer instructions. | ||

+ | # Inputs | ||

+ | # Outputs | ||

+ | |||

+ | In this case there are no ''Inputs'', other than running the program itself. The ''Output'' is the correct value of $\pi$ that you will be printing out. | ||

+ | |||

+ | =Getting Help= | ||

+ | |||

+ | If you get stuck: | ||

+ | |||

+ | # First work the problem out on a piece of paper. Don't ask for help too quickly and don't use a solution you find on the internet. We want you to build the ability to write programs on your own. | ||

+ | # Second ask the person sitting next to you. They'll feel good helping you and if they don't know you will learn together! | ||

+ | # As a last resort if you need help from a TA (and you are working in the lab), please use the help request queue: | ||

+ | |||

+ | [http://taohelpqueue.appspot.com/requesthelp/YPK364KMSA5U5QF55UCL8LQ3JHCS5C http://aml.cs.byu.edu/~kseppi/cs142help.html] | ||

+ | |||

+ | The TA's love to help, but you will gain much more in learning how to solve your problems on your own! | ||

+ | |||

+ | =Tips= | ||

+ | * Take note that you are given the formula for $\frac{\pi}{4}$, nor for $\pi$ itself. | ||

+ | * Ensure you know the difference between integer division and floating point division. | ||

+ | |||

+ | =I need more than this= | ||

+ | |||

+ | Some of you have already done some programming and need an additional challenge. Read ahead to find out how to use loops, then make your program calculate $\pi$ using as many terms (how many iterations the loop completes, NOT how many significant digits are listed when printed) as you ask it to. You will probably want to use a variable to tell your program how many terms you want to include. | ||

+ | |||

+ | If you are '''really curious''' about how computers actually do floating-point math you can take a look at the paper "What Every Computer Scientist Should Know About Floating-Point Arithmetic" by David Goldberg. you can find a link to it at http://dl.acm.org/citation.cfm?id=103163 | ||

+ | |||

+ | =Pass-off procedure= | ||

+ | {{see|How to pass off}} | ||

+ | |||

+ | When you have your program working, you will need to show it to a TA. | ||

+ | |||

+ | Put yourself in the help request queue to pass off: http://taohelpqueue.appspot.com/requesthelp/YPK364KMSA5U5QF55UCL8LQ3JHCS5C. | ||

+ | |||

+ | The TA will evaluate your code based on the following criteria: | ||

+ | |||

+ | # Did you print anything at all? (5 points) | ||

+ | # Did you print out the correct value for $\pi$? (10 points) | ||

+ | # Did you [[Coding_Style|format your code]] as shown in the book and in class, with separate lines and indenting. (5 points) | ||

+ | |||

+ | |||

+ | '''Extra credit''': Did you find out how to print out $\pi$ with as many '''iterations''' (of your loop, NOT calculating pie to a certain decimal place) as needed? (1 point) | ||

+ | |||

+ | =Electronic Submission= | ||

+ | |||

+ | WHEN YOU PASS OFF, you will need to submit your code. To do this follow the instructions below: | ||

+ | |||

+ | # On your computer, navigate to the directory containing your Visual C++ project (clue: look at the top bar in Visual C++). | ||

+ | # Find the .cpp files for the classes you have written. | ||

+ | # Attach these files to an email and send them to {{gmail|cs142ta.codesubmission}}. | ||

+ | |||

+ | If you have trouble, ask a neighbor or a TA. | ||

+ | |||

+ | You can save the files to the desktop and then attach them to an email. | ||

+ | |||

+ | An example pass-off form is shown below for this lab. You will find printed pass-off forms in 1119 TMCB. | ||

+ | |||

+ | [[image:lab2.png|300px]] |