Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
MapTel2
//g++ 7.4.0 ////////////////////////////////////////////////////////////////////////////// //MapTel2: example of map as class attribute //this code is created by Rezaul Hoque on August 05,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> #include <map> using namespace std; #include <iostream> #include <iomanip> #include <string> #include <strstream> //stream manipulator std::ostream& l(std::ostream& os) { return (os<<"\n"); } namespace Pat { void fill(char c) { std::cout.width(40); std::cout.fill(c); std::cout<<l; } void left(int n,char c){ std::cout.setf(std::ios::left); std::cout.fill(c); std::cout.width(n); } void right(int n,char c){ std::cout.setf(std::ios::right); std::cout.fill(c); std::cout.width(n); } } namespace Tel{ class Tel{ std::string name; bool update; map<std::string,std::string> l; public: Tel(){} Tel(std::string n,bool y,map<std::string,std::string> m){l=m;name=n;update=y;} Tel(Tel& c){l=c.l;name=c.name;update=c.update;} ~Tel(){} std::string getName(){return name;} bool getUpd(){return update;} map<std::string,std::string> getL(){ return l;} }; } int main() { Tel::Tel ad("X",true,{{"CBA","&%$#"},{"XYZ","###"},{"ZEN","@#%"}}); Pat::fill('&'); Pat::left(18,' '); std::cout<<"Name"<<"Add Book Updated? "<<l; Pat::left(25,'.'); std::cout<<ad.getName(); if(ad.getUpd()==1) std::cout<<"yes"<<l; else std::cout<<" no"<<l; Pat::fill('-'); std::cout<<"There are "<<ad.getL().size()<<" contacts in X's address book."<<l; //another way to initiate the instance //ad({pair<std::string,std::string>("MrCBA","&%$#")}); Pat::right(28,' '); std::cout<<"Name"<<" "<<"Number"<<l; for(auto& x: ad.getL()){ Pat::right(28,' '); std::cout<<x.first<<" : "<<x.second<<"\n";} Pat::fill('-'); std::cout<<"Mr XYZ's number is "; auto f =ad.getL().find("XYZ"); std::cout<<(*f).second<<l; Pat::fill('&'); return 0; }
run
|
edit
|
history
|
help
0
memcpy
Boost phoenix. e.g 2: functor
hh
Fibonacci
template inhertinace
top5words
11
substring search
merge without extra space Gap method ALgorithm
Vector Example