大学VC++习题集参考答案

  • 格式:doc
  • 大小:173.50 KB
  • 文档页数:23

参考答案

作业1 VC++基本程序结构

一、填空题

1.(1)函数 (2)main()

2.(1)函数体 (2)分号

3.(1)两或二或2 (2)大小写

4.(1)cin (2)cout

5.(1)//

6.(1)/* (2)*/

7.(1)#include

8.(1)#

9.(1).h (2).cpp

10.(1)用户(或编程者)

二、单选题

1.A 2.D 3.A 4.A 5.C 6.B 7.B 8.C 9.D

作业2 数据类型、常量、变量、运算符

一、单选题

1.D 2.B 3.B 4.D 5.D 6.D 7.C 8.B 9.B 10.C 11.C 12.B

二、阅读程序题

1.10 12 19 41

2.I say:”C++” He says:”C++ is very interstiing!”

三、程序设计题

1.#include

void main()

{char c1='C', c2='h', c3='i', c4='n', c5='a';

c1+=4;

c2+=4;

c3+=4;

c4+=4;

c5+=4;

cout<<"password is:"<

}

作业3 表达式

一、单选题

1.B 2.D 3.A 4.C 5.C 6.A 7.B 8.C

二、填空题

1. (1)35

2.(1)25

3.(1)6 (2)30

4.(1)4 (2)11

5.(1)(x+y)/(2*x*y)

6.(1)1/(a*x*x+b*y*y)

7.(1)20

8.(1)1 (2)3

9.(1)3 (2)3.2

10.(1)6 (2)60

11.(1)x

12.(1)true(或1)

13.(1)false(或0)

14.(1)x

15.(1)!x

16.(1)false(或0)

17.(1)true(或1)

三、写出下面各逻辑表达式的值

1.(1)-72.5 (2)11.5 (3)23 (4)9 (5)6 (6)6 (7)4

2.(1)24 (2)9 (3)60 (4)0 (5)0 (6)0

3.(1)0 (2)1 (3)1 (4)0 (5)1

作业4 简单的输入输出

一、阅读程序题

1.ThisisaC++program.

2.a+b=33

3.a=3 b=2 x=1.8 y=7.0 ch1=a ch2=’ ’ ch3=b

4.a=19 b=19 c=35 d=23

5.19 13 43

二、程序改错

1.1) #define pi 3.1416

2) 去掉此句r=2.8;

3) cout<

三、程序设计

1. # include

main()

{ cout<<" ***************"<<'\n';

cout<<" Hello!"<<'\n';

cout<<" ***************"<<'\n';

}

2. # include

main()

{ int s1,s2,s3,sum;

cout<<"请输入三个学生的成绩:";

cin>>s1>>s2>>s3;

sum=s1+s2+s3;

cout<<"sum="<

}

3. # include

void main(){

cout<<"please input a small character :";

char a;

cin>>a;

char b=a-32;

cout<

}

4.#include

void main ()

{float c,f;int a;

cout<<"请输入一个华氏温度:";

cin>>f;

c=(5.0/9.0)*(f-32); //注意5和9要用实型表示,否则5/9值为0

a=c*100+0.5; c= a/100.0; //保留保留两位小数,对第三小数位四舍五入

cout<<"摄氏温度为:"<

}

作业5 选择结构语句

一、填空题

1.(1)顺序结构 (2)循环结构

2.(1)常量

3.(1)if

4.(1)switch

5.(1)不停止

二、阅读程序题

1.13

2.121 a,b,c=7,12,30

3.11 14 switch end.

4.10 6 4

三、程序设计

1.//方法一:

#include

void main ( )

{int a,b,c;

cout<<"please enter three integer numbers:";

cin>>a>>b>>c;

if(a

if(b

cout<<"max="<

else

cout<<"max="<

else if (a

cout<<"max="<

else

cout<<"max="<

cout<

}

//方法二:

#include

void main ( )

{int a,b,c,temp,max ;

cout<<"please enter three integer numbers:";

cin>>a>>b>>c;

temp=(a>b)?a:b; //将a和b中的大者存入temp中

max=(temp>c)?temp:c; // 将a和b中的大者与c比较,最大者存入max

cout<<"max="<

}

2. #include

void main ()

{float score;

char grade;

cout<<"please enter score of student:";

cin>>score;

while (score>100||score<0)

{cout<<"data error,enter data again.";

cin>>score;

}

switch(int(score/10))

{case 10:

case 9: grade='A';break; case 8: grade='B';break;

case 7: grade='C';break;

case 6: grade='D';break;

default:grade='E';

}

cout<<"score is "<

}

3. #include

#include

void main ()

{char c;

int letters=0,space=0,digit=0,other=0;

cout<<"enter one line::"<

while((c=getchar())!='\n')

{if (c>='a' && c<='z'||c>='A' && c<='Z')

letters++;

else if (c==' ')

space++;

else if (c>='0' && c<='9')

digit++;

else

other++;

}

cout<<"letter:"<

other:"<

}

4.#include

void main ( )

{int x,y;

cout<<"enter x:";

cin>>x;

if (x<1)

{y=x;

cout<<"x="<

}

else if (x<10) // 1≤x<10

{y=2*x-1;

cout<<"x="<

}

else // x≥10

{y=3*x-11;

cout<<"x="<

}

cout<