正在加载图片...
例:定义BOX类描述立方体,定义 COLORBOX类描述彩色立方体 class boX void main( public void setwidth (int w)width=w;) COLORBOX cbox void setheight(int h)height=h; cbox setcolor(3); int getwidtho return width; 1 cbox setwidth(150) int getheight(return height; cbox setheight(100) private int width, height cout<<cbox: <<endl cout<< Color: <<cbox. getcolor( class COlorBOX public BOX cout<<Width <<cbox. getwidtho public cout<< Height: <<cbox getheight( void setcolor(int c)(color=c; 1 <<endl int getcolor((return color private int color例:定义BOX类描述立方体,定义COLORBOX类描述彩色立方体 class BOX { public: void setwidth(int w) {width=w;} void setheight(int h) {height=h;} int getwidth( ) {return width;} int getheight( ) {return height;} private: int width,height; }; class COLORBOX:public BOX { public: void setcolor(int c) {color=c;} int getcolor( ) {return color;} private: int color; }; void main( ) { COLORBOX cbox; cbox.setcolor(3); cbox.setwidth(150); cbox.setheight(100); cout<<“Cbox:”<<endl; cout<<“Color:”<<cbox.getcolor( ) <<endl; cout<<“Width:”<<cbox.getwidth( ) <<endl; cout<<“Height:”<<cbox.getheight( ) <<endl; }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有