文档库 最新最全的文档下载
当前位置:文档库 › experienment_reportB

experienment_reportB

experienment_reportB
experienment_reportB

oooooo 实验报告

课程 计算机程序设计 实验名称 计算机程序设计第 页 共 页 系 别 oooooooo 实 验 日 期 2011年 9月 日 专业班级 组别_____________实 验 报 告 日 期 年 月 日

姓 名 彼得大变态 学号 oooooooo 报 告 退 发 ( 订正 、 重做 ) 同 组 人_________________________________ 教 师 审 批 签 字

一.实验目的

参见实验大纲

二.实验内容

(-)实验题目一:1、第2章第2题(必做题):输入两个角度值x,y,计算如下式子的值。 )cos()

sin(y x y x ++

1.程序源代码

#include

#include

double abc(double x,double y)

{

double z;

z=(sin(fabs(x)+fabs(y)))/(pow((cos(fabs(x+y))),0.5));

return z;

}

double main()

{

double x1,y1,resu;

cout <<"Please input x&y";

cin >>x1>>y1;

resu=abc(x1,y1);

cout <<"The result is"<

return 0;

}

2.实验结果

为验证程序正确性,不妨设X=pi/12,Y=-pi/12即X=0.261,Y=-0.261; )cos()

sin(y x y x ++的结果应约为0.5。

(二)实验题目二:2、第2章第3题(必做题):编写一个程序,要求完成以下要求:

(1)提示用户输入任意的三个小数;

(2)显示这三个小数;

(3)将这三个小数相加,并显示其结果;

(4)将结果按四舍五入方法转换成整数并显示。

1.程序源代码

#include

int main()

{

cout<<"Please input three decimal fractions";

float a,b,c,d,g;

cin>>a>>b>>c;

cout<<"The number you have input are "<

cout<

int e,f;

e=a+b+c;

g=d-e;

if(g<0.5)

f=e;

else

f=e+1;

cout<<"The result is "<

return 0;

}

2.实验结果

(三)实验题目三:3、仿照本章课件例题,任意输入3个小写字母组成的单词,采用凯撒加密方法:每个字母用其后第5个字母代替形成密文,然后输出密文。(必做题)

1.程序源代码

#include

#include

int abc(char a)

{

int e;

int d;

int c;

char b;

c=a;

d=c-96+5;

e=d%26;

if(e==0)

{ b='z';}

else

{ b=e+96;}

return b;

}

int main()

{

char a1,b1,c1,d1,e1,f1;

cout<<"please input three char :";

cin>>a1>>b1>>c1;

d1=abc(a1);

e1=abc(b1);

f1=abc(c1);

cout<<"the result is:"<

return 0;

}

2.实验结果

(四)实验题目四:4、输入一个4位十进制数,求其每位数字的立方之和。例如:输入2456,则输出23+43+53+63=8+64+125+216=413。注意只要求输出红色算式结果。(必做题)

1.程序源代码

#include

#include

int main()

{

int a,b,c,d,e;

cout<<"Please input a number(1000<=x<=9999)";

cin>>a;

if(a>=1000&&a<=9999)

b=a/1000;

c=(a-b*1000)/100;

d=(a-b*1000-c*100)/10;

e=(a-b*1000-c*100-d*10);

int f,g,h,i,j;

f=pow(b,3);

g=pow(c,3);

h=pow(d,3);

i=pow(e,3);

j=f+g+h+i;

cout<

return 0;

}

2.实验结果

(五)实验题目五:5、编写程序计算下列二元一次方程组的根:AX + BY = C

DX + EY = F

通过键盘输入6个系数,然后计算求解,最后输出方程的根。(必做题)

1.程序源代码

#include

#include

int main()

{

double a,b,c,d,e,f,g,h;

cout<<"Please input six numbers:";

cin>>a>>b>>c>>d>>e>>f;

g=(a*f-c*d)/(a*e-b*d);

h=(c-b*g)/a;

cout<