Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

5.22 Lab Lesson 9 (Part 2 of 2) Part of lab lesson 9 There are two parts to lab lesson 9. The entire lab will

5.22 Lab Lesson 9 (Part 2 of 2)

Part of lab lesson 9

There are two parts to lab lesson 9. The entire lab will be worth 100 points.

Bonus points for lab lesson 9

There are also 10 bonus points. To earn the bonus points you have to complete the Participation Activities and Challenge Activities for zyBooks/zyLabs unit 5. These have to be completed by the due date for lab lesson 9. For example, if you complete 89% of the activities you will get 8 points (there is no rounding).

Lab lesson 9 part 2 is worth 50 points

For part 2 you will have 40 points if you enter the program and successfully run the program tests. An additional 10 points will be based on the style and formatting of your C++ code.

Style points

The 10 points for coding style will be based on the following guidelines:

Comments at the start of your programming with a brief description of the purpose of the program.

Comments throughout your program

Proper formatting of your code (follow the guidelines in the Gaddis text book, or those used by your CS 1336 professor)

If you have any variables they must have meaningful names.

Development in your IDE

For lab lesson 9 (both parts) you will be developing your solutions using an Integrated Development Environment (IDE) such as Visual Studio, Code::Blocks or Eclipse. You should use whatever IDE you are using for your CS 1336 class. Once you have created and tested your solutions you will be uploading the files to zyBooks/zyLabs. Your uploaded file must match the name specified in the directions for the lab lesson. You will be using an IDE and uploading the appropriate files for this and all future lab lessons.

You will need to develop and test the program in your IDE. Once you are satisfied that it is correct you will need to upload the source file to zyBooks/zyLabs, and submit it for the Submit mode tests. If your program does not pass all of the tests you need to go back to the IDE, and update your program to fix the problems you have with the tests. You must then upload the program from the IDE to zyBooks/zylabs again. You can then run the tests again in Submit mode.

When running your program in Submit mode it is very important that you look at the output from all of the tests. You should then try and fix all of the problems in your IDE and then upload the updated code to zyBooks/zyLabs.

C++ requirements

You are not allowed to use any global variables. Use of global variables will result in a loss of 25 points.

Your program must have at least 4 functions. You will need your main function. This will be the driver of your program. You must also have the calculateFutureValue. In addition you need a read function and a display function.

All of your functions, except main need to have function prototypes.

The calculateFutureValue function must have the following signature:

double calculateFutureValue(double presentValue, double interestRate, int months) 

Failure to follow the C++ requirements could reduce the points received from passing the tests.

General overview

In lab lesson 8 part 2 you calculated the present value. In this lab we are going to be calculating the future value. You will need to read in the present value, the monthly interest rate and the number of months for the investment. The formula is going to compute compounded interest (by month). There are a number of required functions that you will be writing, so do not start programming before you have read all of the instructions.

You must use function prototypes for all of the functions (except main).

Here is the formula:

F = P * pow((1 + i),t)

Where F is the future value, P is the present value, i is the monthly interest rate and t is the number of months.

Your program will need to make sure of better variable names that those used above.

The input for the program will be read in from a file.

You will read in the file name from cin.

You will then read in the present value, monthly interest rate, and the number of months from the input file.

There may be multiple sets of these values. You need to process them all.

The program should end when you reach the end of file on the input file.

The output from the program will be written to two different places.

Any error messages will be written to cout.

You will also be writing out to a file called output.xls.

The first thing you will write out are four "headings" separated by tabs (using the \t escape sequence).

Here is an output statement (this example is using cout). Your program will instead write to the output file.

cout  

This outputs the four headings separated by tabs. If you were to try and open this file with Excel it would give you a warning about the file format being incorrect, but would then determine that it is a tab file and would open it up properly. You could then save it as a read Excel file. This is one way you can get output from your programs into Excel.

The numbers read in must be positive values greater than 0. If they are not you need to output the three read in values to cout and display an error message saying the values are not all greater than 0. Note that all double values should be output in fixed format with two digits to the right of the decimal point. This is true for output to cout and for output to the output.xls file.

Assuming the following input in the input file:

-10000 1.1 48 

The following would be written to cout:

-10000.00 1.10 48 One or more of the above values are not greater than zero 

Your program must have at least four functions (including main).

Function to read data from the file

One function will read in the input values from the input file. Each call will read in the present value, monthly interest rate, and number of months.

Note that the monthly interest rate will be a number such as 10 or 12.5. These are to be read in as percentages (10% and 12.5%). You will need to divide these values by 100 to convert them into the values needed in the function (.1 and .125 for the above values). You need to do this conversion before you call the calculateFutureValue function (see below).

The function will return an unsigned int value that indicates if the call worked or not. A return value of 1 indicates that the values were read properly, a return value of 2 indicates that the input data was invalid, and a return value of 0 indicates that we have reached the end of file. The calling function (main) will use this return value to indicate how to process any data read in by the function. Note that we have to read three values from a file. The input file has already been opened. That means you will have to pass the input file as a parameter to the read function. You MUST pass the input file by reference (a reference to the ifstream object you created for your input file). Since we are reading in three values you will also have to pass these variables to the function by reference as well. That way the function can update the variables passed to it with the values read in from the file. If the read from the file fails due to end of file you will return a value of 0. If the input data is valid (all of the values are greater than 0) you will return back a value of 1. If any of the input values are invalid (0 or less) you need to return back a value of 2.

Function to calculate the future value

This function must have the following signature:

double calculateFutureValue(double presentValue, double interestRate, int months) 

This function will be called by unit tests, so you have to have this signature.

The function needs to calculate the future value and return it to the calling function.

The formula for calculating the future value is show at the start of this lab lesson.

Function to write the values to the output file

You will need to pass the output file (by reference) to this function. You will also need to pass the future value, present value, interest rate (the value before conversion), and number of months to the function (these do not have to be passed by reference).

This function will write the four values to the output file. The values must be separated by tabs (using the escape sequence for the tab character). The numbers must be written to the file in fixed format with two digits to the right of the decimal point.

There is no return value from the function

Finally the main function

The logic for your main will be as follows:

Read in the file name from the console

Open the input file

If the input file did not open write out an error message and stop processing

Open the output file

If the open failed close the input file, display an error message and stop processing

Write the headings to the output file.

Loop while we do not have an end of file condition

Call an input function that reads in the present value, interest rate and number of months

If the input is valid calculate the future value and display the results.

If the input is not valid display the data and an error message

End of loop

Close the input and output files

See Sample run # 3 below for the syntax of the error message that needs to be written to cout when either of the input or output files cannot be opened.

Sample run # 1 (valid input):

Assume the following is read in from cin

input.txt 

The input.txt file contains:

100 .99 36 

The contents of output.xls after the run:

Future Value Present Value Monthly Interest Months 142.57 100.00 0.99 36 

Sample run # 2 (invalid input)

The following is read in from cin

input.txt 

The contents of input.txt are:

-10000 1.1 48 10000 -1.0 12 10000 1.1 0 0 0 0 

The following would be written to cout:

-10000.00 1.10 48 One or more of the above values are not greater than zero 10000.00 -1.00 12 One or more of the above values are not greater than zero 10000.00 1.10 0 One or more of the above values are not greater than zero 0.00 0.00 0 One or more of the above values are not greater than zero 

Sample run # 3 (invalid input file name)

Assume the following is read in from cin

more.txt 

The more.txt file does not exist

The contents of cout after the run:

File "more.txt" could not be opened 

Expected output

There are nine tests. Tests 3 through 5 are unit tests of function calulateFutureValue. The rest of the tests have various input values. For these tests you have to match the expected output.

Can you please help with ouputs One and Three

image text in transcribed

This is the code i was using

#include #include #include #include #include using namespace std; //Function Declarations unsigned int readFile(ifstream &dataIn, double &presentValue, double &interestRate, int &months); double calculateFutureValue(double presentValue, double interestRate, int months); void writeDataToOutFile(ofstream &dataOut, double futureVal, double presentValue, double interestRate, int months); // main function int main() { // defines an input stream for the data file ifstream dataIn; // Defines an output stream for the data file ofstream dataOut; string filename, outfile; double presentValue, interestRate, futureVal; int months; unsigned int res;

// Setting the precision cout > filename; // Opening the input file dataIn.open(filename.c_str()); // checking whether the file name is valid or not if (dataIn.fail()) { cout

} else { // Closing the intput file dataIn.close(); dataOut.close(); break; } }

} return 0; } //This function read the data from the input file unsigned int readFile(ifstream &dataIn, double &presentValue, double &interestRate, int &months) { if (dataIn >> presentValue >> interestRate >> months) { if (presentValue

1: Compare output A 0 10 Could not find file: output.xls Input input2.txt Your output Your program produced no output Months Present Value 10000.00 Monthly Tntereat 0.42 Future Value Expected output 12205.06 4 8 2: Compare output A 10 10 Input inpmt3.txt -10000.00 1.10 48 One or more of the abova values aro not groater than zaro 10000.00 -1.00 12 One or more of the above values are not greater than zero 10000.00 1.10 One or more of the above values are not greater than zero 0.00 0.00 One or more ol the above values are not greater Lhhan zero Your output 3: Unit test A 0 5 Call to calculateFutureValue # 1 The call to ca lculateFutureVa lue (12345678901234.00, 0.0025, 60) returned an uexpected value of 12364211083596.52 Test feedback 4: Unit test 0/5 Call to calculateFutureValue # 2 1: Compare output A 0 10 Could not find file: output.xls Input input2.txt Your output Your program produced no output Months Present Value 10000.00 Monthly Tntereat 0.42 Future Value Expected output 12205.06 4 8 2: Compare output A 10 10 Input inpmt3.txt -10000.00 1.10 48 One or more of the abova values aro not groater than zaro 10000.00 -1.00 12 One or more of the above values are not greater than zero 10000.00 1.10 One or more of the above values are not greater than zero 0.00 0.00 One or more ol the above values are not greater Lhhan zero Your output 3: Unit test A 0 5 Call to calculateFutureValue # 1 The call to ca lculateFutureVa lue (12345678901234.00, 0.0025, 60) returned an uexpected value of 12364211083596.52 Test feedback 4: Unit test 0/5 Call to calculateFutureValue # 2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2019 Wurzburg Germany September 16 20 2019 Proceedings Part 2 Lnai 11907

Authors: Ulf Brefeld ,Elisa Fromont ,Andreas Hotho ,Arno Knobbe ,Marloes Maathuis ,Celine Robardet

1st Edition

3030461467, 978-3030461461

More Books

Students also viewed these Databases questions