下列程序的执行结果为【 】。
include <iostream. h>
class Point
{
public:
Point(double i, double j) { x=i; y=j;}
double Area() const { return 0.0;}
private:
double x, y;
};
class Rectangle: public Point
{
public:
Rectangle(double i, double j, double k, double 1)
double Area() const {return w * h;}
private:
double w, h;
};
Rectangle: :Rectangle(double i, double j, double k. double 1): Point(i,j).
{
w=k, h=1
}
void fun(Point &s)
{
cout<<s. Area()<<end1;
}
void main( )
{
Rectangle rec(3.0, 5.2, 15.0. 25.0);
fun(rec)
}
第1题:
下列程序的输出结果为
Object id=0
Obiect id=1
请将程序补充完整。
include<iostream>
using namespace std;
class Point
{
public:
Point(int xx=O,int yy=O){X=xx;Y=yy;countP++;}
~Point(){countp--;}
int GetX()(return X;)
int GetY(Xremm Y;)
static void GetC(){cout<<"Objcetid="<<countp<<endl;}
private:
int X,Y;
static int countP;
}:
【 】。 //静态数据成员的初始化
int main()
{
Point::GetC();
Point A(4,5);
A.GetC()
return 0;
}
第2题:
有如下程序: #inClude<iostream> using namespaCe std; Class Point{ publiC: statiC int number; publiC: Point( )t.number++;} ~Point( ){number--;} }; , int P0int::number=0; int main( ){ Point *ptr: Point A,B; Point*ptr_point=new Point[3]; ptr=ptr_point;’ } Point C; Cout<<Point:::number<<endl; delete[]ptr; return 0; } 执行这个程序的输出结果是( )。
A.3
B.4
C.6
D.7
第3题:
分析以下程序的执行结果【 】。
include <iostream. h>
class S{
int A[10];
public:
int &operator () (int);
};
int &S: :operator() (int x) {
return A[x];
}
void main() {
S a;
int i,j;
for (i=0; i<10; i++)
a(i)=i*2;
for (i=0; i<10; i++)
cout<<a(i)<<" ";
cout<<end1; }
第4题:
下列程序的输出结果为
Object id=0
Object id=1
请将程序补充完整。
include <iostream>
using namespace std;
class Point
{
public:
Point(int xx=0,int yy=0) {X=xx;Y=yy;countP++;}
~Point(){countP--;}
int GetX(){return X;}
int GetY(){return Y;}
static Void GetC(){cout<<"Object id="<<countP<<endl;}
private:
int X,Y;
static int countP;
};
______ //静态数据成员的初始化
int main ()
{
Point::GetC();
Point A(4,5);
A.GetC();
return 0;
}
第5题:
有以下程序: #include<iostream> #include<math> using namespace std; class point { private: double x; double y; public: point(double a,double B) { x=a; y=b; } friend double distance (point a,point B) ;
A.1
B.5
C.4
D.6