int main() {
A e(1,2); e.show(); B d(3,4,5,6); d.fun(); d.show(); d.f1(); return 0; }
8以下程序的执行结果是 a=0b=0c=0
a=1b=0c=0 a=1b=3c=0 a=1b=3c=5
#includeviostream>
using namespace std; class A { public:
A(){a=0;b=0;} A(int i){a=i;b=0;} A(int i,int j){a=i;b=j;}
void display(){coutvv\int a; int b; };
class B:public A { public:
B(){c=O;} B(int i):A(i){c=0;} B(int i,int j):A(i,j){c=O;} B(int i,int j,int k):A(i,j){c=k;}
void display\
{display。; coutvv\} private: int c; };
int main() {B b1; B b2(1); B b3(1,3); B b4(1,3,5); b1.display1(); b2.display1(); b3.display1(); b4.display1(); return 0; }
9、以下程序的执行结果是 ____________ 30,30 ________ #includeviostream>
using namespace std; class Point {
int x,y; public:
Point(int vx,int vy){x=vx;y=vy;} Point() {x=0;y=0;}
Point operator+(Point p1) {
Point p; int px=x+p.x;
int py=y+p.y; return Point(px,py); }
Point operator-(Point p1) Point p;
int px=x-p1.x; int py=y-p1.y; return Point(px,py); }
void print() {
coutvvxvv ” ”,vvyvvendl; } };
int main() {
Point p1(10,10),p2(20,20); p1= p1+p2; p1.print(); return 0; }
10、以下程序的执行结果是
base class
_________________________________derive class
derive2 class #includeviostream> using namespace std; class base
{ public: virtual void who() {
coutvv \} };
class derive:public base { public: void who() {
coutvv \derive class\vvendl; } };
class derive2:public base { public:
void who()
{
coutvv \
};
int main() {
base obj1,*p; derive obj2; derive2 obj3; p=&obj1; p->who(); p=&obj2; p->who(); p=&obj3; p->who(); return 0;
f1 function of base f2 function of base f3 function of base f1 function of derive f2 function of base f4 function of derive
#include
public: }
11以下程序的执行结果是 virtual void f1() 、
{
cout<<\f1 function of base\< virtual void f2() { cout<<\f2 function of base\< virtual void f3() { cout<<\f3 function of base\< virtual void f4() { cout<<\f3 function of base\< }; class derive:public base { void f1() { coutvv ”1 function of derive ”vvendl;