Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ListTel
//g++ 7.4.0 ////////////////////////////////////////////////////////////////////////////// //ListTel: example of tuple as class attribute //this code is created by Rezaul Hoque on August 07,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 <tuple> #include <list> 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{ std::string name; bool update; list<tuple<std::string,int>> l; public: Tel(){} Tel(std::string n,bool y, list<tuple<std::string,int>> 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;} list<tuple<std::string,int>> getL(){ return l;} }; } int main() { 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,{t1,t2}); Pat::fill('@'); Pat::left(18,' '); std::cout<<"Name"<<"ContName"<<" Number"<<l; Pat::left(20,' '); for(auto thisTup:ad.getL()){ tuple<std::string, int> tuple=thisTup; Pat::left(18,' '); std::cout<<ad.getName(); std::cout<<get<0>(thisTup)<<" "; std::cout<<get<1>(thisTup)<<l; } Pat::fill('@'); return 0; }
run
|
edit
|
history
|
help
0
Sort array of 0's and 1's
Sort 0's 1's 2's
My Tuple class
GET ALL PRIME FACTORS OF A NUMBER
ttt
Khadijah Alshehhi
MoaJhalMury
test
CPP - Pointers - Ex.3
perimetar na triagolnik