Created
September 10, 2012 12:25
-
-
Save phlandscape/3690635 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Euro.h" | |
//constructor | |
Currency::Currency(string name): | |
value(0), | |
Inter_Name(name) | |
{ | |
} | |
Currency::Currency(string name,double x): | |
value(x), | |
Inter_Name(name) | |
{ | |
} | |
Currency::Currency(const Currency& other): | |
Currency(other.GetName(),other.GetVal()) | |
{ | |
} | |
//destructor | |
Currency::~Currency() | |
{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef CURRENCY_H | |
#define CURRENCY_H | |
#include <iostream> | |
using std::string; | |
using std::ostream; | |
#define EuroToDollar 1.28961 | |
#define DollarToEuro 0.77543 | |
class Currency | |
{ | |
public: | |
//operator overloading | |
friend ostream& operator<<(ostream &out, const Currency &ThisVery); | |
//getter | |
inline double GetVal() const {return value;} | |
inline string GetName() const {return Inter_Name;} | |
//setter | |
inline void SetVal(const double x){this->value = x;} | |
protected: | |
//constructor | |
Currency(string); | |
Currency(string,double); | |
Currency(const Currency& other); | |
//destructor | |
virtual ~Currency(); | |
//variables | |
double value; | |
private: | |
//variables | |
const string Inter_Name; | |
}; | |
//friend operators | |
inline ostream& operator<<(ostream &out, const Currency &ThisVery){ | |
out << ThisVery.GetVal() << " " << ThisVery.GetName(); | |
return out; | |
} | |
#endif // CURRENCY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Euro.h" | |
#include "Dollar.h" | |
//constructor | |
Dollar::Dollar(): | |
Currency("Dollar") | |
{ | |
} | |
Dollar::Dollar(double x): | |
Currency("Dollar",x) | |
{ | |
} | |
//destructor | |
Dollar::~Dollar() | |
{ | |
} | |
//operator overloading | |
Dollar& Dollar::operator+(const Dollar& rhs){ | |
this->value += rhs.GetVal(); | |
return *this; | |
} | |
Dollar& Dollar::operator+(double x){ | |
this->value += x; | |
return *this; | |
} | |
Dollar& Dollar::operator-(const Dollar& rhs){ | |
this->value -= rhs.GetVal(); | |
return *this; | |
} | |
Dollar& Dollar::operator-(double x){ | |
this->value -= x; | |
return *this; | |
} | |
Dollar& Dollar::operator=(const Dollar& rhs){ | |
if(this == &rhs) return *this; | |
this->value = rhs.GetVal(); | |
return *this; | |
} | |
Dollar& Dollar::operator=(const Euro& rhs){ | |
this->value = rhs.GetVal() * EuroToDollar; | |
return *this; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef DOLLAR_H | |
#define DOLLAR_H | |
#include "Currency.h" | |
class Euro; | |
class Dollar : public Currency | |
{ | |
public: | |
//constructor | |
Dollar(); | |
Dollar(double); | |
//destructor | |
~Dollar(); | |
//operator overloading | |
Dollar& operator+(const Dollar& rhs); | |
Dollar& operator+(double x); | |
Dollar& operator-(const Dollar& rhs); | |
Dollar& operator-(double x); | |
Dollar& operator=(const Dollar& rhs); | |
Dollar& operator=(const Euro& rhs); | |
protected: | |
private: | |
}; | |
#endif // DOLLAR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Euro.h" | |
#include "Dollar.h" | |
//constructor | |
Euro::Euro(): | |
Currency("Euro") | |
{ | |
} | |
Euro::Euro(double x): | |
Currency("Euro",x) | |
{ | |
} | |
//destructor | |
Euro::~Euro() | |
{ | |
} | |
//operator overloading | |
Euro& Euro::operator+(const Euro& rhs){ | |
this->value += rhs.GetVal(); | |
return *this; | |
} | |
Euro& Euro::operator+(double x){ | |
this->value += x; | |
return *this; | |
} | |
Euro& Euro::operator-(const Euro& rhs){ | |
this->value -= rhs.GetVal(); | |
return *this; | |
} | |
Euro& Euro::operator-(double x){ | |
this->value -= x; | |
return *this; | |
} | |
Euro& Euro::operator=(const Euro& rhs){ | |
if(this == &rhs) return *this; | |
this->value = rhs.GetVal(); | |
return *this; | |
} | |
Euro& Euro::operator=(const Dollar& rhs){ | |
this->value = rhs.GetVal() * DollarToEuro; | |
return *this; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef EURO_H | |
#define EURO_H | |
#include "Currency.h" | |
class Dollar; | |
class Euro : public Currency | |
{ | |
public: | |
//constructor | |
Euro(); | |
Euro(double); | |
//destructor | |
~Euro(); | |
//operator overloading | |
Euro& operator+(const Euro& rhs); | |
Euro& operator+(double x); | |
Euro& operator-(const Euro& rhs); | |
Euro& operator-(double x); | |
Euro& operator=(const Euro& rhs); | |
Euro& operator=(const Dollar& rhs); | |
protected: | |
private: | |
}; | |
#endif // EURO_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Currency.h includes | |
^ iostream | |
* | |
* | |
*/ | |
#include "Dollar.h" | |
#include "Euro.h" | |
int funct(); | |
int funct(); | |
int funct(){return 1;} | |
using std::cout; | |
using std::endl; | |
int main(){ | |
Euro eOne(2); | |
Dollar dTwo(2); | |
Dollar nDol; | |
Euro nEur; | |
nDol = eOne; | |
nEur = dTwo; | |
eOne = nDol; | |
dTwo = nEur; | |
cout << nDol << " and " << eOne << endl; | |
cout << nEur << " and " << dTwo << endl; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment