C实验报告剖析Word格式文档下载.docx
《C实验报告剖析Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《C实验报告剖析Word格式文档下载.docx(25页珍藏版)》请在冰豆网上搜索。
iostream>
string>
usingnamespacestd;
boolisMatch(strings);
intmain(){
strings;
while
(1){
cin>
>
s;
if(pare("
000000"
)==0){
break;
}
if(isMatch(s)){
cout<
<
"
Symmetry"
<
endl;
else{
Notsymmetry"
}
return0;
}
boolisMatch(strings){
intlen=s.length();
for(inti=0;
i<
len/2;
i++){
if((s[i]>
='
a'
&
s[i]<
z'
)&
(s[len-i-1]>
A'
s[len-i-1]<
Z'
)){
if(s[i]!
=(s[len-i-1]+('
-'
))){
returnfalse;
}
elseif((s[i]>
=(s[len-i-1]-('
elseif(((s[i]=='
{'
s[len-i-1]=='
}'
continue;
'
['
]'
('
)'
=s[len-i-1]){
returntrue;
【运行结果】
图3实验一运行结果
实验1-2面向对象编程技术
(1)
理解面向对象的的程序设计思想。
定义一个时间类Time,能提供和设置由时、分、秒组成的时间,并编出应用程序,要求包括定义时间对象,设置时间,输出该对象提供的时间。
并请将类定义作为界面,用多文件结构实现之。
//Time.h
classTime
{
public:
inth;
intm;
ints;
voidinputT();
voidchangeT();
voidoutputT();
};
//Time.cpp
#include"
Time.h"
voidTime:
:
inputT()
begin:
inta,b,c;
std:
cout<
Inputtime(H:
M:
S)\n"
;
cin>
a>
b>
c;
if(c>
60||c<
0)
{
std:
cout<
Wrongtime!
Pleasesetagain!
\n"
gotobegin;
else
if(b>
60||b<
{
std:
;
gotobegin;
else
if(a>
24||a<
{
std:
gotobegin;
elseif(a==24)
if(b!
=0||c!
=0)
{
std:
gotobegin;
}
else
h=a;
m=b;
s=c;
else
h=a;
m=b;
s=c;
changeT()
charp;
Doyouwannachangetime?
(Y/N):
\n"
p;
if(p=='
n'
||p=='
N'
)
Thankyouforyourusing!
begin1:
inta,b,c;
if(c>
gotobegin1;
if(b>
gotobegin1;
if(a>
gotobegin1;
elseif(a==24)
if(b!
=0||c!
=0)
{
std:
gotobegin1;
}
else{
h=a;
m=b;
s=c;
outputT()
Outputtime(H:
h<
"
m<
//testmain.cpp
voidmain(void)
Timetime1;
time1.inputT();
time1.outputT();
time1.changeT();
图4实验二运行结果
实验3面向对象程序设计
(2)
改写程序f0815.cpp,使之含有构造函数,拷贝构造函数和析构函数。
并对主函数和矩阵向量的乘法也进行改写。
对于第91和92行,合并成“multiply(ve,ma).display();
”使之不会产生内存泄漏。
【实验程序】
//实验三
//改写f0815.cpp
fstream>
string.h>
classVector
int*v;
//指向一个数组,表示向量
intsz;
intsize(){returnsz;
Vector(int);
Vector(constVector&
s);
int&
operator[](int);
voiddisplay();
~Vector();
Vector:
Vector(ints)
sz=s;
if(s<
cerr<
badVectorsize.\n"
exit
(1);
v=newint[s];
Vector(constVector&
s)
inti;
sz=s.sz;
v=newint[sz];
for(i=0;
sz;
i++)
v[i]=s.v[i];
~Vector()
delete[]v;
int&
Vector:
operator[](inti)//引用返回的目的是返回值可以做左值
if(i<
0||i>
=sz)
Vectorindexoutofrang.\n"
returnv[i];
voidVector:
display()
++i)
cout<
v[i]<
cout<
classMatrix
int*m;
intszl,szr;
Matrix(int,int);
Matrix(constMatrix&