### 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.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122`` ``````#include 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.
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166`` ``````#include 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.