Hi, I'm taking a class on C++ and we just went over classes and objects. We have a homework assignment due and I was wondering if someone could check over my work because some of this class stuff is hard to wrap my head around.
Here's the homework assignment (it's a diagram I have to follow):
http://i28.photobucket.com/albums/c216/aldodesigns/class.jpg
The first question says: Write a class declaration based on the diagram and my code for that is,
#include <iostream>
using namespace std;
class money
{
private:
int dollars;
int cents;
void adjust(int, int);
public:
money(int d = 0, int c = 0) : dollars(d), cents(c) {}
int getDollars() const;
int getCents() const;
void setDollars(int d);
void setCents (int c);
void print(ostream & o)const;
operator + (const money rhs) const;
};
The second question asks for a default constructor that sets the dollar and cent values to 0, this is my code:
money(int d = 0, int c = 0) : dollars(d), cents(c) {}
Lastly, it asks for the code for the method, print
void money::print(ostream & o)
{
o << "$" << d << ". " << setfill('0') << setw(2) << c << endl;
return;
}