- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
C程序设计实验5
《》
实验报告
名: 钟玲
学 号:
专 业: 通信工程
实验时间: 2016.11.15
杭州电子科技大学
通信工程学院
一、实验目的实验内容
Sum() //计算某学生三门课总成绩
Print() //输出某学生学号、姓名和成绩
modify() //修改某学生学号、姓名和成绩
(3)在主函数中,先定义一个学生类对象数组,再通过for循环给对象数组赋上实际值,最后输出对象数组各元素的值。
三、实验过程#includeiostream
using namespace std;
class A
{
public:
A(){ coutA::A()called.\n; }
~A(){ coutA::~A()called.\n; }
};
class B:public A
{
public:
B(int i)
{
coutB::B()called.\n;
buf=new char[i];
}
virtual ~B()
{
delete []buf;
coutB::~B() called.\n;
}
private:
char *buf;
};
int main()
{
B b(10);
return 0;
}
实验结果:
程序2
#includeiostream
using namespace std;
class A{
public:
A(int a, int b):x(a), y(b){ coutA constructor...endl; }
void Add(int a, int b){ x+=a; y+=b; }
void display(){ cout(x,y); }
~A(){coutdestructor A...endl;}
private:
int x, y;
};
class B:private A{
private:
int i, j;
A Aobj;
public:
B(int a, int b, int c, int d):A(a, b), i(c), j(d), Aobj(1,1)
{ coutBconstructor..endl; }
void Add(int x1, int y1, int x2, int y2)
{
A::Add(x1, y1);
i+=x2; j+=y2;
}
void display(){
A::display();
Aobj.display();
cout(i,j(endl;
}
~B(){ coutdestructor B...endl;}
};
int main()
{
B b(1,2,3,4);
b.display();
b.Add(1,3,5,7);
b.display();
return 0;
}
实验结果:
程序3
#includeiostream
using namespace std;
class A{
public:
A(int a):x(a){ coutA constructor...xendl; }
int f(){ return ++x; }
~A(){coutdestructor A...endl;}
private:
int x;
};
class B:private virtual A{
private:
int y;
A Aobj;
public:
B(int a, int b, int c):A(a), y(c), Aobj(c)
{ coutB constructor..yendl; }
int f(){
A::f();
Aobj.f();
return ++y;
}
void display(){
coutA::f()\tAobj.f()\tf()endl;
}
~B(){ coutdestructor B...endl;}
};
class C: public B{
public:
C(int a, int b, int c): B(a, b, c), A(0){ coutC constructor...endl; }
};
class D:public C, public virtual A{
public:
D(int a, int b, int
您可能关注的文档
最近下载
- 一种窄冠带条多层缠绕搭接量计算方法及应用.pdf VIP
- 2025年融媒体中心全媒体记者招聘考试笔试试题(附答案).docx VIP
- L10010022《病理学》课程标准.pdf VIP
- 【必备收藏】幼儿建构区游戏指导完整版课件-.pptx VIP
- 主题策略-【专题报告】CANSLIM4.0策略:叠加企业生命周期.docx VIP
- 最新人教版九年级化学演示、分组实验统计表.xls VIP
- GB 50797-2012 光伏发电站设计规范.docx VIP
- 插画设计-PPT课件(全).pptx
- 古代牝户手抄本雨花香PPT课件.pptx VIP
- 【大单元整体教学设计】人教版初中化学九年级上册 第三单元物质构成的奥秘 课题1 分子和原子.doc VIP
文档评论(0)