C++简单编程Word下载.docx
- 文档编号:13749453
- 上传时间:2022-10-13
- 格式:DOCX
- 页数:55
- 大小:25.41KB
C++简单编程Word下载.docx
《C++简单编程Word下载.docx》由会员分享,可在线阅读,更多相关《C++简单编程Word下载.docx(55页珍藏版)》请在冰豆网上搜索。
voidarray:
:
set_time()
inti;
cout<
<
"
请输入10个整数:
endl;
for(i=0;
i<
10;
i++)
{
cin>
>
integer[i];
}
请输出10个整数:
integer[i]<
}
max()
max1=integer[0];
for(i=1;
if(integer[i]>
max1)
max1=integer[i];
show_time()
请输出最大的数值max1:
endl<
max1<
intmain(void)
arraymax_integer;
max_integer.set_time();
max_integer.max();
max_integer.show_time();
return0;
/*
请完善该程序,在类中增加一个对数据成员赋初值的成员函数set_value,
调试并运行。
给出了类定义的头文件student.h,包含成员函数定义的源文件student.cpp
以及包含主函数的源文件main.cpp。
(1)类定义的头文件student.h中的内容:
(2)成员函数定义的源文件student.cpp中的内容:
classStudent
{public:
voiddisplay();
voidset_value();
intnum;
charname[20];
charsex[10];
voidStudent:
set_value()
请分别输入学号、姓名、性别:
num>
name>
sex;
display()
{cout<
num:
num<
name:
name<
sex:
sex<
Studentstu1;
stu1.set_value();
stu1.display();
功能描述:
声明一个时钟类,包含小时Hour、分钟Minutes、秒Second等3个数据成员,
有2个公有成员函数,分别是:
时间设置函数SetTime
(intNewH=0,intNewM=0,intNewS=0)
和时间显示函数ShowTime()。
在主函数main()中。
利用时间设置函数SetTime设置时间,
当调用时间显示函数ShowTime()时就显示设置的时间。
classclock
clock(intNewH=0,intNewM=0,intNewS=0);
voidShowTime();
intHour;
intMinutes;
intSecond;
clock:
clock(intNewH,intNewM,intNewS)
Hour=NewH;
Minutes=NewM;
Second=NewS;
voidclock:
ShowTime()
现在的时间为:
Hour<
'
-'
Minutes<
Second<
clocktime_1(12,34,12);
time_1.ShowTime();
clocktime_2(12,34);
time_2.ShowTime();
clocktime_3(12);
time_3.ShowTime();
clocktime_4;
time_4.ShowTime();
定义一个图书类Book,类中包括name(书名)、author(作者)和sale(销售量)
三个数据成员以及带三个参数的(所有参数都具有默认值)
构造函数、析构函数、设置信息的函数和显示信息的函数。
编写相应程序对所定义的类进行测试。
string.h>
classBook
Book(stringna="
C++"
stringau="
li"
intsa=0):
name(na),author(au),sale(sa){}
~Book();
stringname;
stringauthor;
intsale;
Book:
~Book()
析构函数被调用!
voidBook:
author:
author<
sale:
sale<
BookBook_1;
Book_1.show_time();
BookBook_2("
datastructure"
"
YanWeiMin"
29);
Book_2.show_time();
需要求3个长方柱的体积,请编写一个基于对象的程序。
数据成员包括length(长)
witch(宽)、height(高)。
要求用成员函数实现以下功能:
1)由键盘分别输入3个长方柱的长宽高;
2)计算长方柱的体积;
3)输出3个长方柱的体积。
请编程序,上机调试并运行。
classmath
voidvolume();
floatlength;
floatwitch;
floatheight;
floatv;
voidmath:
请输入长方体的长、宽、高:
length>
witch>
height;
volume()
v=length*witch*height;
输出长方体的体积:
v<
mathvolume_1;
volume_1.set_time();
volume_1.volume();
volume_1.show_time();
mathvolume_2;
volume_2.set_time();
volume_2.volume();
volume_2.show_time();
mathvolume_3;
volume_3.set_time();
volume_3.volume();
volume_3.show_time();
找出一个整型数组中的元素的最大值。
1、用类来实现,数据和函数都封装在类里面
2、写为一个多文件的程序:
(1)将类定义放在头文件arraymax.h中;
(2)将成员函数定义放在源文件arraymax.cpp中;
(3)主函数放在源文件file1.cpp中。
请写出完整的程序,调试并运行。
classarraymax
voidarraymax:
arraymaxmax_integer;
定义一个日期类Date,包含年、月、日三个数据成员,
以及一个求第二天日期的成员函数和输出日期的成员函数。
classDate
voidsecond_time();
intyear;
intmonth;
intday;
voidDate:
请分别输入年、月、日:
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C+ 简单 编程