- 1、本文档共11页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
北邮c第七章实验作业
基础题
1.
#include iostream
using namespace std;
class csample
{
double a;
csample(){a=2.5};
public:
csample(int val){};
~csample(){};
};
2.
#includeiostream
using namespace std;
class cube
{
public:
cube(); //定义构造函数
~cube(); //定义析构函数
int volume(); //定义整型变量表示立方体体积
private:
int height,width,depth; //定义私有数据成员长宽高
};
cube::cube()
{
height=2;
width=20;
depth=20;
coutConstructor called.endl;
}
cube::~cube()
{
coutDestructor called.endl;
}
int cube::volume()
{
return height*width*depth;
}
void main()
{
cube cubeone; //定义对象
cout立方体的体积为:cubeone.volume()endl;
}
3.
#includeiostream
using namespace std;
class CCounter
{
int value;
public:
void CCountr()
{ cout CCounter Constructor1 endl;
value = 0;
}
void CCountr(int val)
{ cout CCounter Constructor2 endl;
value = val;
}
~CCounter() { cout CCounter Destructor endl; }
};
class CExample
{ int value;
public:
CCounter car;
CExample()
{
cout CExample Constructor1 endl;
value = 0;
}
CExample(int val)
{ cout CExample Constructor2 endl;
value = val;
}
~CExample() { cout CExample Destructor endl; }
void Display() { cout value= value endl; }
};
void main()
{
CExample obj(350);
obj.Display();
}
次序为:CExample(int val)- ~CExample()-~CCounter() 次数:各一次。
4.
#includeiostream
using namespace std;
class Point
{
protected:
int x;
public:
int Getx(){return x;}
int Y;
void init(int a,int b){x=a;Y=b;}
int Gety(){return Y;}
void Setx(int a){x=a;}
void Sety(int b){Y=b;}
};
void main()
{
Point A,B;
A.init(25,27);
B.init(29,31);
coutA.x=A.Getx()endl;
coutB.x=B.Getx()endl;
coutA.Y=A.Yendl;
coutA.y=A.Gety()endl;
coutB.y=B.Yendl;
coutB.y=B.Gety()endl;
}
出错原因:使用成员函数未打括号,定义成员函数时,未定义形式参数。
5.
#includeiostream
using namespace std;
class base
{
private:
int i;
static int k; //定义静态变量
public:
base(){i=0;k++;}//定义构造函数
void Display
您可能关注的文档
- 北师大大学英语(三).docx
- 北师大初一下册Lesson 21.ppt
- 北师大版 模块八 unit 23 lesson 3.ppt
- 北师大初二英语Lesson 6.ppt
- 北师大版 U15L1 life-long learning.ppt
- 北京科技大学小学期C++实践报告.doc
- 北师大版2014-2015中考数学模拟试题.doc
- 北师大版 高一 model 4 综合能力检测.doc
- 北师大版m5-u15-l1 life-long learning.ppt
- 北师大版 M2U5L1 A True Performer.ppt
- DB32∕T 1706-2011 梭鱼和脊尾白虾混养技术规范.docx
- DB32∕T 2096-2012 种猪登记管理规程.docx
- DB32∕T 1791-2011 甘薯采收与贮藏技术规程.docx
- DB32∕T 2081-2012 海蜇人工繁殖技术规程.docx
- DB32∕T 972-2006 实验动物笼器具 独立通气笼盒(IVC)系统.docx
- DB32∕T 564-2010 饲料用小球藻粉.docx
- DB32∕T 1582-2010 奶牛繁育技术档案建立规范.docx
- DB32∕T 971-2006 实验动物笼器具 饮水瓶.docx
- DB32∕T 1508-2009 苏柳172扦插育苗技术规程.docx
- DB32∕T 1945-2011 豇豆大棚早春栽培技术规程.docx
文档评论(0)