Here is the code I have now...
Code:
class CanadianMoney //CanadianMoney class
{
private:
int dollars;
double cents;
public:
CanadianMoney() : dollars(0), cents(0)
{ } //constructor (no args) ..good
CanadianMoney (double c): dollars (static_cast<int> (c) ), cents (c - static_cast<int> (c) )
{ } //constructor (one arg)
CanadianMoney(int d) : dollars(d), cents(0)
{ } //constructor (one arg) ..good
CanadianMoney(int d, double c) : dollars(d), cents(c)
{ } //constructor (two args) ... good
~CanadianMoney () //destructor
{
cout << "CanadianMoney object "<<dollars<<"."<<cents<< " deleted";
cout << endl;
}
void setDollars(int d);
void setCents(double c);
int getDollars();
double getCents();
string toString (int d, double c);
};
///////////////////////////////////////////////////////////
void CanadianMoney :: setDollars (int d) //mutator
{
dollars = d;
}
void CanadianMoney :: setCents (double c) //mutator
{
cents = c;
}
int CanadianMoney :: getDollars () //accessor
{
return dollars;
}
double CanadianMoney :: getCents () //accessor
{
return cents;
}
string CanadianMoney :: toString (int d, double c) //string method
{
char membuff[SIZE]; //buffer in memory
ostrstream omem(membuff, SIZE); //create stream object
omem << "$" << d << "." << c << endl
<< ends;
cout << membuff;
return membuff;
}
///////////////////////////////////////////////////////////////
int main ()
{
//1
CanadianMoney money1(34.54);
CanadianMoney money2(15);
CanadianMoney money3(20,.61);
money1.getDollars();
money1.getCents();
money2.getDollars();
money2.getCents();
money3.getDollars();
money3.getCents();
//2
const int nmArray = 15;
CanadianMoney moneyArray[nmArray];
int n = 0;
double amount;
moneyArray[n].setCents(.0000);
moneyArray[n].setDollars(0); //element 0
cout << "Enter dollar and cents amount: ";
cin >> amount;
moneyArray[n++].getDollars();
moneyArray[n++].getCents(); //element 1
//cout << "Enter dollar and cents amount: ";
//cout <<endl;
//moneyArray[1].getDollars();
//moneyArray[1].getCents(); //element 2
return 0;
};
maybe this will give you an idea of what i mean....Thanks