有以下程序:
include <iostream>
using namespace std;
int f(int);
int main()
{
int i;
for(i=0;i<5;i++)
cout<<f(i)<<" ";
return 0;
}
int f(int i)
{
static int k=1;
for(;i>0;i--)
k+=i;
在下面程序的横线处填上适当的内容,使程序执行后的输出结果为ABCD。
include <iostream.h>
using namespace std;
class A
{
public: A() {cout<<'A';
};
class B:______
{
public: B() {cout<<'B';}
};
class C:______
{
public: C(} cout<<'C';}
};
class D:public B, public C
{
public: D(){cout<<'D';}
};
void main(){D obj;}
下列程序的执行结果为【 】。
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)
}
请将下列类定义补充完整,横线处应填加语句______。
class TestClass{public:void fun(){cout<<"Base::fun"<<end1;}};
class TestClass1:public TestClass
{
public:
voidfun()
{
______;//显示调用基类的fun函数
cout<<"TestClass1::fun"<<end1;
}
};
写出下列程序代码运行的结果【 】。
include<iostream.h>
class A{
public:
virtual void disp() {cout<<" calss A!" <<(end1;}
}:
class B: public A{
public:
void disp() {cout<<" class B! " <<end1:}
};
class C: public A{
public:
void disp() {cout<<"class C! " (<end1;}
};
void main() {
A a, *ptr;
B b;
C c;
a. disp();
b. disp();
c. disp();
ptr=&b;
ptr->disp();
ptr=&c;
ptr->disp():
}
A.x=2,y=2
B.x=3,y=3
C.x=2,y=3
D.x=3,y=2
长理培训客户端 资讯,试题,视频一手掌握
去 App Store 免费下载 iOS 客户端
点击加载更多评论>>