Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
TempSpecial
//g++ 7.4.0 //TempSpecial:example of template specialization where class DayTemp with enumeration data type Day prints special message of no temperature record for weekend; //this code is created by Rezaul Hoque on May 11,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> enum Day {Sat,Sun,Mon,Tue,Wed,Thu,Fri}; template <class X, class Y=float> class DayTemp{ X w; Y temp; public: DayTemp (){} DayTemp(X a,Y c){ temp=c; w=a;} DayTemp(DayTemp& y){ temp=y.temp;w=y.w;} ~DayTemp (){} Y getTemp(){ return temp;} X getDay(){return w;} }; template<> class DayTemp <Day> { Day w; float temp; public: DayTemp (){} DayTemp(Day a,float c){ if(a==Sat || a==Sun) std::cout<<"Note!No record for weekend temperature!\n"; else {temp=c; w=a;} } ~DayTemp (){} float getTemp(){ return temp;} Day getDay(){return w;} }; int main() { const int sz=7; DayTemp<Day,float> * p; p=new DayTemp<Day,float>[sz]; p[0]={Thu,20.4}; p[1]={Wed,30}; p[2]={Mon,35}; p[3]={Tue,50}; p[4]={Sun,45}; p[5]={Sat,36}; p[6]={Fri,29}; std::cout<<"Day Temp:\n"; for(int i=0;i<sz;i++){ if(p[i].getDay()==0){ std::cout<<" NA\n";} else { std::cout<<"\n"; std::cout<<p[i].getDay()<<"\t"; std::cout<<p[i].getTemp(); std::cout<<"\n";} } delete [] p; return 0; }
run
|
edit
|
history
|
help
0
in shorted array print without duplicate o/p array
Test
Job Scheduling
MeanSDVar
Callback
Amisha
QuickSort
template
Quadratic Equation
Metodos