当前位置:首页 > C++面向对象程序设计实验指导书谭浩强
{ }
CDerive d; d.print(); CBase b; b.print();
问题一:以上程序有两大错误,试指出来,并改正之? 答:
2.理解下面的程序,并在VC++6.0下运行查看结果,回答程序后面的问题。
#include
public:
CBase(int a) :a(a) { cout<<\ }
~CBase() { cout<<\ }
void print() { cout<<\ } protected: int a; };
class CDerive : public CBase {
public:
CDerive(int a, int b,int c) :CBase(a),b(b),c(c) { cout<<\ }
~CDerive() { cout<<\ }
void print() {
CBase::print(); cout<<\ cout<<\ } private:
CBase b; int c; };
void main() {
CDerive d(1,2,3); -----------------------------------------------------① d.print(); }
问题一:以上程序的输出结果是什么,说明为什么? 答: 问题二:① 答:
6.2.2 程序设计
1.定义点CPoint类作为基类,在此基础上派生出直线CLine类和圆CCircle类,并要求基类和各派生类具有以下特点:
a.CLine类含有计算直线长度和斜率的成员函数; b.CCircle类含有计算圆面积的成员函数。
实验七 派生与继承—多重派生
7.1 实验目的
1.理解多重派生的定义;
2.理解多重派生中构造函数与析构函数的调用顺序; 3.理解多重派生中虚拟基类的作用;
7.2 实验内容
1.理解下面的程序,并在VC++6.0下运行查看结果,回答程序后面的问题。
class CBase1 {
public:
CBase1(int a) :a(a) { cout<<\< ~CBase1() { cout<<\< void print() { cout<<\< class CBase2 { public: CBase2(int b) :b(b) { cout<<\< ~CBase2() { cout<<\< void print() { cout<<\< class CDerive : public CBase1, public CBase2 { public: CDerive() { cout<<\< ~CDerive() { cout<<\< void print() { CBase1::print(); CBase2::print(); b1.print(); b2.print(); cout<<\< CBase1 b1; CBase2 b2; int c; }; void main() { CDerive d; d.print(); } 问题一:改正以上程序中存在的错误,并分析该程序的输出结果。 2.理解下面的程序,并在VC++6.0下运行查看结果,回答程序后面的问题。 #include \ class CBase { public:
共分享92篇相关文档