题目内容

程序完善填空:以下程序是实现一个安全计数器,防止溢出。 #include #include using namespace std; class Calculator{ public: Calculator() { value = 0 ; } ; void ______ ++ (); void operator -- (); unsigned int operator() (); private: unsigned ______ value; }; void Calculator ______ operator ++ (){ if ( value < 65535 ) value ++ ; else { cout << "\nData overflow !" << endl ; abort() ; } } void Calculator::operator --(){ if ( value > 0 ) value -- ; else{ cout << "\n Data overflow !" << endl ; abort() ; } } unsigned int Calculator::operator() (){ ______ value ; } int main(){ Calculator ______ ; int i ; for( i = 0 ; i < 5 ; i ++ ){ ++Counter ; cout << "\n Counter = " << Counter() ; } for( i = 0 ; i <= 5 ; i ++ ){ --Counter ; cout << "\n Counter = " << Counter() ; } return 0; }

查看答案
更多问题

程序完善填空:以下程序是利用指针访问类对象的成员。 #include using namespace std; class ______ { public : int x,y ; void print(){ cout << x << "," << y << endl ; } ; } ; int add( Tclass ______ ){ return ( ptf->x + ptf->y ) ; } int main(){ Tclass test,______ pt = ______ ( Tclass ) ; pt->x = 100 ; pt->y = 200 ; pt->print() ; test.x = 150 ; test.y = 450 ; test.print() ; cout << "x+y=" << add(______ ) ; return 0; }

对下标运算符“[]”,既可以重载为类成员函数,又可重载为友元函数。( )

重载运算符需要的参数个数与操作数一样多。( )

预定义的提取符和插入符都是可以重载的。( )

答案查题题库