Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ProPriceTemp
//g++ 7.4.0 //ProPriceTemp: example of template stack and array //this code is created by Rezaul Hoque on May 13,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> namespace Banner{ template<class T> class Deco{ T* item; int up; int sz; public: Deco(int len){sz=len; item= new T[sz];} ~Deco(){delete [] item;} void add(const T& a){ item[++up]=a;} void message(){std::cout<<"\nExample of Template Stack & Array\n";} T getIt(){return item[up--];} }; } namespace ProdPrice{ template<class X, class Y> class Prod{ X* p; Y* p2; int size; public: Prod(X a[], Y c[]); void display(X a[],Y c[]); }; template<> Prod<std::string,float>::Prod(std::string a[],float c[]){ int size= 5; p=new std::string[size]; for(int k= 0;k<size;k++) p[k]=a[k]; p2=new float[size]; for(int k= 0;k<size;k++) p2[k]=c[k]; } template<> void Prod<std::string,float>::display(std::string a[],float c[]){ int size=5; for(int k= 0;k<size;k++){ std::cout<<*(a+k)<<"\t"; std::cout<<*(c+k)<<" \n";} } } int main() { Banner::Deco<char> s(25); s.message (); for (int h=0;h<25;h++){ s.add('~'); } for (int h=0;h<25;h++){ std::cout<<s.getIt(); } int size=5; std::string a[5]={"\nRice","Lentil","Oil","Potato","Chicken"}; float c[5]={58,60,180,25,165}; ProdPrice::Prod<std::string,float> f(a,c); f.display(a,c); return 0; }
run
|
edit
|
history
|
help
0
Laborator 2 SD
Project Euler - 113
rstring
c2p
Buenos Amigos
Test 16(2020)
tAquireSignalProcessor
Equilateral triangle
fundamental type sizes
cpp base