Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
DailyExchRate
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 ////////////////////////////////////////////////////////////////////////////////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; }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.64 sec, absolute running time: 0.19 sec, cpu time: 0.02 sec, memory peak: 5 Mb, absolute service time: 0,86 sec
edit mode
|
history
|
discussion
Day Country City Exch.Rate($1) Thursday Bangladesh Dhaka 6.76 Yuan