CSCI 136 Supervised Programming Lab Assignment #4

$30.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (2 votes)

This week’s assignment will have you write programs that introduce you file IO, predefined functions and
call-by-reference function parameters. Feel free to work in pairs and ask for help early.
Using the Terminal command line, create a folder (using the mkdir command) called lab04 and cd into
that folder. I have added examples of what should happen when the programs are run to the end of
this document. Your source code files must each have a preamble at the top (see the programming
rules and guidelines document in Blackboard for more on the preamble).
a. (lab04a.cpp) Write a program that reads information for multiple investment accounts from a file
and computes the expected future value of each, outputting it to the console. The file containing the
investment information is “lab04a-data.txt” and is attached to this assignment. Each account
entry in the file will have values for the account balance, the number of times interest is compounded
per year, and the number of years to calculate for (3 values). The future value of an account can be
computed with the following formula:
�� = �� × (1 + �)!
• FV is the future value of the account
• CV is the current value of the account
• i is the interest rate per compound period
• t is the total number of compound periods
Use a global constant for the annual interest rate of 6%. Decimal values should be output with twoplace precision. You must use the pow predefined function in your solution. You must also write and
use a function that computes and returns the future value of an account when it is provided with the
current balance, the compounds-per-year and the number of years.
As an example, suppose $10,000.00 is invested at the annual interest rate of 6%, compounded 6 times
a year over 5 years. What is the future value?
�� = 10000.00
� = 0.06
6 = 0.01
� = 6 × 5 = 30
�� = 10000.00 × (1 + 0.01)!” = 13478.49
b. (lab04b.cpp) Write a program that repeatedly reads three whole numbers from a file and outputs
them in ascending order (smallest to largest). The data file is “lab04b-data.txt” and is attached to
this assignment.
CSCI 136 Supervised Programming Lab
Lab Assignment #4
You must write and use a function that swaps two call-by-reference parameters. You must then utilize
the swap function to put the values of the three variables into ascending order. You may only have a
single output statement in your code, so the values must be sorted prior to your
output.
Submitting your work
Make sure you are in your lab04 folder (use the pwd command) with your four source code files (use
the ls command) and then run the following to create a zip archive of them:
$ mkdir lastname_firstname_lab04
$ cp lab04a.cpp lastname_firstname_lab04/lab04a.cpp
$ cp lab04b.cpp lastname_firstname_lab04/lab04b.cpp
$ zip –r lastname_firstname_lab04.zip lastname_firstname_lab04/
You’ll need to change lastname and firstname to your actual last and first names in the steps
above. Once you have your zipfile, you can use that file as your submission for the assignment in
Blackboard.
If you are working in pairs, then you should have both of your names included as comments in the
source code file’s preamble (see the programming rules and guidelines document in Blackboard for
more on the preamble). Also, write both your names to the notes section in the submission form when
submitting to Blackboard.
Sample output
$ ./lab04a
$10000.00, 6% rate, compounded 6 times a year for 5 years yields: $13478.49
$15205.50, 6% rate, compounded 12 times a year for 4 years yields: $19318.42
$292041.66, 6% rate, compounded 8 times a year for 30 years yields: $1754922.59
$ ./lab04b
2 9 73
132 133 165
5 10 20
-20 20 20
7 7 7