ENGR 021 Fall 2014 Assignment #3

DUE: Monday, October 13, 2014 6:30 PM at Start of Class

Rules:



1. Function to Create a Half-Diamond


 Write a C++ program that uses a function, outside of main(), to print the following pattern, the size of which will depend on input from the user:

*
**
***
****
*****
******
*******
********
*******
******
*****
****
***
**
*


In main() the user will enter the pattern height in terms of the number of rows, in the case shown above, 15.
Make sure that this information gets passed to the function that creates the pattern.
From looking at the symmetry involved, note that the number of rows should be an odd integer.
If the number of rows entered by the user is not odd, ask them to re-enter before proceeding.
Submit at least two patterns greater than 20 rows.


2. Pi Calculation


There are many formulas for computing pi.  One of the simplest is:

     pi/4 = 1 - 1/3 + 1/5 - 1/7 + 1/9 - ...  which comes from the series

     arctan(x) = x - x^3/3 + x^5/5 - x^7/7 +  x^9/9 - ...  (by letting x = 1.0, and in this notation, x^n is "x to the nth power")
	
Since it's a formula with an infinite number of terms, we can approximate its final value by taking a large number of terms and stopping.
Write a C++ program that writes a table of the values of this formula to a file, for all terms of the series up to 100 terms.
Then, after 100, show every 10th term until you get up to 1000.  Then show every 250th term until it goes up to 10,000 terms.
Show columns for term number, value of that particular term, and cumulative sum of the entire series of terms.
Finally, have the program print out the final value of pi computed.
Is it a good approximation?


3. Written Expression of a Large Integer, Up to 5-Digits


Write a program that accepts as input an integer up to five-digits, then prints out the number in proper English.
Show output for the program on numbers with one digit, two digits, three digits, four digits, and five digits.
Here is an example run:


This program "speaks" larger integers in word form!
Enter integer to be written in words (no commas!):  23719
Thanks.  You entered twenty three thousand seven hundred nineteen.
Would you like to enter another integer now? (y/n): y
Enter integer to be written in words (no commas!):  8404
Thanks.  You entered eight thousand four hundred and four.
Would you like to enter another integer now? (y/n): n
See ya later!