Created
May 31, 2017 20:14
-
-
Save kgashok/0768d6eaf4b5cdbee03db6bcbd2e2584 to your computer and use it in GitHub Desktop.
dollarToRupee created by kgashok - https://repl.it/I0Qr/0
This file contains hidden or 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 <iostream> | |
using namespace std; | |
class RupeeAmount { | |
float valueInRupees; | |
public: | |
RupeeAmount() { valueInRupees = 0; } | |
RupeeAmount(float val) { valueInRupees = val; } | |
operator float() { return valueInRupees / 70; } | |
void display() { cout << "Rupee value: " << valueInRupees << endl; } | |
}; | |
class DollarAmount { | |
float valueInDollars; | |
public: | |
DollarAmount() { valueInDollars = 0; } | |
DollarAmount(float value) { valueInDollars = value; } | |
operator RupeeAmount() { return valueInDollars * 70.0; } | |
void display() { cout << "Dollar value: " << valueInDollars << endl; } | |
}; | |
int main() { | |
DollarAmount d(100); | |
RupeeAmount r; | |
r = d; // calls operator DollarAmount function | |
r.display(); | |
float dollarEquiv; | |
dollarEquiv = r; // calls operator float function | |
cout << "Dollar Value : " << dollarEquiv << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment