c++实验报告一II.docx

上传人:b****0 文档编号:17182979 上传时间:2023-07-22 格式:DOCX 页数:8 大小:15.86KB
下载 相关 举报
c++实验报告一II.docx_第1页
第1页 / 共8页
c++实验报告一II.docx_第2页
第2页 / 共8页
c++实验报告一II.docx_第3页
第3页 / 共8页
c++实验报告一II.docx_第4页
第4页 / 共8页
c++实验报告一II.docx_第5页
第5页 / 共8页
c++实验报告一II.docx_第6页
第6页 / 共8页
c++实验报告一II.docx_第7页
第7页 / 共8页
c++实验报告一II.docx_第8页
第8页 / 共8页
亲,该文档总共8页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

c++实验报告一II.docx

《c++实验报告一II.docx》由会员分享,可在线阅读,更多相关《c++实验报告一II.docx(8页珍藏版)》请在冰点文库上搜索。

c++实验报告一II.docx

c++实验报告一II

实验一

(1)实验报告

1.实验目的及要求

(1)理解基本的解题技巧,掌握用自顶向下、逐步求精的过程设计算法。

(2)熟练掌握if/else语句和switch语句的使用。

(3)熟练掌握while语句、do/while语句和for语句的使用以及区别。

(4)掌握break和continue程序控制语句的使用。

2.实验设备

计算机、MicrosoftVisualC++

3.实验内容

(1)阅读下列程序,写出(由指定的输入)所产生的运行结果,并指出其功能。

<1>

#include

voidmain()

{

intm,n;

m=1000;

n=850;

cout<<“\n(“<

while(m!

=n){

while(m>n){

m=m–n;

cout<<‘(‘<

}

while(m

n=n–m;

cout<<‘(‘<

}

}

cout<<“\n”<

}

<2>

#include

voidmain()

{

intm,n,k;

m=1000;

n=45;

cout<<“\n(“<

’<

k=0;

while(m>=n){

m=m–n;

k=k+1;

}

cout<

}

<3>

#include

voidmain()

{

inti;

for(i=1;i<=5;i++){

if(i%2)

cout<<‘*’;

else

continue;

cout<<‘#’;

}

cout<<“$\n”;

}

<4>

#include

voidmain()

{

inta=1,b=10;

do{

b-=a;

a++;

}while(b--<=0);

cout<<“a=”<

}

(2)编写程序实现下列问题的求解。

<1>求解下面函数的值。

e

x+y

x<0,y<0

z=ln(x+y)1≤x+y〈10

log10

|x+y|+1

4.算法分析与设计:

(2).<1>

#include

#include

main()

{

float x,y,z;

cout<<"Please input the value of x and y:

";

cin>>x>>y;

if((x<0)&&(y<0))

{

z=exp(x+y);

       cout<

}

else if((x+y>=1)&&(x+y<10))

{

z=log(x+y);

    cout<

}

else

z=log10(abs(x+y)+1);

cout<

}

<2>.1)

#include

main()

{

int x=0,i;

for(i=1;i<=100;i++)

      x=x+i;

cout<<"1+2+3+...+100="<

return 0;

}

<2>.2)

#include

int jiechen(int a)

{

int w,y=1;

for(w=1;w<=a;w++)

y=y*w;

return y;

}

main()

{

int x=0,i;

for(i=1;i<=7;i++)

x=x+jiechen(i);

cout<<"1!

+2!

+...7!

="<

return 0;

}

<2>.3)

#include

main()

{

int s=0,i;

for(i=1;i<=20;i++)

s=s+(i*2)*(i*2-1);

cout<<"1*2+3*4+...39*40="<

return 0;

<2>.4)

#include

#include

double jiechen(double a)

{

double q=1;

int w;

for(w=1;w<=a;w++)

q=q*w;

return q;

}

main()

{

double x,y,n;

int i;

cout<<"输入两个数n,x \n";

cin>>n>>x;

for(i=1;i<=n;i++)

x=x+(pow((-1),(n+1))*pow(x,(2n-1)))/(jiechen(2n-1));

y=x;

cout<<"y="<

return 0;

}

<3>.

#include

main()

{

int i,n,j,k;

for(i=1;i<=11;i++)

{

for(j=1;j<=(11-i);j++)

cout<<" ";

        for(n=1;n<=i;n++)

cout<<2*n-1;

for(k=1;k<=i-1;k++)

cout<<2*(n-k-1)-1;

cout<<'\n';

}

return 0;

}

<4>.

#include

main()

{

int i,j;

for(i=1;i<=10;i++)

for(j=1;j

cout<<"<"<"<<"  ";

return 0;

}

<5>.

#include

main()

{

int i;

for(i=12;i<=99;i++)

if(i/10<(i-i/10*10))

cout<

for(i=100;i<=999;i++)

if(i/100<(i-i/100*100)/10&&(i-i/100*100)/10<(i-i/100*100)-(i-i/100*100)/10*10)

cout<

for(i=1000;i<=10000;i++)

if(i/1000<(i-i/1000*1000)/100&&(i-i/1000*1000)/100<(i-i/1000*1000-(i-i/1000*1000)/100*100)/10&&(i-i/1000*1000-(i-i/1000*1000)/100*100)/10<(i-i/1000*1000-(i-i/1000*1000)/100*100-(i-i/1000*1000-(i-i/1000*1000)/100*100)/10*10))

cout<

return 0;

}

6.#includemain(){intx;cout<<"输入一个数\n";cin>>x;inti;cout<

测试用例数据1+2+…+100=

功能测试用例计算阶乘

功能A描述计算公式

用例目的:

测试算法设计的正确性

前提条件:

算法正确

期望的输出/响应:

5050

实际情况

5050

6.测试结论:

程序设计正确

7.测试过程和运行结果分析

代码测试过程中测试用例期望的输出/响应和实际情况不一致的原因分析及解决方案:

实验的代码要清楚,把算法想清楚。

8、参考资料

TurboCForWindows

报告者:

林铭霞

2012/3/6

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

当前位置:首页 > 总结汇报 > 学习总结

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2