第一二次上机实验报告.docVIP

  • 3
  • 0
  • 约 26页
  • 2017-09-02 发布于浙江
  • 举报
第一二次上机实验报告

实验报告Ⅰ 实验目的要求 (1)使用C++语言编写简单的计算机程序,掌握C++程序从编辑、编译到运行的全过程,初步了解C++程序的特点。 (2) 掌握C++语言的数据类型(包括对各种数据类型变量的定义、初始化、赋值等)、运 算符和表达式的使用。 (3) 掌握赋值语句的使用。 (4) 掌握数据的输入输出方法。 实验设备 计算机及Visual C++开发环境 3.实验内容 (1)设计简单程序,分别计算下列表达式,式中变量由键盘输入,输出表达式的值。 1 2 3 4 5 6 (2)阅读下列程序,写出(由指定的输入)所产生的运行结果,并指出其功能。 1 #include iostream.h void main() { char ch; cin ch ; ch = ( ch = ’A’ ch = ’Z’ ) ? ( ch + 32 ) : ch ; ch = ( ch = ’a’ ch = ’z’ ) ? ( ch – 32 ) : ch ; cout ch endl; } 输入a结果为A;输入A结果为A。 其功能为:输入小写转大写,输入大写不变。 2分别输入100 40,2000 3000,1000 1000,2000 300,100 4000 运行。 #include iostream.h void main() { int m; float x; bool bi,br; cout \n int m=; cin m; bi = m 1000; cout \n float x=; cin x; br = x = 1e3; cout bi , br endl; } 运行结果分别为:0,1;1,0;0,1;1,1;1,1;0,0。 其功能是:输入整数m,大于1000输出1,否则输出0;输入浮点数x,小于等于1e3输出1,否则输出0. 3 #include iostream.h void main() { int n; cin n ; if ( n ++ 10 ) cout n endl ; else cout n -- endl ; } 输入100,输出101. 其功能是:输入整数n,输出比n大1的数。 (3)编写程序实现下列问题的求解。 1 根据随机从键盘输入的圆半径值,求圆的周长和半径并输出。 2 读入三个整数a、b、c,交换它们中的数,使a 存放b 的值,b 存放c 的值,c 存放a 的值。 3 对任意输入的四位整数,分别求出其各位数字,并按从后到前的顺序依次输出。例如,输入为1234 时,输出结果为4,3,2,1。 算法分析与设计 里面的6个小题都是简单的数学计算,用C++表达出来就可运行处结果。 (3) 1 2 3 F T F T 源代码 (1)设计简单程序,分别计算下列表达式,式中变量由键盘输入,输出表达式的值。 1 #includeiostream.h void main() { float x,a,b,c,d,y; coutenter the number:\n; cinxabcd; y=x+(a+b)/(c-d); coutthe result is:\n; couty endl; } 2 #include iostream.h #include math.h void main() { float x,y; coutenter the number:\n; cinx; y=sqrt(1+1/(x+1/(x+1))); coutthe result is:\n; couty endl; } 3 #include iostream.h #include math.h void main() { float x,y; coutenter the number:\n; cinx; y=sin(x)+cos(x)+1/tan(x); coutthe result is:\n; couty endl; } 4 #include iostream.h #include math.h void main() { float x,y,z; coutenter the numbers:\n; cinxy; z=exp(x+y)+exp(x-y); coutthe result is:\n; coutz endl; } 5

文档评论(0)

1亿VIP精品文档

相关文档