Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
DailyExchRate2
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//g++ 7.4.0 ////////////////////////////////////////////////////////////////////////////////DailyExchRate2: example of enumeration with overloaded operator using class //this code is created by Rezaul Hoque on May 20,2022; //contact:jewelmrh@yahoo.com;Dhaka,Bangladesh;https://rezaulhoque.wordpress.com,https://hoquestake.blogspot.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; ////////////////////////////////////////////////////////////////////////////// #include <iostream> #include <string> enum Day {Sat,Sun,Mon,Tue,Wed,Thu,Fri}; enum Exch {Taka, Eur,Inr,Pound,Yen,Ruble,Yuan}; //enumeration with overloaded operator std::ostream& operator<<(std::ostream& outs, Day j) { switch(j){ case Sat: outs<<"Saturday"; break; case Sun: outs<<"Sunday"; break; case Mon: outs<<"Monday"; break; case Tue: outs<<"Tuesday"; break; case Wed: outs<<"Wednesday"; break; case Thu: outs<<"Thursday"; break; case Fri: outs<<"Friday"; break; } return outs; } std::ostream& operator<<(std::ostream& outs, Exch cr) { switch(cr){ case Taka: outs<<"88.0 Taka"; break; case Eur: outs<<"0.95 Euro"; break; case Inr: outs<<"77.50 Indian Rupee"; break; case Pound: outs<<"0.81 Pound"; break; case Yen: outs<<"128.82 Yen"; break; case Ruble: outs<<" 63.40 Ruble"; break; case Yuan: outs<<"6.76 Yuan"; break; } return outs; } class CutRate{ Day day; Exch currency; std::string country; std::string city; public: CutRate(){} CutRate(Day j,std::string c,std::string v,Exch m){ day=j;country=c;city=v;currency=m;} CutRate(CutRate& s){ day=s.day;country=s.country;city=s.city;currency=s.currency;} ~CutRate(){} Day getDay(){return day;} std::string getCountry(){return country;} std::string getCity(){return city;} Exch getCur(){return currency;} }; int main() { CutRate c(Thu,"Bangladesh","Dhaka",Yuan); std::cout<<"Day Country City Exch.Rate($1)\n"; { std::cout<<c.getDay()<<" "; std::cout<<c.getCountry()<<" "; std::cout<<c.getCity()<<" "; std::cout<<c.getCur()<<" "; std::cout<<"\n"; } return 0; }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.63 sec, absolute running time: 0.26 sec, cpu time: 0.02 sec, memory peak: 5 Mb, absolute service time: 1,73 sec
edit mode
|
history
|
discussion
Day Country City Exch.Rate($1) Thursday Bangladesh Dhaka 6.76 Yuan