You will write a program that allows a user to determine his tax bill due to capital gains. You should make use of classes that already exist (particularly one or more of the ADTs we've studied since the 6-week exam) as well as make your own class(es) should the need arise. You should also ensure that you are utilizing information hiding (i.e. private class members) whenever possible to limit unwanted access to your data members.
People have all different types of income and one of these types is called capital gains. A capital gain is a profit that results from the sale of a capital asset (stock, bond, mutual fund, property, etc.) for more than you purchased it for.
Now whenever money is made, the IRS is there to take their cut. The capital gains tax rate varies depending on a number of factors but we will only look at two rates for people in the middle class: short-term and long-term. The difference is this:
The amount the IRS takes is the tax rate multiplied by the capital gain. How this capital gain is calculated is (of course!) the interesting part.
The capital gain is the sell price minus cost basis (purchase price). The IRS allows three different ways to calculate your cost basis for things in which you may own multiple shares, purchased over time (like stocks and mutual funds):
Here is a simple example. You purchased 200 shares of Facebook in mid-2013 (100 shares at $30 in May & 100 shares at $50 in July.) Then later sold 100 shares in late-2014 at $75.
Using the three methods described, your tax bill would be:
Note that in each case, you received $7500 dollars for the sale. The only difference in calculating the taxes you owe on the profit is which shares you sold.
The project is divided up into a number of parts. I strongly recommend that you solve each part completely - including thorough testing - before you move on to the next part. Smart (and functional) code in the early parts will save you time in the later parts. For example, here are a few ideas that may make your accounting job easier (optional, of course, but IMO helpful):
Date
class which would hold day, month, and year to make handling the date much easier in your program.Share
class to record the particulars of each transaction such as the Date
and the purchase price. You wouldn't want to use a single Share
instance to keep track of the number of shares purchased since later on you may only sell a portion of the number purchased at that price on that particular day; rather, you should create a new Share
instance for every single share you purchased so that selling an individual share becomes more intuitive. Plus, you won't have to dig around your monolithic uber-Share structure to figure out what the purchase price was for a particular share.Share
class and wanted to use the Stack we worked with during class and lab to hold your Share
s, making a Stack<Share>
seems fitting.<iomanip>
library and the following two lines of code before you decide to cout
any information:
cout.precision(2); cout.setf(ios::fixed,ios::floatfield);This will give you the nice presentation you see in the examples.
Write a program that reads in the information from a file such as test.txt and prints out the total taxes based upon the FIFO method. Treat all gains as long term.
$ ./part1 < test.txt You purchased 100.00 shares of Facebook at $30.00 on 7/21/2013 You purchased 100.00 shares of Facebook at $50.00 on 5/9/2014 You sold 50.00 shares of Facebook at $75.00 on 7/19/2014 You sold 50.00 shares of Facebook at $75.00 on 7/25/2014 Using FIFO accounting, you owe Uncle Sam $675.00 $
Write a program that reads in the information from files such as test.txt and test2.txt prints out the total taxes based upon the FIFO method. Expand your program to accurately calculate taxes for short-term and long-term capital gain.
$ ./part2 < test.txt You purchased 100.00 shares of Facebook at $30.00 on 7/21/2013 You purchased 100.00 shares of Facebook at $50.00 on 5/9/2014 You sold 50.00 shares of Facebook at $75.00 on 7/19/2014 You sold 50.00 shares of Facebook at $75.00 on 7/25/2014 Using FIFO accounting, you owe Uncle Sam $900.00 $ ./part2 < test2.txt You purchased 100.00 shares of Facebook at $30.00 on 7/21/2012 You purchased 100.00 shares of Facebook at $50.00 on 5/9/2013 You sold 50.00 shares of Facebook at $75.00 on 7/19/2014 You sold 50.00 shares of Facebook at $75.00 on 7/25/2014 Using FIFO accounting, you owe Uncle Sam $675.00 $
Write a program that reads in the information from files such as test.txt and test2.txt prints out the total taxes based upon the FIFO method and the average cost basis method.
$ ./part3 < test.txt You purchased 100.00 shares of Facebook at $30.00 on 7/21/2013 You purchased 100.00 shares of Facebook at $50.00 on 5/9/2014 You sold 50.00 shares of Facebook at $75.00 on 7/19/2014 You sold 50.00 shares of Facebook at $75.00 on 7/25/2014 Using FIFO accounting, you owe Uncle Sam $900.00 Using average accounting, you owe Uncle Sam $700.00 $ ./part3 < test2.txt You purchased 100.00 shares of Facebook at $30.00 on 7/21/2012 You purchased 100.00 shares of Facebook at $50.00 on 5/9/2013 You sold 50.00 shares of Facebook at $75.00 on 7/19/2014 You sold 50.00 shares of Facebook at $75.00 on 7/25/2014 Using FIFO accounting, you owe Uncle Sam $675.00 Using average accounting, you owe Uncle Sam $525.00 $
Write a program that reads in the information from files such as test.txt and test2.txt and prints out the total taxes based upon the FIFO method, the average cost basis method, and selling your most expensive shares first.
$ ./part4 < test.txt You purchased 100.00 shares of Facebook at $30.00 on 7/21/2013 You purchased 100.00 shares of Facebook at $50.00 on 5/9/2014 You sold 50.00 shares of Facebook at $75.00 on 7/19/2014 You sold 50.00 shares of Facebook at $75.00 on 7/25/2014 Using FIFO accounting, you owe Uncle Sam $900.00 Using average accounting, you owe Uncle Sam $700.00 By selling most expensive shares first, you owe Uncle Sam $625.00 $ ./part4 < test2.txt You purchased 100.00 shares of Facebook at $30.00 on 7/21/2012 You purchased 100.00 shares of Facebook at $50.00 on 5/9/2013 You sold 50.00 shares of Facebook at $75.00 on 7/19/2014 You sold 50.00 shares of Facebook at $75.00 on 7/25/2014 Using FIFO accounting, you owe Uncle Sam $675.00 Using average accounting, you owe Uncle Sam $525.00 By selling most expensive shares first, you owe Uncle Sam $375.00 $
Put the main method for your solution in a file named driver.cpp
, since each part builds upon the previous with corresponding output, there is no reason to submit a different driver file for each part. You will only receive credit for the highest numbered part that actually works! For example, if you have a working solution to Part 3, but only a partially completed solution to Part 4, you will not receive any partial credit for Part 4. Important points:
Submit all the .cpp and .h files containing the source code for your solution along with a screen captures showing your code compiling and the accounting results of your program after being run on transactions.txt (name the files compile.png
& execute.png
) via the the submisison website: submit.cs.usna.edu.
In a terminal window from your project02 folder, use the following command to submit your solution:
~/bin/submit -c=SI221 -p=Project02 *.cpp *.h compile.png execute.png
Do not submit any .o or executable files!
Complete and submit a signed copy of this cover sheet / survey in the first class / lab session after submitting your project electronically.
Highest Completed Part | Maximum Points Available |
Part 1 | 60 points |
Part 2 | 70 points |
Part 3 | 90 points |
Part 4 | 100 points |
Write you own Makefile and submit it along with your code. It should work so that typing make
in the terminal automatically compiles your project! (HINT: see Lab01). Your screenshot must demonstrate use of your Makefile.