高等继续教育 / 面向对象程序设计
正确率:100%
【面向对象程序设计】模拟试题
#include<iostream.h>class goods{private: static int totalweight; int weight;public: goods(int w){ weight=w; totalweight+=weight; } goods(goods&gd){ weight=gd.weight; totalweight+=weight; } ~goods(){ totalweight-=weight; } static int gettotal(){ return totalweight; }};int goods::totalweight=0;void main(){ goods g1(50); cout<<goods::gettotal()<<endl; goods g2(100); cout<<G2.GETTOTAL()<<endl;}
考题内容:
#include<iostream.h>class goods{private: static int totalweight; int weight;public: goods(int w){ weight=w; totalweight+=weight; } goods(goods&gd){ weight=gd.weight; totalweight+=weight; } ~goods(){ totalweight-=weight; } static int gettotal(){ return totalweight; }};int goods::totalweight=0;void main(){ goods g1(50); cout<<goods::gettotal()<<endl; goods g2(100); cout<<G2.GETTOTAL()<<endl;}
#include<iostream.h>class goods{private: static int totalweight; int weight;public: goods(int w){ weight=w; totalweight+=weight; } goods(goods&gd){ weight=gd.weight; totalweight+=weight; } ~goods(){ totalweight-=weight; } static int gettotal(){ return totalweight; }};int goods::totalweight=0;void main(){ goods g1(50); cout<<goods::gettotal()<<endl; goods g2(100); cout<<G2.GETTOTAL()<<endl;}
考题内容:
#include<iostream.h>class goods{private: static int totalweight; int weight;public: goods(int w){ weight=w; totalweight+=weight; } goods(goods&gd){ weight=gd.weight; totalweight+=weight; } ~goods(){ totalweight-=weight; } static int gettotal(){ return totalweight; }};int goods::totalweight=0;void main(){ goods g1(50); cout<<goods::gettotal()<<endl; goods g2(100); cout<<G2.GETTOTAL()<<endl;}
参考答案:
佳题速递: