Reading to Input Failure, Simple File Input/Output, Arithmetic Calculations

Read and follow the following program specification carefully.

The Program Specification: Calculating the Future Value of an Investment

You will write a program to calculate the future value of an investment, using the formula:

where:

S is the value of the investment after t years

P is the initial value of the investment

R is the annual interest rate the investment earns

n is the number of periods per year

t is the number of years the investment is held

Input file description and sample:

Your program must read its input from a file named DATA.IN - use of another input file name will result in massive deductions. Each line of the input file will contain four values, separated by whitespace:

the amount initially invested (positive real number between 1.00 and 100,000.00)

the annual interest rate earned (positive real number between 0.001 and 0.20)

number of periods per year (integer between 1 and 365)

number of years investment is held (integer between 1 and 30)

You may assume that all input values will be logically correct (no negatives, for instance), and that all values will be in the specified ranges. For instance:

1000.00 0.05 12 10

1000.00 0.05 12 20

1000.00 0.05 12 30

1000.00 0.05 365 10

1000.00 0.05 365 20

1000.00 0.05 365 30

Note that you must not make any assumptions about the number of lines of data in the input file. Your program must be written so that it will detect when it's out of input and terminate correctly.

What to Calculate:

Your program must read each line of input data, as described above, and calculate the corresponding future value. In order to achieve the best possible accuracy, you are required to use variables of type double to store all real (that is, decimal) numbers needed in this program.

In order to raise the parenthesized quantity to a power, use the function pow( ). This function may be used to calculate y = xk, where x is a double and k is an integer:

y = pow(x, k);

In order to use pow( ), you must include the standard header file cmath.

Output description and sample:

Your program must write all output data to a file named DATA.OUT - use of any other output file name will result in a massive deduction of points. The sample output file shown below corresponds to the sample input data given above:

Jonathan Leidig

 

Principal..Rate....Periods.....Years........Balance

1000.00....0.0500.......12........10........1647.01

1000.00....0.0500.......12........20........2712.64

1000.00....0.0500.......12........30........4467.74

1000.00....0.0500......365........10........1648.66

1000.00....0.0500......365........20........2718.10

1000.00....0.0500......365........30........4481.23

 

You are not required to use this exact horizontal spacing, but your output must satisfy the following requirements:

The first line of the output file must contain your name.

The second line of the output file must be blank.

You must use the specified column labels, in the third line of the output file.

All dollar amounts must be formatted to show two places after the decimal.

The annual interest rates must be formatted to show four places after the decimal.

The number of periods and number of years must be formatted as integer values.

Allow sufficient space for each value your program prints; the future values could be on the order of 10 million.

You must arrange your output in neatly aligned columns.

You must use the same ordering of the columns as shown here.

Do not insert any additional lines of output; do have a newline at the end of each line.

Programming Standards:

Remember to name your project by your last name, first initial, and project 2 as in Leidig-J-Project-2.cpp.

You'll be expected to observe good programming and documentation standards. All the discussions in class about formatting, structure, and commenting your code will be enforced. Some, but not necessarily all, specifics:

You must include header comments specifying your name and the date your source code and documentation were completed.

The header comment must also include a brief description of the purpose of the program (sort of a user guide) - this should be in your own words, not copied from this specification.

You must include a comment explaining the purpose of every variable you use in your program.

You must use meaningful, suggestive (of function or purpose!) variable names.

Precede every major block of your code with a comment explaining its purpose. You don't have to describe how it works unless you do something so sneaky it deserves special recognition.

You must use indentation to make control structures, like loops, if-else statements, or function bodies more readable.

Hints:

This program requires that you know how to manage file-oriented input/output operations --- the slides and the text provide good examples and guidelines. Your program must read lines of input data until there is no more data to be processed. You may want to use the same logical design as Project 1.

You'll have to use manipulators to manage the formatting of your code.

Testing:

At minimum, you should be certain that your program produces the output given above when you use the given input file. However, verifying that your program produces correct results on a single test case does not constitute a satisfactory testing regimen. You should make up and try additional input files as well; of course, you'll have to determine what the correct output would be.

What to turn in and how:

This project will be submitted to the Curator system for grading.

You must also turn in a printout of your fully documented C++ source code, which will be graded for adherence to the programming and documentation standards given in this specification. Print your source code using a fixed-pitch font, such as Courier rather than a proportional font, such as Times Roman.

Your final project score will be a weighted average of the runtime score (50%) and the score from your hardcopy (50%).

Getting Started:

#include <fstream>

#include <string>

using namespace std;

double calculateBalance( double principal, double rate, int periods, int years)

{

double balance = 0;

//calculate the balance

return balance;

}

int main()

{

//Setup input and output files

//Loop

//Read an input line

//Calculate the future balance

//Output the results

//Close files and return

}