Help With Classes

I was given a shell program and the only instructions given were to write the 13 functions. I am having a hard time trying to figure out where to even start with this. Any help would be appreciated.


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
#include <iostream>
using namespace::std;

class Coins
{
public:
// Constructors
Coins(void);
Coins(int q, int d, int n, int p);

// Mutator Functions
void setPennies(int) ;
void setNickels(int);
void setDimes(int);
void setQuarters(int);

// Accessor Functions
int getPennies(void);
int getNickels(void);
int getDimes(void);
int getQuarters(void);

// Other Functions
void advanceOnePenny();
//  increase the pennies amount by 1
//      NOTE:  you may have to advance the nickels
//             you may have to advance the dimes
//             you may have to advance the quarters
//  in other words, minimize the number of coins

void output(ostream &);
void zeroOut(void); //set quarters, dimes, nickels & pennies to 0

private:
int quarters;
int dimes;
int nickels;
int pennies;
};

void main()
{
Coins stackOfChange(0, 1, 1, 3);

for( int i = 1; i <= 33; i++)
{
stackOfChange.advanceOnePenny();
stackOfChange.output(cout);
}

stackOfChange.zeroOut();
stackOfChange.output(cout);

stackOfChange.setQuarters(3);
stackOfChange.setDimes(1);
stackOfChange.setNickels(1);
stackOfChange.setPennies(2);

cout << stackOfChange.getQuarters()  << ' ' 
<< stackOfChange.getDimes()     << ' '
<< stackOfChange.getNickels()   << ' '
<< stackOfChange.getPennies() << endl;

return;
}
//////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// WRITE THE coins FUNCTIONS BELOW

// Constructors //    These two I don't know what functions would be written for them?
Coins::Coins(void)   
{
}
Coins::Coins(int q, int d, int n, int p)
{
}

// Mutator Functions
void Coins::setPennies(int p)
{
}
void Coins::setNickels(int n)
{
}
void Coins::setDimes(int d)
{
}
void Coins::setQuarters(int q)
{
}

// Accessor Functions
int Coins::getPennies(void)
{
}
int Coins::getNickels(void)
{
}
int Coins::getDimes(void)
{
}
int Coins::getQuarters(void)
{
}

// Other Functions
void Coins::advanceOnePenny()
{
}
//  increase the pennies amount by 1
//      NOTE:  you may have to advance the nickels
//             you may have to advance the dimes
//             you may have to advance the quarters
//  in other words, minimize the number of coins

void Coins::output(ostream &)
{
}
void Coins::zeroOut(void) //set quarters, dimes, nickels & pennies to 0
{
}
Are you trying to find out the value of the functions?
Seems rather straightforward. Could you be a little more specific?
I am sure its extremely straight forward. For starters, lines 72-77 I am not sure what I am suppose to be calling with the constructor functions?
Contructors are used to initialize class members.

Coins::Coins(int, int, int, int) takes four parameters, each named with the initial of a member of Coins. Which member should be initialized to which parameter?

Coins::Coins() takes no parameters. What should the members be initialized to?
Initialized to 0?
This is what I have added, I can't figure out how/what to put in the output.
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include <iostream>
using namespace::std;

class Coins
{
public:
// Constructors
Coins(void);
Coins(int q, int d, int n, int p);

// Mutator Functions
void setPennies(int) ;
void setNickels(int);
void setDimes(int);
void setQuarters(int);

// Accessor Functions
int getPennies(void);
int getNickels(void);
int getDimes(void);
int getQuarters(void);

// Other Functions
void advanceOnePenny();
//  increase the pennies amount by 1
//      NOTE:  you may have to advance the nickels
//             you may have to advance the dimes
//             you may have to advance the quarters
//  in other words, minimize the number of coins

void output(ostream &);
void zeroOut(void); //set quarters, dimes, nickels & pennies to 0

private:
int quarters;
int dimes;
int nickels;
int pennies;
};

void main()
{
Coins stackOfChange(0, 1, 1, 3);

for( int i = 1; i <= 33; i++)
{
stackOfChange.advanceOnePenny();
stackOfChange.output(cout);
}

stackOfChange.zeroOut();
stackOfChange.output(cout);

stackOfChange.setQuarters(3);
stackOfChange.setDimes(1);
stackOfChange.setNickels(1);
stackOfChange.setPennies(2);

cout << stackOfChange.getQuarters()  << ' ' 
<< stackOfChange.getDimes()     << ' '
<< stackOfChange.getNickels()   << ' '
<< stackOfChange.getPennies() << endl;

return;
}
//////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// WRITE THE coins FUNCTIONS BELOW

// Constructors
Coins::Coins(void)
{
}
Coins::Coins(int q, int d, int n, int p)
{
}

// Mutator Functions
void Coins::setPennies(int p)
{
	if (p >=0)
	{
		pennies = p;
	}
}
void Coins::setNickels(int n)
{
	if (n >=0)
	{
		nickels = n;
	}
}
void Coins::setDimes(int d)
{
	if (d >=0)
	{
		dimes = d;
	}
}
void Coins::setQuarters(int q)
{
	if (q >= 0)
	{
		quarters = q;
	}
}

// Accessor Functions
int Coins::getPennies(void)
{
	return pennies;
	
}
int Coins::getNickels(void)
{
	return nickels;
}
int Coins::getDimes(void)
{
	return dimes;
}
int Coins::getQuarters(void)
{
	return quarters;
}

// Other Functions
void Coins::advanceOnePenny()
{
pennies++;
	//getting the total amount into pennies then translating to n d and q.
pennies = pennies;
pennies = pennies + (nickels * 5);
pennies = pennies + (dimes * 10);
pennies = pennies + (quarters * 25);

quarters = pennies / 25;
pennies = pennies - (quarters * 25);
dimes = pennies / 10;
pennies = pennies - (dimes * 10);
nickels = pennies / 5;
pennies = pennies - (nickels * 5);


	
}
//  increase the pennies amount by 1
//      NOTE:  you may have to advance the nickels
//             you may have to advance the dimes
//             you may have to advance the quarters
//			in other words, minimize the number of coins

void Coins::output(ostream & )
{
	
}
void Coins::zeroOut(void) //set quarters, dimes, nickels & pennies to 0
{
	pennies = 0;
	nickels = 0;
	dimes = 0;
	quarters = 0;

}
Topic archived. No new replies allowed.