实验一 Visual C++ 集成环境
实验内容
(一)程序改错
1.
(1)无法运行
一个工程文件中main 函数(2)将第二个
一个工程文件中
main 函数
(3)同一个工程文件只能有一个
2.
(1)/* 一个简单的程序 */
(2)void main()
(3)}
3.
(1)int a,b,c;
(2)a=2;
(3)c=a*b;
(二)完善程序
1.
(1)year
(2)month
(3)day
2.
(1)c
(2)a*a+b*b
(3)c
3.
(1)4
(2)4*a
(3)s
课后练习
函数
实验二 数据类型、运算符和表达式
课前练习
208700
Abs3 Class _else sum my_class
3block a+b for fun(4) a-b
实验内容
(一)程序改错
1.
(1)int x1,x2,x3,x4;
(2)scanf("%d,%d",&a,&b);
(3)C=x4*1000+x2*100+x3*10+x1;
2.
程序1:
2 2
error C2065: 'a1' : un declared identifier
变量a1没有定义
sum=a+b+c
J
error C2146: syn tax error : miss ingbefore ide ntifier 'pri ntf
printf 语句之前缺少分号
sum=a+b+c;
0 error(s), 0 warnin g(s)
a=1b=3c=2 sum=6
程序2:
2 2
error C2065: 'sum': undeclared identifier
变量sum没有定义
int sum=a+b;
1
error C2086: 'c' : redefinition
变量c重复定义
c=a+b+sum;
a=1b=3 sum=8
在同一个函数体内,变量要先定义后使用,但不能重复定义
程序3:
1
error C2106: '=' : left opera nd must be l-value
赋值符号左边参数错误
c=a+b;
c=4
赋值符号左边只能是变量,不能是常量或表达式
3.
(1)t=a;
(2)a=b;;
(3)printf("a=%d\tb=%d\n",a,b);
(二)完善程序
1.
(1)intn
(2)” %d,&n
(3)s
2.
(1)float s
(2)(float)a/b
(3)%f
3.
(1)#include
(2)pow(x,y)
(3)“ %lf ” ,s
课后练习
19. 5 和 4
double(删除最后"语句”两字)
double
a=3(回车)
实验三if选择结构语句
课前练习
1.
9
0
2.
11
0
3.
(1)
n%2==0
(2)
n %2!=0
(3)
a>=' O'
&& a<=
'9'
(4)
a>=' a'
&& a<=
z
(5)
a>=' A'
&& a<=
'Z'
(6)
(a>=' a'
&& a<=
'z' ) || (a>=
'A && a<= ' Z)
(7)
(x
((x>10) &
& (x<=20))
(8)
a%b!=0
9)a*b>0
30 40
实验内容
一)程序改错
1.
(1)scanf("%d",&t);
(2)if(t%5==0 && t%7==0)
(3)else
2.
(1)char y;
(2)if(x==0)
(3)printf("%c\n",y);
3.
(1)if(x==m)
(2){ printf("Wrong\n");
(3)printf("Too low\n");}
二)完善程序
1.
(1)#include<>
(2)(-b+sqrt(d))/(2*a);
(3)sqrt(fabs(d))/(2*a);
2.
(1)c>='a'&& c<='u'
(2)c>='v'&& c<='z'
(3)c=c+5-26;
3.
(1)c>='a'&& c<='z'
(2)c>='A'&& c<='Z'
(3)else
课后练习
,0
22.!
实验四switch
开关语句
课前练习
411
2.
if((k==1)||(k==2)
prin tf("a\n");
else if((k==3)||(k==4)||(k==5))
prin tf("b\n");
else
prin tf("c\ n");
3.
switch (x)
{
case 1:
case 2:
case 3:pri ntf("x\ n" );break;
case 19:
case 20:
ca