题目内容

程序改错填空3.原程序: #include using namespace std; class f{ private: int x=0,y=0; public: void f1(int a,int b){x=a;y=b;} void get(){cout<

查看答案
更多问题

程序改错填空2.原程序: #include using namespace std; class f{ private: int x,y; public: f1(){x=0;y=0;} print(){cout<

程序改错填空1.原程序: #include using namespace std; int main(){ int x=5,y=6;const int * p=&x; *p=y; cout<

程序完善填空:用友员函数计算两点之间的距离。 #include #include ______ using namespace std; class Point{ public: Point(double xi, double yi) { X = xi ; Y = yi ;} double GetX() { return X ; } double GetY() { return Y ; } ______ double Distance(Point & a, Point & b) ; private: double X, Y ; }; double Distance(Point ______ a, Point ______ b ){ double dx = a.X-b.X ; double dy = a.Y-b.Y ; return sqrt( dx * dx + dy * dy ) ; } int main(){ ______ p1(3.0,5.0), p2(4.0,6.0) ; double d = Distance(p1,p2) ; // 调用友员函数 cout << "This distance is " << d << endl ; return 0; }

程序完善填空:以下程序是实现一个安全计数器,防止溢出。 #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; }

答案查题题库