Hey friends,
Started c++ not to logn ago and took right to it, up until now I have had no problems whatsoever. Now, with my specific assignment I have absolutely no idea what do to. I dont even know where to begin. I feel foolish and embarrassed and I'll i ask is that you folks can help point me in the right direction, Im not askign for the program code but maybe a fews hints at where to get started or an algorithm to help me along the way. Any help at all will be greatly appreciated.
The following is a snipped of the program retirements and I guess my first and biggest problem is that I have no idea what the program is supposed to do. Also keep in mind I am TERRIBLE at math so the thought of pi throws me for a total frenzy.
------------------------------------------------------
Here are 2 series that can be used to approximate the value of π :
π/4 = 1/1 - 1/3 + 1/5 - 1/7 + . . .
π2/24 = 1/22 + 1/42 + 1/62 + 1/82 + . . .
Design a C++ program that will use these 2 series to approximate the value of π. The number of terms to be used in the approximation will be read from a file. The number of terms must be an int, but use double type variables when performing arithmetic related to generating approximations.
Input File - This is the first program that will be designed to run in batch mode (read from a file, no prompts necessary). The data file will consist of a series of int values. Each value will be separated by whitespace and will be greater than zero. The first value in the data file will indicate the number of data sets to be processed. Each data set will consist of a single int value. This value represents the number of terms to be used in computing the approximation of π. See sample compilation and execution below.
Required Output - As output your program must generate a table (see sample below) with 4 columns. The estimates of π will be displayed in the first 2 columns with 12 digits to the right of the decimal. The 3rd column will be used to display the absolute value of the difference (also with 12 digits to the right of decimal) between the 2 estimates (see fabs, page 1504 in text). Display the number of terms used in the approximations in column 4 (maximum number of terms will be 100,000,000). Each column must have an appropriate heading and the headings and values must be right justified.
Running a program in batch mode using Linux redirection
1. When designing your program, omit the prompts. If you expect data to be read from a file, messages to the user are not necessary.
2. Create data file(s) to test your program. Use emacs to create a file. Include only the data values that you want the program to read. Make sure that the data is in the proper order and formatted as specified in the assignment. Save the file (its name should not end with .cpp).
3. Compile your program in the normal manner.
4. To run your program and use the data file you created as input, type in the command: ./a.out < datafilename
Sample compilation and execution
[l***@bobby]$ more data06
2
15
100
[***@bobby]$ g++ hw06.cpp
[***@bobby]$ ./a.out < data06
Estimate 1 Estimate 2 Difference # Terms
3.208185652262 3.079389826032 0.128795826230 15
3.131592903559 3.132076531809 0.000483628251 100
--------------------------------------------------------------------
Again thanks for the help and I look forward to joinign the community!