Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PriQTel2
//g++ 7.4.0 ////////////////////////////////////////////////////////////////////////////// //PriQTel2:example of tuple as class attribute //this code is created by Rezaul Hoque on August 09,2022;update: 22:30 //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 <queue> 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); } } 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() { priority_queue<tuple<std::string,int>,vector<tuple<std::string,int>>,greater<tuple<std::string,int>>> Q; tuple<std::string,int> t1; t1=make_tuple ("XYZ",151); tuple<std::string,int> t2; t2=make_tuple ("CBA",121); Tel ad("X",true,{t1,t2}); Q.push(t1); Q.push(t2); Pat::fill('@'); Pat::left(18,' '); std::cout<<"Name"<<"ContName"<<" Number"<<l; Pat::left(20,' '); for(auto thisTup:ad.getL()){ while(!Q.empty()){ tuple<std::string, int> tuple=Q.top(); Pat::left(18,' '); std::cout<<ad.getName(); std::cout<<get<0>(tuple)<<" "; std::cout<<get<1>(tuple)<<l; Q.pop(); } } Pat::fill('@'); return 0; }
run
|
edit
|
history
|
help
0
Test 12(2020)
HotelVec
ammmma
cppPyClassMethod
SVGAnimated Value
factor
LIS
СПКИ АП КЭП 3
Primality test Fermat primality test
AVL - ith element