Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
DailyExchRate
//g++ 7.4.0 ////////////////////////////////////////////////////////////////////////////////DailyExchRate: example of enumeration with overloaded operator & anonymous union //this code is created by Rezaul Hoque on May 19,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 <cstdint> #include <stdio.h> #include <stdlib.h> #include <string.h> 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; } struct CurRate{ //anonymous union union { Day day; }; //regular union union{ Exch currency; }money; char country[80]; char city[80]; }; int main() { struct CurRate c; strcpy(c.country, "Bangladesh"); strcpy(c.city, "Dhaka"); c.day=Thu; c.money.currency=Yuan; std::cout<<"Day Country City Exch.Rate($1)\n"; { std::cout<<c.day<<" "; std::cout<<c.country<<" "; std::cout<<c.city<<" "; std::cout<<c.money. currency<<" "; std::cout<<"\n"; } return 0; }
run
|
edit
|
history
|
help
0
Binary Search
derive* -> gcc
Sort an array of 0s, 1s and 2s
Bad Code2
773. Sliding Puzzle
TempBubbleDouble
triangle_ isosceles
is_sorted_30-Seconds-of-C++
Top view of a Binary tree
Vector Example