ENGR 021 Fall 2014 Assignment #2

DUE: Monday, September 29, 2014 6:30 PM at Start of Class

Rules:



1. Factorial Approximation


See textbook end of chapter 3, problem #3, p. 134.  The problem states to calculate the factorial of 15 with direct computation as well as Stirlings approximation formula.
In addition to 15, also perform the calculation with the numbers 8 and 11.  Your program must calculate and print the following results:

(a) factorial of 15 calculated directly
(b) factorial of 15 calculated with Stirlings approximation formula
(c) the difference between those two calculations
(d) factorial of 8 calculated directly
(e) factorial of 8 calculated with Stirlings approximation formula
(f) the difference between those two calculations
(g) factorial of 11 calculated directly
(h) factorial of 11 calculated with Stirlings approximation formula
(i) the difference between those two calculations

From these results, describe the accuracy of Stirlings formula with a handwritten summary on the same page as your output.  Is it a good approximation?




2. Number Properties Table


Write a C++ program that generates a table of certain properties of integers between 1 and 100. 
The table will indicate the following data:  Square root of each integer; if that integer is a perfect square or not (Y/N); e (2.7182818284590452353602874713527) raised to that power; and whether that integer is evenly divisible by 12; in that order.
There is NO user input...just have the program make the table by itself SENDING OUTPUT TO A TEXT FILE that you later send to a printer yourself. 
As in any good table, the table must have header labels to show what you are reporting. 
Also, have real numbers accurate to three decimal places, and have columns well-aligned. 
This is an exercise in getting the computer to "do the work for you!" - make it look pretty.
Example output:

     N    sq rt N   perf sq?    e^N   div by 12?    
     ---------------------------------------------

     1     1.000      Y        2.718     N
     2     1.414      N        7.389     N
     .     .....     ...       .....    ...
     .     .....     ...       .....    ...
     .     .....     ...       .....    ...
   100    10.000      Y    2.688E+43     N

3. Date format conversion


Write a C++ program that reads the date from the keyboard in the form "month-day-year", with two digits each, and returns the same date in "MONTH DAY, YEAR" format.
Represent the day of the month as an ordinal number (e.g. 1st, 2nd, 3rd, 4th...)
Use the SWITCH-CASE statement to manipulate the 12 months. 
Of course, you must check the validity of the input, so that impossible dates like June 47 or 13-21-95 would be rejected, whereby you would give the user a chance to correct it, as discussed in class.
Examples:

 10-5-94    October 5th,1994
 2-2-82     February 2nd,1982
 6-1-02     June 1st, 2002