Assignment Question? Need assistances

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.


Thank you very much,


Marcus
You probably shouldn't get any assistance at all, until you show your own code. You must have some idea form your lectures & tutorials?

Make sure to use code tags - select your code then press the <> button on the right so your code looks like this:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

using std::cout;
using std::cin;
using std::endl;
using std::string;

int main() {

string MyString = "Hello World" ;

cout << MyString << endl;

return 0;
}


TheIdeasMan,

Thank you for the reply.

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.

Just learning from this sites tutorial...

Marcus
Last edited on
Here is what I have started... At the line 30 I am getting an error and have no idea what it means.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <ctime>
#include <iostream>
using namespace std;


int main()
{
    // variables declaration
    int a, b, c, d, e;
    float f;
    float g;
    float h;
    float i;
    float j;
    float k;

    //actual initialization
    a = 100;                    
    b = 20;             
    c = 200;            
    d = 150;            
    e = 40;             
/*    f = 20.00
    g = 24.00
    h = 36.00
    i = 30.00
    j = 35.50
    k = 27.55*/

    //int TodaysDate = time_t now
    {

        time_t now = time(0);
        tm *ltm = localtime(&now);

        cout << ltm->tm_mday << '/' << 01 + ltm->tm_mon << '/' << 1900 + ltm->tm_year << endl;
    } 
    cout << time_t now << '/' << "ABC" << '/' << "buy" << '/' << a << '/' << f = 20.00 <<endl; 
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <ctime>
#include <iostream>
using namespace std;

void TodaysDate()
{
        time_t now = time(0);
        tm *ltm = localtime(&now);

        cout << ltm->tm_mday << '/' << 01 + ltm->tm_mon << '/' << 1900 + ltm->tm_year << endl;
} 

// Declaration of main()    
int main()
{
    // variables declaration
    int Day1, Day2, Day3, Day4, e;
    float f;
    float g;
    float h;
    float i;
    float j;
    float k;

    //actual initialization
    Day1 = 100;                    
    Day2 = 20;             
    Day3 = 200;            
    Day4 = 150;            
    e = 40;             
    f = 20.00;
    g = 24.00;
    h = 36.00;
    i = 30.00;
    j = 35.50;
    k = 27.55;

    cout << TodaysDate << ',' << "ABC" << ',' << "buy" << ',' << Day1 << ',' << f <<endl; 
    return 0;
}


After compling the code I got these results "1,ABC,buy,100,20" which is not what I wanted too.

What I want was "CurrentDate,ABC,buy,100,20.00". Any thoughts on this.


Thanks


Marcus
Topic archived. No new replies allowed.