C++面向对象程序设计 第3章1例程讲解Word文档格式.docx

上传人:b****6 文档编号:18344412 上传时间:2022-12-15 格式:DOCX 页数:7 大小:14.72KB
下载 相关 举报
C++面向对象程序设计 第3章1例程讲解Word文档格式.docx_第1页
第1页 / 共7页
C++面向对象程序设计 第3章1例程讲解Word文档格式.docx_第2页
第2页 / 共7页
C++面向对象程序设计 第3章1例程讲解Word文档格式.docx_第3页
第3页 / 共7页
C++面向对象程序设计 第3章1例程讲解Word文档格式.docx_第4页
第4页 / 共7页
C++面向对象程序设计 第3章1例程讲解Word文档格式.docx_第5页
第5页 / 共7页
点击查看更多>>
下载资源
资源描述

C++面向对象程序设计 第3章1例程讲解Word文档格式.docx

《C++面向对象程序设计 第3章1例程讲解Word文档格式.docx》由会员分享,可在线阅读,更多相关《C++面向对象程序设计 第3章1例程讲解Word文档格式.docx(7页珍藏版)》请在冰豆网上搜索。

C++面向对象程序设计 第3章1例程讲解Word文档格式.docx

}

voidset_time();

voidshow_time();

private:

inthour;

intminute;

intsec;

};

voidTime:

:

set_time()

{cin>

>

hour;

cin>

minute;

sec;

}

show_time()

{cout<

<

hour<

"

minute<

sec<

endl;

intmain()

{

Timet1;

t1.show_time();

Timet2;

t2.show_time();

return0;

3-1-1

#include<

minute=0;

sec=0;

intmain()

t1.set_time();

set_time()

show_time()

cout<

3-1-2

Time();

Time:

Time()

{hour=0;

3-2

classBox

Box(int,int,int);

intvolume();

intheight;

intwidth;

intlength;

Box:

Box(inth,intw,intlen)

{height=h;

width=w;

length=len;

intBox:

volume()

{return(height*width*length);

Boxbox1(12,25,30);

Thevolumeofbox1is"

box1.volume()<

Boxbox2(15,30,21);

Thevolumeofbox2is"

box2.volume()<

3-3在例3.2的基础上,定义两个构造函数,其中一个无参数,一个有参数。

Box();

Box(inth,intw,intlen):

height(h),width(w),length(len){}

Box()

{height=10;

width=10;

length=10;

Boxbox1;

Boxbox2(15,30,25);

3-4将例3.3程序中的构造函数改用含默认值的参数,长、宽、高的默认值均为10。

Box(intw=10,inth=10,intlen=10);

Box(intw,inth,intlen)

}intBox:

Boxbox2(15);

Boxbox3(15,30);

Thevolumeofbox3is"

box3.volume()<

Boxbox4(15,30,20);

Thevolumeofbox4is"

box4.volume()<

}

3-4-2

Box(inth=10,intw=10,intlen=10);

Box(inth,intw,intlen):

height(h),width(w),length(len)

{}

 

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 其它

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1