Skip to content

Instantly share code, notes, and snippets.

@kgashok
Created May 31, 2017 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kgashok/0768d6eaf4b5cdbee03db6bcbd2e2584 to your computer and use it in GitHub Desktop.
Save kgashok/0768d6eaf4b5cdbee03db6bcbd2e2584 to your computer and use it in GitHub Desktop.
dollarToRupee created by kgashok - https://repl.it/I0Qr/0
#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