Stock class

I am having trouble with this program I am not sure if I have the functions declared properly and what I need to call them? I am especially confused about the driver program. Can anyone let me know if I'm on the right track? Here is what my lab is:

(45) 1. Specify a class Stock with these attributes
• sym : string – stock symbol
• noShares : integer – number of shares
• shareVal : floating point – dollar value of one share
• totVal : floating point – dollar value of the shares
The Stock class has these responsibilities
• - setTot() : void – computes the total value of the stock//
• + ctor() – sets stock symbol to null string, number of shares to zero, the value of a share and the total value of the stock to 0.0
• + ctor(s : string, n : integer, v : real) - sets stock symbol to s, number of shares to n, the value of a share to v, and calls the setTot() member function to get the total value of the stock
• + setSym(s : string) : void – sets the ticker symbol
• +buy(n : integer, p : real) : void – buy n shares at $p per share
• +sell(n : integer, p : real) : void – sell n shares at $p per share
• +update(p : real) : void – update the dollar value of one share $p
• +getSym() : string – get the ticker symbol
• +getVal() : real – get the value of a single share
• +getNoShares () : integer – get the number of shares
• + print() : void – print ticker symbol, number of shares, the current price per share, and the total value of the holding
• + operator++() : Stock – increments the number of shares by one at the current price and invokes the setTot() member function
• + operator++(dummy : integer) : Stock – increments the number of shares by one at the current price and invokes the setTot() member function after making a copy of the current object to return to the caller
• + operator--() : Stock – decrements the number of shares by one at the current price and invokes the setTot() member function
• + operator--(dummy : integer) : Stock – decrements the number of shares by one at the current price and invokes the setTot() member function after making a copy of the current object to return to the caller

Test your class specification and member function implementations by exercising ALL the member functions by testing a minimum of three holdings.
Data validation: ensure no sell or buy involves 0 or negative numbers of shares and that a sell cannot exceed the number of shares held.

This is what I have so far:

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
  
#include <iostream>
#include <string>
using namespace std;

class Stock 
{
public:
	string sym; 
	int noShares; 
	double shareVal;
	double totVal;
	
	Stock(); //ctor
	Stock(string s, int n, double v);
	void setSym(string s);
	void buy(int n, double p);
	void sell(int n, double p);
	void update(double p);
	string getSym();
	double getVal();
	int getnoShares();
	void print();
	Stock operator++();
	Stock operator++(int);
	Stock operator--();
	Stock operator--(int);


private:
	void setTot();


};//endclass

void Stock::setSym(string s)
{ s = sym;}

string Stock::getSym()
{return sym;}

double Stock::getVal()
{return shareVal;}

int Stock::getnoShares()
{return noShares;}

Stock::Stock(string s, int n, double v)
{
	s = sym;
	n = noShares;
	v = shareVal;
	setTot();
}

void Stock::buy(int n, double p)
{
	cout << "Enter the Symbol of the Stock you would like to buy: " ;
	cin >> sym;
	cout << "How many shares of the stock would you like to buy?: ";
	cin>> noShares;
	cout << "What is the current price of the stock?: ";
	cin >> shareVal;
	n = noShares;
	p = shareVal;

}

void Stock::sell(int n, double p)
{
	cout << "Enter the Symbol of the Stock you would like to sell: " ;
	cin >> sym;
	cout << "How many shares of the stock would you like to sell?: ";
	cin>> noShares;
	cout << "What is the current price of the stock?: ";
	cin >> shareVal;
	n = noShares;
	p = shareVal;

}

void Stock::update(double p)
{
	p = shareVal;
}

void Stock::print()
{

	cout << "SYMBOL: " << getSym();

	cout << "Number of Shares: " << getnoShares();

	cout << "Current Price of Share: " << getVal();

	cout << "Total Value of Holding: " << totVal;
}

void Stock::setTot()
{
	totVal = noShares * shareVal;

}

Stock Stock::operator++()
{
	
	++noShares;
	setTot();
	
	
}


Stock Stock::operator--()
{
	--noShares;
	setTot();
}

int main()
{









return 0;
}//endmain
Topic archived. No new replies allowed.