实验报告模板C++实验报告.docx
《实验报告模板C++实验报告.docx》由会员分享,可在线阅读,更多相关《实验报告模板C++实验报告.docx(10页珍藏版)》请在冰豆网上搜索。
![实验报告模板C++实验报告.docx](https://file1.bdocx.com/fileroot1/2022-12/7/a77fbbff-4662-48cd-969d-afad7a19ff8c/a77fbbff-4662-48cd-969d-afad7a19ff8c1.gif)
实验报告模板C++实验报告
【实验报告模板】C++实验报告
各位读友大家好,此文档由网络收集而来,欢迎您下载,谢谢
C++实验报告
实验1-1 过程化编程
【实验目的】
理解、掌握过程化编程程序设计思想。
【实验内容】
1.程序填空,练习类、对象、继承的定义和实现方法。
2.根据程序运行结果,补充完整程序。
【实验要求】
我们在进行英语阅读的时候,会发现一个有趣的现象:
有些字串是左右对称的,如madam。
我们把这种字串称为symmetrytext即“对称文”。
现在有若干航字串,每一行可以由数字、标点符号、空格符以及英文字符(包括大小写)组成。
要你帮忙编程判断是否是对称文,否则,就不能最大限度地发现有趣现象了。
输入说明
每个字串为一行,每行结束以回车符为标志,可能有上百上千行业说不定。
当字串为“000000”时,输入结束。
英文字符不区分大小写,即Madam亦为对称文。
不要忘了“{}”也是互为对称的。
输出说明
如果是对称文,则输出“Symmetry”,否则输出“Notsymmetry”。
每个结论占一行。
图1
图2
【程序代码】#include
#include
usingnamespacestd;
boolisMatch(strings);
intmain(){
}
boolisMatch(strings){
{
}elseif((s[i]>=‘A’&&s[i]=‘a’&&s[len-i-1]=‘a’&&s[i]=‘A’&&s[len-i-1]>
s;
if((“000000”)==0){ }if(isMatch(s)){ }else{ }cout‘))){ }elseif(((s[i]==‘[‘&&s[len-i-1]==‘]’))){ }elseif(((s[i]==‘(‘&&s[len-i-1]==‘)’))){ }else{ }if(s[i]!
=s[len-i-1]){ }returnfalse;
continue;
continue;
continue;
continue;
returntrue;
【运行结果】
图3实验一运行结果
实验1-2 面向对象编程技术
(1)
最全面的范文参考写作网站【实验目的】
理解面向对象的的程序设计思想。
【实验内容】
定义一个时间类Time,能提供和设置由时、分、秒组成的时间,并编出应用程序,要求包括定义时间对象,设置时间,输出该对象提供的时间。
并请将类定义作为界面,用多文件结构实现之。
【程序代码】//
#include
classTime{
public:
};
//
#include““
#include
voidTime:
:
inputT()
{
begin:
inta,b,c;
std:
:
cout>
a>>
b>>
c;
if(c>
60||c
60||b
24||a>
p;
if(p==‘n’
||p==‘N’){ }std:
:
coutC++实验报告
{begin1:
inta,b,c;
std:
:
cout>
a>>
b>>
c;
if(c>
60||c
60||b
24||a
voidmain(void)
{
}Timetime1;
();
();
();
();
{ }std:
:
cout
#include
#include
usingnamespacestd;
classVector
{
};
Vector:
:
Vector(ints)
{
}
Vector:
:
Vector(constVector&
s)
{
}inti;
sz=;
v=newint[sz];
for(i=0;
i=sz){ }returnv[i];
cerrC++实验报告
}inti,j;
ifstreamin(““);
//文件名intx,y;
in>>
x>>
y;
Matrixma(x,y);
for(i=0;
i>
(i,j);
in>>
x;
Vectorve(x);
for(i=0;
i>
ve[i];
【实验结果】
图5实验三运行结果
实验4 面向对象程序设计(3)
【实验要求】
请在程序中的日期类的基础上,实现一个可以进行加天数操作获得另一个日期,以及进行日期减日期操作获得相隔天数的日期类,并进行应用程序设计:
创建和两个日期,并计算中间相隔的天数,前者加上300天会是什么日子呢?
范文TOP100【实验程序】一、头文件部分
#pragmaonce
//classDatewithyear-month-dayversion
#include
#include
usingnamespacestd;
classDate{
};
二、函数定义intyear,month,day;
Date(intn=1){ }intymd2i()const;
voidi2ymd(intn);
staticconstinttians[];
Date(conststring&
s);
Date(inty,intm,intd):
year(y),month(m),day(d){}Dateoperator+(intn)const{ } Date&
operator+=(intn){ }Date&
operator++(){ }intoperator-(Date&
d)const{ }boolisLeapYear()const{ }friendostream&
operator
#include
#include
usingnamespacestd;
constintDate:
:
tians[]={0,31,59,90,120,151,181,212,243,273,304,334};
constintY400=146097;//numberofdaysof400years
constintY100=36524;//numberofdaysof100years
constintY4=1461;//numberofdaysof4years
Date:
:
Date(conststring&
s){(转载于:
在点网)
}
voidDate:
:
i2ymd(intabsDay){
}
intDate:
:
ymd2i()const{
intyearDay=(year-1)*365+(year-1)/4-(year-1)/100+(year-1)/400;
returnyearDay+tians[month-1]+(isLeapYear()&&
month>
2)+day;
year=absDay/Y400*400;
inty=absDay%Y400;//被400年除得的天数if(y==Y400-1){ }year+=y/Y100*100;
y%=Y100;
year+=y/Y4*4;
y%=Y4;
if(y==Y4-1){ }year+=y/365;
y%=365;
if(y==0){ }year++;
boolleap=isLeapYear();
for(month=1;
monthtians[month]+(month>=2&&
leap);
month++);
day=y-tians[month-1];
month=12,day=31;
return;
month=12,day=30;
return;
month=12,day=30;
return;
year=atoi((0,4).c_str());
month=atoi((5,2).c_str());
day=atoi((8,2).c_str());
}
ostream&
operator
usingnamespacestd;
intmain(){
Dated1(2005,8,21);
Dated2(2008,8,8);
cout
#include
usingnamespacestd;
classDate{
};
intyear,month,day;
staticconstinttians[];
Date(intn=1){ }intymd2i()const;
voidi2ymd(intn);
Date(conststring&
s);
Date(inty,intm,intd):
year(y),month(m),day(d){}Dateoperator+(intn)const{ }Date&
operator+=(intn){ }Date&
operator++(){ }intoperator-(Date&
d)const{ }boolisLeapYear()const{ }friendostream&
operatorC++实验报告
二、头文件
#pragmaonce
//
#include”“
#include
#include
usingnamespacestd;
classWDate:
publicDate{
protected:
WDateoperator+(intn)const{returnDate:
:
operator+(n);
}WDate&
operator+=(intn){Date:
:
operator+=(n);
return*this;
}WDate&
operator++(){return*this+=1;}intgetWeekDay(){returnymd2i()%7;
}//0:
Sunday,1:
Monday,etc..intoperator-(WDate&
wd)const{returnymd2i()-();
}friendostream&
operator
#include
#include
usingnamespacestd;
constintDate:
:
tians[]={0,31,59,90,120,151,181,212,243,273,304,334};
constintY400=146097;//numberofdaysof400years
constintY100=36524;//numberofdaysof100years
constintY4=1461;//numberofdaysof4years
Date:
:
Date(conststring&
s){
}
voidDate:
:
i2ymd(intabsDay){
year=absDay/Y400*400;
inty=absDay%Y400;//被400年除得的天数if(y==Y400-1){ month=12,day=30;
year=atoi((0,4).c_str());
month=atoi((5,2).c_str());
day=atoi((8,2).c_str());
} }return;
year+=y/Y100*100;
y%=Y100;
year+=y/Y4*4;
y%=Y4;
if(y==Y4-1){ }year+=y/365;
y%=365;
if(y==0){ }year++;
boolleap=isLeapYear();
for(month=1;
monthtians[month]+(month>=2&&
leap);
month++);
day=y-tians[month-1];
month=12,day=31;
return;
month=12,day=30;
return;
intDate:
:
ymd2i()const{
}
ostream&
operator
2)+day;
四、
//
//ClassWDatewithyear-month-dayVersion
#include”“
#include
usingnamespacestd;
ostream&
operator
usingnamespacestd;
intmain(){
WDated1(2005,8,21);
WDated2(2008,8,8);
cout<<
d1<<
”\n”;
cout<<
d2<<
”\n”;
}
【实验结果】上页
各位读友大家好,此文档由网络收集而来,欢迎您下载,谢谢