The purpose of this lab is to build a program with multiple classes as well as use the other skills you have picked up over the last few weeks. Note that in this lab you will be graded on your choices of how you break the problem up into small and meaningful pieces. Please make several nice, small, natural classes and methods.
Note to more advanced students: As noted above you will be graded on your choices of how you break the problem up into small and meaningful pieces. The TA's have been instructed NOT to be impressed that you found a way to code the entire lab in just three very complex lines, as impressive as that might be!
You will write a program that computes the total value of a portfolio for pretend customers at a bank.
Your code will read data for the portfolio from a data file. You will prompt the user for the needed file name.
There may be three kinds of assets in the customers account:
This will look something like this:
customer Kevin checking myaccount 100.00 bond mybond1 1997 100 0.07 bond mybond2 2010 200 0.01 irabond myirabond1 1997 100 0.06 end customer Mark irabond hisirabond1 1999 200 0.08 bond hisbond1 1990 2000 0.10 endThere are two pass-off files. Please download both(1 and 2). The second file should make it easy for you to tell where your program might be making mistakes.
“customer Kevin” means that there is a customer named Kevin and that his data will follow this line
“checking myaccount 100.00” means that Kevin has a checking account called “myaccount” containing $100.00.
“bond mybond1 1997 100 0.07” means that Kevin holds a bond called “mybond1” purchased in 1997 for $100.00 that earns 7% interest per year.
“irabond myirabond1 1997 100 0.06” means that Kevin holds a tax free bond called “myirabond1” purchased in 1997 for $100.00 that earns 6% interest per year.
Note that, as shown, the customer may have multiple assets of each type.
“end” indicates the end of a customer portfolio (there is no more information for Kevin).
“customer Mark” means that there is another customer named Mark and his data will follow.
The value of checking accounts is just the balance given for the account in the file.
The value of an irabond is the purchase amount plus interest compounded annually (don't include 2011, that is, if a bond was purchased in 2011, there will be no interest on it yet). See pages 132-138 for an example. You can think of it simply as a loop where each iteration (i.e. each year) your value goes up like this (make sure you don't modify the original value in calculating interest!):
valuePlusInterest = valuePlusInterest * (1.0 + rate)
The value of a bond is the purchase amount plus interest compounded annually (just like above) MINUS 30% of the interest (taxes). Note that taxes aren't taken out annually, only when the bond is cashed (this affects the interest you earn). Mathematically that would be:
cashValue = valuePlusInterest - (.3 * (valuePlusInterest - value) )
Once you have read in all of the data, allow your user to type the name of a customer. If the customer exists, print out the customer name, the portfolio value and all of the items in the portfolio with their individual values. Allow the user ask about names until they enter “stop”.
As you did in the previous labs, write some test cases. These should start very small and simple but progressively become more complex. You will use these to test that your program does what it is supposed to.
Your program should allow the user to give an account name for which the assets and total portfolio value will be printed. If we put the data from the example above in a file “example.txt”, we might picture seeing something like this as the output:
Please, dear user, a file name:example.txt Loading example.txt.......... done Customer name (or "stop"): Kevin Customer Name: Kevin Total Portfolio Value: 737.99 Checking: myaccount Value: 100.00 Bond: mybond1 Year: 1997 Value: 100.00 Rate: 0.07 Bond: mybond2 Year: 2010 Value: 200.00 Rate: 0.01 IRABond: myirabond1 Year: 1997 Value: 100.00 Rate: 0.06 Customer name (or "stop"): Mark Customer Name: Mark Total Portfolio Value: 11463.98 IRABond: hisirabond1 Year: 1999 Value: 200.00 Rate: 0.08 Bond: hisbond1 Year: 1990 Value: 2000.00 Rate: 0.10 Customer name (or "stop"): stop Peace out!
You can assume that no two customers in the file will have the same name and no two assets for a customer in the file will have the same name.
The point of this lab is for you to make classes. We are expecting you to make classes for the customers, and the various kinds of assets. And since you just learned about inheritance, you should use inheritance where it makes sense (the assets). You will need to use virtual functions (each asset will compute its current value in a different way) and a vector of asset pointers (see the Animals example for help). I would rather not say more that that here. This is the kind of problem you should be able to sort out now. So give it a try. If you get really stuck see a TA.
When you have your program working, you will need to show it to a TA. The TA will evaluate your code based on the following criteria:
Extra credit:
(2 point) Financial institutions do not compute interest in a loop. There is a formula for this. Look it up and use it. Compare the result to the loop version to assure it is right (print out the value for both computed values). Note that the formula depends on how often the interest is “compounded”. You will have to add another item to the bond lines in the file for this.