C实验报告剖析Word格式文档下载.docx

上传人:b****2 文档编号:13404343 上传时间:2022-10-10 格式:DOCX 页数:25 大小:68.74KB
下载 相关 举报
C实验报告剖析Word格式文档下载.docx_第1页
第1页 / 共25页
C实验报告剖析Word格式文档下载.docx_第2页
第2页 / 共25页
C实验报告剖析Word格式文档下载.docx_第3页
第3页 / 共25页
C实验报告剖析Word格式文档下载.docx_第4页
第4页 / 共25页
C实验报告剖析Word格式文档下载.docx_第5页
第5页 / 共25页
点击查看更多>>
下载资源
资源描述

C实验报告剖析Word格式文档下载.docx

《C实验报告剖析Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《C实验报告剖析Word格式文档下载.docx(25页珍藏版)》请在冰豆网上搜索。

C实验报告剖析Word格式文档下载.docx

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&

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

当前位置:首页 > 高等教育 > 农学

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

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