Another approach is using map of enumeration and string:
Code:#include <cstdlib> #include <iostream> #include <map> #include <string> enum resolution {low,medium,hight}; std::map<resolution,std::string > resMap; //class class display{ int width,height; resolution res; public: void set(int w,int h){width=w; height=h;} void get(int &w,int &h){w=width; h=height;} void setR(resolution r){res=r;} std::string getR(){ return resMap[res];} }; int main(int argc, char *argv[]) { resMap[low]= "low"; resMap[medium]= "medium"; resMap[hight]= "high"; display dm[3]; int i,w,h; dm[0].set(640,480); dm[1].set(800,600); dm[2].set(1600,1200); dm[0].setR(low); dm[1].setR(medium); dm[2].setR(hight); std::cout<<"We have:"<<std::endl; for(int i=0;i<3;i++){ dm[i].get(w,h); std::cout<<dm[i].getR()<<" "<<w<<"x"<<h<<std::endl; } system("PAUSE"); return 0; }




Reply With Quote