Objectives:
Design an object-oriented solution and implement the solution in C++ to solve the problem described below
As an example, suppose the user buys 1 00 ARC shares at $0 on a particular date (day 1 ), 20 share at $24 on a later date (day 2). 200 shares at $36 on day 3:and then sells 150 shares some time later (day 4) at $30 each.
Applying the longest held rule mean that of the 150 shares sold on day 4. I 00 were bought on day I . 20 were bought on day 2. and 30 were bought on day 3. To calculate the capital gain or loss. the price differential (i.e. sale price buy price) is multiplied by the corresponding number or shares. For this example, the calculation is
lOO x I0 | 20x6 | 30x(-6). giving a capital gain of $940. There arc other methods for calculating this amount but you should follow the "longest held rule".
Buy and sell information is stored in a text file. The name of the text. file is share-da!a.t.rt.
The format of the text tile is:
Date. x-code. activity•. shares. price
Each piece of data is separat ed by <1 comma.
[)ate irecorded as dd/m m/yyyy. ( :J?./08/ 2. 011 ).
x-code is the stock exchange code. for this assignment, it will be ABC.
Activity is either buy or sell.
Shares indicate the quantity of shares
Price is the price in dollars and cents for each share.
Some examples of the data file share-data.txt content:
02/08/2011,ABC,buy,100,20.00
05/08/2011,ABC,buy,20,24.00
06/08/2011,ABC,buy,200,36.00
15/08/2011,ABC,sell,150,30.00
19/10/2011,ABC,sell,40,35.50
03/11/2011,ABC,buy,100,7.25
You need to write'' C++ program that provides the to!lowing menu options.
1. Show capital gain (or loss) !'or the whole year.
2. F'or a given month. the number of shares bought that month and the cost.
3. Exit the program
Appreciate all assistance given in solving this problem of mine.
1, How, to approach this kind of issue
2. What are the steps that should be done
3. Can anyone give a heads-up on how to start writing the code.
For your info, I am not a programmer. But, i wanted to learn c++ programming. As I found interest on to it. I am still learning the basics and was seeking advice from experts on how to approach such problem.