Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
StackTel
//g++ 7.4.0 ////////////////////////////////////////////////////////////////////////////// //StackTel: example of tuple as class attribute //this code is created by Rezaul Hoque on August 08,2022; update:22:00; //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 <tuple> #include <list> #include <stack> using namespace std; //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{ public: std::string name; bool update; std::stack<int> t; list<tuple<std::string,int>> l; Tel(){} Tel(std::string n,bool y,std::stack<int> a, list<tuple<std::string,int>> m){l=m;name=n;update=y;t=a;} Tel(Tel& c){l=c.l;name=c.name;update=c.update;t=c.t;} ~Tel(){} std::stack<int> getS(){return t;} void pop(){ t.pop();} std::string getName(){return name;} bool getUpd(){return update;} list<tuple<std::string,int>> getL(){ return l;} }; } int main() { stack<int> k; k.push(2); k.push(1); tuple<std::string,int> t1; t1=make_tuple ("XYZ",111); tuple<std::string,int> t2; t2=make_tuple ("CTZ",121); Tel::Tel ad("X",true,k,{t1,t2}); Pat::fill('@'); Pat::left(18,' '); std::cout<<"Name"<<"id"<<" ContName"<<" Number"<<l; Pat::left(20,' '); for(auto thisTup:ad.getL()){ tuple<std::string, int> tuple=thisTup; Pat::left(18,' '); std::cout<<ad.getName()<<" "<<ad.getS().top()<<" "; ad.pop(); std::cout<<get<0>(thisTup)<<" "; std::cout<<get<1>(thisTup)<<l; } Pat::fill('@'); return 0; }
run
|
edit
|
history
|
help
0
SayHi
11340 v3.1
Conjuntos - Contar caracteres únicos
10 wizards-DFS_vector
CharSearch
basic TREAP
infix to postfix v 5.0 (with exponent support)
runtime template mode processor
MyString
dijkstra's algo