#include <iostream>
//Class prototype
class Cents;
class Dollars
{
private:
int m_DollarAmount;
public:
Dollars(int dollars = 1) { m_DollarAmount = dollars; }
void getDollar()
{
int x;
std::cin >> x;
void setDollar(int x);
}
void setDollar()
{
int y;
std::cin >> y;
m_DollarAmount = y;
}
//Overload to add Dollars and Cents
friend Dollars operator+(const Dollars &d1, const Cents &c1);
friend Dollars operator+(const Cents &c1, const Dollars &d1);
};
class Cents
{
private:
float m_CentsAmount;
public:
Cents(float cents = 25) { m_CentsAmount = cents; }
void getCents()
{
int cents;
std::cin >> cents;
void setCents(int cents);
}
void setCents()
{
int cents;
std::cin >> cents;
m_CentsAmount = cents;
}
friend Cents operator+(const Dollars &d1, const Cents &c1);
friend Cents operator+(const Cents &c1, const Dollars &d1);
};
Dollars operator+(const Dollars &d1, const Cents &c1)
{
//Confused here on how to add these correctly.
}
Dollars operator+(const Cents &c1, const Dollars &d1)
{
//Confused here on how to add these correctly.
}
Cents operator+(const Cents &c1, const Dollars &d1)
{
//Confused here on how to add these correctly.
}
Cents operator+(const Dollars &d1, const Cents &c1)
{
//Confused here on how to add these correctly.
}
int main()
{
//Initiating objects
Dollars UserCash;
Cents UserCoin;
std::cout << "Please enter the amount of dollars you have: ";
UserCash.getDollar();
std::cout << "Please enter the amount of cents you have: ";
UserCoin.getCents();
return 0;
}
It compiles. As of now there are no errors. I am confused on how I would add my cents to my dollars and have them wrap around at every dollar. For example if I enter one dollar and 250 cents, I want it to add to 3.50 cents. I don't know how I would do this. I don't want an answer, but a push in the right direction to work this out please!
Also, is my implementation correct on adding different types for the overloaded functions?
Thanks,
Chris

New Topic/Question
Reply



MultiQuote







|