I am trying to write a program with this class.
I need to create two currency objects, print them to the screen,
and add them together. Here is what I have so far.
I am not sure if I am understanding it right.
Any suggestions will help.
#include <iostream>
using namespace std;
class Currency
{
friend ostream &operator <<(ostream &, const Currency &c);
public:
Currency();
~Currency();
void setDollars(int d);
int getDollars() const;
void setCents(int c) ;
int getCents() const;
Currency operator+ (const Currency &) const;
private:
int dollars;
int cents;
};
Currency::Currency() //default constructor
{
dollars = 0;
cents = 0;
}
Currency::~Currency() //gives space back to the system
{
delete dollars;
delete cents;
cout << "Destroying the object";
}
void Currency::setDollars(int d) //sets the dollar amount
{
dollars=d;
}
void getDollars()const //gets the dollar amount
{
return dollars;
}
void Currency::setCents(int c) //sets cents amount
{
cents=c;
}
void getCents() const //gets cents amount
{
return cents;
}
Currency operator+(const Currency &) const
{
//Addition operator, adds two Currency objects together and returns the sum
}
ostream &operator <<(ostream &out, const Currency &c)
{
out << c.dollars << "." << c.cents;
return out;
}
int main()
{
Currency anAmount;
cout << anAmount << endl;
getchar();
return 0;
}