Executive Summary

This programming project has you implementing a financial simulation. In this simulation, you have an account, daily expenses that are withdrawn from the account, bi-weekly paychecks, and interest that is compounded daily, but only withdrawn from or deposited in the account every 30 days. The basic parameters defining the simulation are stored in input files (we have several samples we refere to, input0.txt, input1.txt, input2.txt and a file with errors, input3.txt). The program's output includes ending balance, ending interest accrued, average daily balance, and a plot of the daily balance over the period of the simulation.
Honor: The course policy and the instructions it references, most pertinently COMPSCIDEPTINST 1531.1C, spell out what kinds of assistance are permissable for programming projects. The instructor can give explicit permission for things that would otherwise not be allowed. For this project, you have explicit permission
  1. to get help from the other current IC210 instructor as well as your own (any assistance must be documented though), and
  2. to use general purpose C++ resources online (though such use must be documented). Resources that might specifically address this project, say looking through code of programs that do interest calculations, are not allowed.
Put the instructions referenced in the course policy and the explicit permissions above, and what you get is summarized as:

Part 1 [Up to 30pts]

A Part 1 solution is a program that reads an input file name from the user, processes the input file with that name, and prints out the values defined in the input file in the following order (regardless of the order they appear in the input file): daily, paycheck, saverate, loanrate, one per line. If there is no file with the inputted name, the program should print out an error message and return 1 instead of zero. If any one of the above values is missing in the input file or has a negative value, the program should print an error message and return 2 instead of zero.
~/$ ./part1
Enter input file name: input4.txt
File "input4.txt" not found!
~/$ echo $?
1
~/$ ./part1
Enter input file name: input3.txt
Invalid input file!
~/$ echo $?
2
~/$ ./part1
Enter input file name: input0.txt
daily = 40
paycheck = 550
saverate = 3.5
loanrate = 13.25
~/$ echo $?
0

Part 2 [Up to 60pts]

A Part 2 solution should do all Part 1 did plus it should ask the user for an initial balance and a number of weeks to simulate, and it should simulate that many weeks of a bank account. The simulation should include:
  1. The first day of the simulation is Sunday, and the account balance starts off as the input "initial balance".
  2. Every day "daily" dollars should be taken out of the account.
  3. Every other Friday "paycheck" dollars should be deposited into the account. This means that the first Friday of the simulation, nothing will go into the account, but the second Friday there will be a deposit. The Friday after that, nothing goes into the account. The Friday after that there will be a deposit, and so on.
Note: There will be no interest componant to the Part 2 simulation.
Your Program must output the ending balance of the account along with the average daily balance in the account — specifically, the average of the end-of-the-day balances.
~/$ ./part2
Enter input file name: input0.txt
daily = 40
paycheck = 550
saverate = 3.5
loanrate = 13.25
Enter initial account balance: 722.50
Enter length of simulation in weeks: 10
Ending balance = 672.5
Daily average balance = 481.071
~/$ ./part2
Enter input file name: input2.txt
daily = 45
paycheck = 350
saverate = 0
loanrate = 0
Enter initial account balance: 1200.00
Enter length of simulation in weeks: 14
Ending balance = -760
Daily average balance = 72.5
~/$ ./part2
Enter input file name: input1.txt
daily = 40
paycheck = 550
saverate = 2.75
loanrate = 19
Enter initial account balance: $300
Error reading balance!
~/$ echo $?
3
~/$ ./part2
Enter input file name: input1.txt
daily = 40
paycheck = 550
saverate = 2.75
loanrate = 19
Enter initial account balance: 300
Enter length of simulation in weeks: -5
Error reading duration!
~/$ echo $?
4

Part 3 [Up to 85pts]

If you haven't already installed gnuplot in your VM, you'll have to do it now. To install gnuplot for your Ubuntu box/VM, give the command:
sudo apt-get install gnuplot-x11
You'll have to enter your VM password. After this, gnuplot should be available. To make sure everything's good, try the command:
echo "plot sin(x) with lines" | gnuplot -p
If a window with a plot of the sine function pops up, you're good to go.
A Part 3 solution should do all that Parts 1 and 2 did, but it will also produce a plot of the daily balance of the account. You will do this by producing a file called out.txt that contains the balance at the end of each simulated day, in order, one per line. Be sure to use .close() to close the file stream you use to to this. Then add the following code at the end of your program right before "return 0"
system("gnuplot -p -e 'plot \"out.txt\" with lines'");
which instructs your program to ask the operating system to run the command
gnuplot -p -e 'plot "out.txt" with lines'
which is a command that launches gnuplot and has it plot out.txt. In order for this to compile, you will have to add
#include <cstdlib>
to your list of #include's. This is required in order to use the system( ) function.
$ ./part3
Enter input file name: input0.txt
daily = 40
paycheck = 550
saverate = 3.5
loanrate = 13.25
Enter initial account balance: 500
Enter length of simulation in weeks: 40
Ending balance = 300
Daily average balance = 183.571

Part 4 [Up to 100pts]

A Part 4 solution should do everything that Parts 1, 2 and 3 did, but will also incorporate interest into the simulation. The account will be set up so that interest is compounded daily, which for our purposes means that interest will be calculated at the end of each day using rate/365 as the interest rate. However, the rate used depends on whether you have a positive or negative balance in the account. This bank allows a negative balance, but only at a pretty high interest rate. So, for example, if the rates are saverate = 2% and loanrate = 14%, then when the balance is $85.00 the interest for the day would be
interest = 85 * 0.02 / 365
but when the balance is $-85.00 the interest for the day would be
interest = -85 * 0.14 / 365
Note that your interest is negative when you're account is in the negative indicating that you'll lose money, and positive when your account is in the positive. That means when you owe money, you'll owe even more money. Although interest is compounded daily, it is only added to your account every 30 days. That means interest accrues (or builds up) in its own little side account until 30 days have been completed. Then at the very beginning of the 31st day, the interest is added or deducted from your account. Note that at the end of the 31st day, the first bit of the next installment of interest is accrued. Now your program should output the current amount of accured in interest along with the ending balance and daily average balance.
$ ./part4
Enter input file name: input1.txt
daily = 40
paycheck = 550
saverate = 2.75
loanrate = 19
Enter initial account balance: 450
Enter length of simulation in weeks: 64
Ending balance = 125.062
Ending interest = -1.61362
Daily average balance = 73.4497


When to submit

Project 1 is due by COB on Monday, September 22nd, according to the course's particular definition of "COB". Late projects incurr a penalty of 3N points, where N is the number of days late. So, a project that is not turned in by COB Monday, September 22, but which is turned in by COB Tuesday receives a 3 point penalty. A project that is not turned in by COB Tuesday, but which is turned in by COB Wednesday receives a 9 point penalty. And so on.

What to submit

You will submit the furthest properly functioning solution. So, if your Part 4 solution works, submit the Part 4 solution. If you don't have a properly functioning Part 4 solution, but your Part 3 solution works fine, submit a Part 3 solution. And so on. What gets submitted is:
  1. Your source code (i.e the .cpp file). You will submit a printout of this (use codeprint) and an electronic copy (how to do the electronic submission will be explained later).
  2. A completed copy of this coversheet on paper.
  3. A printout of a screen capture of the terminal (and of the gnuplot window if you've made it to parts 3 or 4) of your program running on input file input1.txt, with initial balance 500 and 400 weeks of simulation.

How to submit

The paper portions of your submission should be stapled together and slid under your prof's door. Instructions on electronic submission: Instructions on electronic submission: Install curl and the submit script onto your VM using the instructions on LCDR Kenney's software page ( http://zee.cs.usna.edu/~kenney/sw ), once installed you may submit your project by going to the directory on your VM with the project files and typing:
submit proj01 *.cpp
This will submit all C++ files in that directory, the syntax of the command is submit Project_Name (in this case proj01) and the files you wish to submit. Feel free to include any additional files you believe may be beneficial.

How projects are graded / how to maximize your points

Things to keep in mind to receive full marks:
  1. Submit all required items (as described above) on time.
  2. Make sure your output matches the example output in all ways. Note: your numbers could conceivably vary from the example outputs, but only by the tiniest amounts (less than a cent).
  3. Make sure you follow the IC210 Style Guide. This means proper indentation, use of whitespace within lines of code, logical organization of chunks of code,
Most important: Look at the the grading sheet.