/*烟台大学计算机学院
03.*文件名称:yueduchengxu.cpp
04.*作 者:李亚辉
05.*完成日期:2016年6月14日
06.*版 本 号:vc++6.0
07.*
08.*问题描述:阅读程序,写出运算结果,并进行理解
09.*输入描述:无
*问题输出:
10.*/
#include <iostream>
using namespace std;
class Data
{
public:
Data(int i):x(i){cout<<"A";}
~Data(){ cout<<"B";}
private:
int x;
};
class Base
{
public:
Base(int i):b1(i){cout<<"C";}
~Base(){ cout<<"D";}
private:
int b1;
};
class Derived:public Base
{
public:
Derived (int i,int j):Base(i),d1(j){
cout<<"E";
}
~Derived(){cout<<"F";}
private:
Data d1;
};
int main()
{
Derived obj(1,2);
return 0;
}
<img src="https://img-blog.csdn.net/20160614133921375?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
#include <iostream>
using namespace std;
class A
{
public:
A(){a=0;}
A (int i){a=i;}
void print(){cout<<a<<" ";}
private:
int a;
};
class B: public A
{
public:
B(){b=0;}
B(int i, int j, int k): A(i),aa(j){b=k;}
//思考:这3处出现的print,有何区别
void print() //(1)
{
A::print(); //(2)
aa.print(); //(3)
cout<<b<<endl;
}
private:
int b;
A aa;
};
int main()
{
B test[2];
test[0]=B(1,4,7);
test[1]=B(2,5,8);
for(int i=0; i<2; i++)
test[i].print();
return 0;
}
<img src="https://img-blog.csdn.net/20160614133925297?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
第十、十一周课后实践(1)
最新推荐文章于 2016-06-16 08:16:25 发布