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;
}
|