请帮助做出答案
发布网友
发布时间:2022-05-14 03:02
我来回答
共1个回答
热心网友
时间:2024-03-16 02:30
如果有错误,请网友指出,
感谢……
61 c 63 d(不可继承) 65 d(基类中说明了虚函数 后,派生类说明的虚函数应该与基类中虚函数的参数个数相等,对应参数的类型相同)
66.d 67a
69 (对应着填上吧)
#include <iostream.h>
class Base{
public:
Base(int i) { b=i;}
//(1)
Base() {}
virtual void Print()=0;
friend void fun(Base *obj);
protected:
int b;
};
class Derive1:public Base{
public:
//(2)
Derive1() {}
void Print()
{ cout<<"Derive1's Print() called."<<endl;
}
};
class Derive2:public Base{
//(3)
public:
Derive2() {}
void Print()
{ cout<<"Derive2's Print() called."<<endl;
}
};
void fun(Base *obj) //(4)
{
obj->Print();
}
void main()
{
// (5)
Derive1 *d1=new Derive1();
Derive2 *d2=new Derive2();
fun(d1);
fun(d2);
}
71 a
72 //主要出错的地方:1.静态成员变量需要类外初始化2.不能通过类名::调用非静态成员函数,必须通过类的对象调用
#include <iostream.h>
class Point
{
public:
void output()
{
init();
}
static void init()
{ x=6;
y=6;
}
private:
static int x,y;
};
int Point::x=0;
int Point::y=0;
void main()
{
Point::init();
Point a;
a.output();
}
75.
class Complex{
public:
Complex(double r=0.0,double i=0.0) { real=r;imag=i; }
const Complex operator +(Complex);
const Complex operator -(Complex,Complex);
private:
double real,imag;
};
const Complex operator +(Complex c)
{
Complex d;
d.real=c.real+real;
d.imag=c.imag+imag;
return d;
}
const Complex operator -(Complex c1,Complex c2)
{
return Complex( ⑦ );
76.题目没有说明要干什么,程序本身无错误