C++程序设计真题及答案(双语)

C++程序设计真题及答案(双语)
C++程序设计真题及答案(双语)

《PROGRAMMING IN C++》试卷( A )

Part Ⅰ. Multiple Choice (40 points)

1. Which one of the following is not one of the three major phases in the life cycle of a computer

program?

A) the problem-solving phase B) the management phase C) the implementation phase D) the maintenance phase

2. Given that x is a float variable and num is an int variable containing the value 5, what will x contain after execution of the following statement: x = num + 2;

A) 7 B) 7.0 C) 5 D) nothing; a compile-time error occurs 3. Which of the following translates a program written in a high-level language into machine

code?

A) a mouse B) a compiler C) an operating system D) an editor

4. One of the following statements does not show a proper use of the sqrt library function.

Which one is the wrong statement? (Assume all variables are float variables.) A) y = 3.85 * sqrt(x + 4.2); B) cout << sqrt(x);

C) sqrt(25.0 * x); D) y = sqrt(sqrt(x)) - x;

5. Of the following components of a computer, which one stores data and instructions? A) input device B) output device C)arithmetic/logic unit D) memory unit

6. If plant is a string variable and the statement

plant = "Dandelion";

is executed, then the value of the expression plant.find('d') is A) 0 B) 1 C) 3 D) 4 7. Given the three lines of input data 111 222 333 444 555 666 777 888 999

what value is read into gamma by the following code? (All variables are of type int.) cin >> alpha;

cin.ignore(500, '\n'); cin >> beta >> gamma;

A) 333 B) 444 C) 555 D 777

8. Given the following code:

string name1; string name2;

name1 = "Mark"; name2 = "Mary";

what is the value of the relational expression string1 < string2 ? A) true B) false

C) none; it causes a compile-time error D) none; it causes a run-time error

9. Which assignment statement could be used to store the letter A into the char variable

someChar?

A) someChar = "A"; B) someChar = A; C) someChar = 'A'; D) a, b, and c above

10. What is the missing If condition in the following code fragment? The program is

supposed to halt if the input file does not exist. ifstream inFile;

inFile.open("myfile.dat"); if ( )

{ cout << "Cannot open input file." << endl; return 1; }

A) inFile B) myfile.dat C) !inFile D) !myfile.dat

11. If x is a float variable containing a positive value, which of the following statements

outputs the value of x, rounded to the nearest integer?

A) cout << int(x); B) cout << int(x) + 0.5; C) cout << int(x + 0.5); D) cout << x + int(0.5);

12. In order to test the boundaries of the following condition, what data values would

you use for the variable alpha? ( alpha is of type int.) alpha >= 1

A) 0, 1, and INT_MAX B) 1, 2, and INT_MAX

C) INT_MIN, 1, and INT_MAX D) INT_MIN, 0, 1, and INT_MAX 13. A value can be stored into a variable by execution of:

A) an input statement B) an output statement C) an assignment statement D) a and c above

14. Which of the following is not a reason why programmers write their own functions? A) to help organize and clarify programs

B) to make programs execute faster than they would with sequential flow of control C) to allow the reuse of the same code (function) within the same program D) to allow the reuse of the same code (function) within another program

15. If p is a Boolean variable, which of the following logical expressions always has the

value false? A) p && p B) p || p C) p && !p D) p || !p

班级: 姓名: 学号:

答 题 不 允 许 超 越 边 线 否 则 无 效

16. Which of the following is the correct function heading for a parameterless function named

PrintStars?

A) void PrintStars B) void PrintStars; C)void PrintStars( ) D)void PrintStars( );

17.Given the function prototype

bool IsGreater( int, int );

which of the following statements use valid calls to the IsGreater function? (The data types of the variables are suggested by their names.)

A) someBoolean = IsGreater(someInt, 8);

B) if (IsGreater(5, someInt)) intCounter++;

C) while (IsGreater(inputInt, 23)) cin >> inputInt;

D) all of the above

18. Given the function heading

void GetNums( int howMany, float& alpha, float& beta )

which of the following is a valid function prototype for GetNums?

A) void GetNums( int howMany, float& alpha, float& beta );

B) void GetNums( int, float&, float& );

C) void GetNums( int, float, float );

D) A and B above

19. If the int variables i, j, and k contain the values 10, 3, and 20, respectively, what is the value of the following logical expression: j < 4 || j == 5 && i <= k

A) 3 B) false C) 20 D) true

20. If an ampersand (&) is not attached to the data type of a parameter, then the corresponding

argument can be:

A) a constant B) a variable name

C) an arbitrary expression D) all of the above

21. Which type of loop would be most appropriate for solving the problem "Calculate the sum

of all the odd integers in a data file of unknown length"?

A) a count-controlled loop B) a flag-controlled loop

C) a sentinel-controlled loop D) an EOF-controlled loop

22.What is the output of the following code fragment if the input value is 4? (Be careful here.)

int num; int alpha = 10;

cin >> num;

switch (num)

{ case 3 : alpha++;

case 4 : alpha = alpha + 2;

case 8 : alpha = alpha + 3;

default : alpha = alpha + 4;

}

cout << alpha << endl;

A) 10 B) 14 C) 12 D) 19 23. What is the value of someInt after control exits the following loop?

someInt = 273;

while (someInt > 500)

someInt = someInt - 3;

A) 270 B) 273 C) 497 D) 500

24. If a variable alpha is accessible only within function F, then alpha is either

A) a global variable or a parameter of F.

B) a local variable within F or a parameter of F.

C) a global variable or an argument to F.

D) a local variable within F or an argument to F.

25. What is the output of the following C++ code fragment? (Be careful here.)

int1 = 120;

cin >> int2; // Assume user types 30

if ((int1 > 100) && (int2 = 50))

int3 = int1 + int2;

else

int3 = int1 - int2;

cout << int1 << ' ' << int2 << ' ' << int3;

A) 120 30 150 B) 120 30 90 C) 120 50 170 D) 120 50 70

26. What is the output of the following code fragment? (loopCount is of type int.)

for (loopCount = 1; loopCount > 3; loopCount++)

cout << loopCount << ' ';

cout << "Done" << endl;

A) Done B) 1 Done C) 1 2 Done D) 1 2 3 Done

27. Given the input data

25 10 6 -1

what is the output of the following code fragment? (All variables are of type int.) sum = 0;

cin >> number;

while (number != -1)

{ cin >> number;

sum = sum + number;

}

cout << sum << endl;

A) 15 B) 41 C) 16 D) no output--this is an infinite loop

28. What is the output of the following code fragment? (All variables are of type int.)

n = 2;

for (loopCount = 1; loopCount <= 3; loopCount++)

do

n = 2 * n;

while (n <= 4);

cout << n << endl;

A) 4 B) 8 C) 16 D) 32

29. In C++, a function prototype is

A) a declaration but not a definition. B) a definition but not a declaration.

C) both a declaration and a definition. D) neither a declaration nor a definition.

30.Given the declarations

struct BrandInfo

{ string company;

string model;

};

struct DiskType

{ BrandInfo brand;

float capacity;

} myDisk;

what is the type of https://www.360docs.net/doc/ad3301841.html,pany[2] ?

A) char B) string C) BrandInfo D) none of the above

31. A function SomeFunc has two parameters, alpha and beta, of type int. The data flow for

alpha is one-way, into the function. The data flow for beta is two-way, into and out of the function. What is the most appropriate function heading for SomeFunc?

A) void SomeFunc( int alpha, int beta )

B) void SomeFunc( int& alpha, int beta )

C) void SomeFunc( int alpha, int& beta )

D) void SomeFunc( int& alpha, int& beta )

32. Which of the following could cause an unexpected side effect?

A) modifying a global variable

B) changing the value of a value parameter

C) referencing a global constant

D) declaring an incoming-only parameter to be a reference parameter

33. For the function definition

void Func( int& gamma )

{ gamma = 3 * gamma;

}

which of the following comments describes the direction of data flow for gamma?

A) /* in */ B) /* out */ C) /* inout */

34. 2. Inside a computer, a single character such as the letter A usually is represented by a:

A)bit B) byte C) nibble D) Word

35. Suppose the first few lines of a function are as follows:

void Calc( /* in */ float beta )

{

alpha = 3.8 * beta;

Then the variable alpha must be

A) a local variable. B) a global variable.

C) a parameter. D) an argument. 36. Given the declarations

float x[300]; float y[75][4]; float z[79];

which of the following statements is true?

A) x has more components than y.

B) y has more components than x.

C) y and z have the same number of components.

D) x and y have the same number of components.

37. Which of the following stores into min the smaller of alpha and beta?

A) if (alpha < beta)

min = alpha;

else

min = beta;

B) min = (alpha < beta) ? beta : alpha;

C) min = (alpha < beta) ? alpha : beta;

D) a and c above

38.Which line of the following program fragment contains a syntax error?

struct StatType // Line 1

{ float height; // Line 2

int weight; // Line 3

} // Line 4

StatType stats; // Line 5

A) line 1 B) line 2 C) line 4 D) line 5

39. In C++, which of the following is not allowed as an aggregate operation on structs?

A) assignment B) I/O

C) argument passage by value D) argument passage by reference

40.Given the recursive function

int Sum( /* in */ int n )

{

if (n < 8) return n + Sum(n + 1);

else return 2;

}

what is the value of the expression Sum(5) ?

A) 5 B) 13 C) 20 D) 28

Part Ⅱ. Fill in-1 (20 points)

1 . A general solution, or algorithm, is written during the ____________________ phase of a

computer program's life cycle.

2. A(n) ________________ is a location in memory, referenced by an identifier, in which a data

value that can be changed is stored.

3 . ____________________ is the written text and comments that make a program easier for

others to understand, use, and modify.

4. A(n) _______________ is a specific set of data values along with a set of operations on those

values.

5. A sequence of 8 bits is known as a(n) ____________________.

6. In C++ systems, names appearing in #include directives are called ___________ files.

7 . A(n) ____________________ is a program that translates a high-level language program into

machine code.

8. The expression int(someFloat) is an example of a(n) _______________ operation.

9. In a C++ function, the statements enclosed by a { } pair are known as the

____________________ of the function.

10. A(n) _______________ is a printed message that explains what the user should enter as input.

Part Ⅲ.Fill in -2 (20 points)

1. (4 points)What is printed by the following program fragment, assuming the input value is 0?(All variables are of type int)

cin>>n;

i=1;

do

{

cout<

}while(i<=n);

______________ ______2. (4 points)What is printed by the following program ?

#include

#define F1(a,b) a+b

#define F2(a,b) a-b

#define CAL(a,b) a*b+a+3

void main( )

{ cout<

}

3.(4 points)What is printed by the following program fragment?

#include

void main( )

{ char a[ ]=“language”, b[]= “program”;

char *p1, *p2;

int i;

p1=a; p2=b;

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

if ( *(p1+i)!=*(p2+i) )

cout<<*(p2+i);

}

______________ ______

4 . (8 points) Fill in the blanks in the following program, which should input any values into the array a[2][3], and find out the max of the array elements and its indexs.

#include

using namespace std;

void main()

{ long int a[2][3], i, j;

srand(100);

for (i=0;i<2;i++)

for ( ) a[i][j]= ;

int h,l,Max= ;

for (i=0;i<2;i++)

for ()

if (Max a[i][j] )

{ ;

; ; }

cout<<"Max: "<<"a["<

}

Part Ⅳ. Programming Problems (20 points)

1.(10 points) Write a C++ program that implements the formula:

Fib(n)=Fib(n-1)+Fib(n-2)

with base bases Fib(0)=1 and Fib(1)=1, produces the preceding 40 items of this sequence.

(1)Using iterative. (迭代)

(2)Using recursion. (递归)

2. (10 points)Sorting the components of the list into order, the list exists in the array elements stu[0] through stu[9]. (for instance , stu[ ].s.aver into ascending order.

Using the straight selection sort (选择法排序) . There are the first parts of the program, complete it.

5. D 10. C 15. C 20. D 25. C 30. A 35. B 40. C .

试卷标准答案及评分标准

课程名称:高级语言程序设计(双语PROGRAMMING IN C++)任课教师:丁学钧《PROGRAMMING IN C++》试卷(A)PartⅠ. Multiple Choice (40 points)

评分标准:每小题1分

1. B 6. C 11. C 16. C 21. D 26. A 31. C 36. D .

2. B 7. C 12. D 17. D 22. D 27. A 32. D 37. D .

3. B 8. A 13. D 18. D 23. B 28. D 33. C 38. C .

4. C 9. C 14. B 19. D 24. B 29. A 34. B 39. B .

#include

#include

#include

struct Grade

{ int s1, s2, int s3;

float aver;

};

struct StudentRec

{ int num;

string name;

Grade s;

};

typedef struct StudentRec

STUDENT;

STUDENT inputstu( int );

void sort( STUDENT stu[ ], int );

void main( )

{ ……

PartⅡ. Fill in-1 (20 points)

评分标准:每空2分

1. Probem-solving

2.variable

3. documentation

4. data type

5. byte

6. header

7. compiler 8. type cast 9. body

10. prompt

PartⅢ. Fill in-2 (20 points)

评分标准:第1、2题每小题3分, 第3小题4分,第4小题每空1分。

1. 1

2. 9

3. prorm

4.j=0;j<3;j++ rand( ) a[0][0] j=0;j<3;j++ <

Max=a[i][j] h=i l=j

第 1 页共 3 页

Part Ⅳ. Programming Problems (20 points)

1.(10分)

(1) 方法1: Using iterative (迭代)

#include

#include // 评分标准:写出该头文件,0.5分

using namespace std;

void main()

{

long int f1=1, f2=1; //评分标准:定义并初始化数列的头2个,0.5分

for(int i=1; i<=20; i++ ) //评分标准:循环语句,0.5分

{

cout<

if (i%2==0) cout<

f1=f1+ f2; //评分标准:迭代,2分

f2=f2+f1;

}

}

(2) 方法2: Using recursion (递归)

#include

#include

using namespace std;

int fib(int n) // 评分标准:正确写出函数头,1分

{

if(n==1) return 1; // 评分标准:正确写出递归终止条件,1分

else if (n==2) return 1;

else return fib(n-1)+fib(n-2); // 评分标准:正确写出递归步骤,1分

}

void main( )

{

for (int i=1;i<=40;i++)

{ cout<

if (i%5==0) cout<

}

cout<

}

第 2 页共 3 页

2.(10分)

void main()

{ STUDENT stu[10]; //评分标准:定义结构体数组,1分

for(int i=0;i<10;i++)

stu[i]=inputstu(i); //评分标准:正确调用inputsru函数,必须要有返回值,1分

sort(stu,10); //评分标准:调用sort函数,正确给出实参,1分

cout<

for(i=9;i>=0;i--)

cout<<10-i<<": "<

<

1分

}

STUDENT inputstu(int i) //评分标准:正确写出函数头,0.5分

{ STUDENT stu; //评分标准:定义函数返回值变量类型为结构体,0.5分cout<

cin>>stu.num;

cout<<"input stu"<

cin>>https://www.360docs.net/doc/ad3301841.html,;

cout<<"input stu"<

cin>>stu.s.s1>>stu.s.s2>>stu.s.s3 ;

stu.s.aver =(stu.s.s1+stu.s.s2+stu.s.s3)/3.0; //评分标准:正确计算平均值,0.5分return stu; //评分标准:返回函数结果,1分

}

// 选择法排序

void sort( STUDENT stu[],int n) //评分标准:正确写出函数头,0.5分

{ int i, j, min;

STUDENT t; //评分标准:定义变量t类型为结构体,0.5分

for ( i=0; i

{ min=i;

for(j=i; j

if (stu[j].s.aver

min = j;

t = stu[i];

stu[i] =stu[min];

stu[min] = t;

}

}

第 3 页共 3 页

C语言程序设计第三版习题库答案

C 语言程序设计(第三版)习题库 1、设圆半径r=,圆柱高h=3,求圆周长、圆面积、圆球表面积、圆球体积、圆柱体积。用scanf 输入数据,输出计算结果,输出时要求文字说明,取小数点后两位数字。请编程序。 #include<> main(){ floatr,h,C1,Sa,Sb,Va,Vb; scanf(__”%f ”__,&r); scanf(”%d ”,__&h _);; C1=2**r; Sa=*r*r; Sb=4*Sa; Va=4**r*r*r/3; Vb=Sa*h; printf(___”Cl=%.2fSa=%.2fSb=%.2fVa=%.2fVb=%.2f ”,Cl,Sa,Sb,Va,Vb ); } 2、输入一个华氏温度,要求输出摄氏温度。公式为c=5(F-32)/9 输出要求有文字说明,取位2小数。 #include<> main(){ floatF,c; scanf("%f",&F); ____c=5*(F-32)/9______; printf("c=%.2f",c); } 3、有一函数:?? ???≥-<≤-<=10113101121x x x x x x y 写一程序,输入x 值,输出y 值。 #include<> main(){ intx,y; printf("输入x :"); scanf("%d",&x); if(x<1){/*x<1*/ y=x; printf("x=%3d,y=x=%d\n",x,y);

}elseif(____x<10_______){/*1≤x-10*/ _____y=2*x-1_______; printf("x=%3d,y=2*x-1=%d\n",x,y); }else{/*x≥10*/ y=3*x-11; printf("x=%3d,y=3*x-11=%d\n",x#include"" main() { intx,y; scanf("%d",&x); if(x<1) {y=x;} elseif(x>=1&&x<10) {y=2*x-1;} else {y=3*x-11;} printf("%d",y); }#include"" main() { intx,y; scanf("%d",&x); if(x<1) {y=x;} elseif(x>=1&&x<10) {y=2*x-1;} else {y=3*x-11;} printf("%d\n",y); }#include"" main() { intx,y; scanf("%d",&x); if(x<1) {y=x;} elseif(x>=1&&x<10) {y=2*x-1;} else {y=3*x-11;} printf("%d",y); }scanf("%d",&x);

C语言程序设计试题1

C语言程序设计试题1 一、单项选择题 1.C语言规定,在一个源程序中main函数的位置______d___ 。 A.必须在最开始B.必须在最后 C.必须在预处理命令的后面D.可以在其他函数之前或之后 2.以下选项中,_________d__ 是C语言关键字 A.printf B.include C.fun D.default 3.已知有声明"int a=3,b=4,c;",则执行语句"c=1/2*(a+b);"后,c的值为____a_ 。 A.0 B.3 C.3.5 D.4 4.设指针变量占4个字节的内存空间,若有声明"char *p="123";int c;",则执行语句 "c=sizeof(p);"后,c的值为__d__ A.1 B.2 C.3 D.4 5.已知有声明"int a=3,b=4;",下列表达式中合法的是_d___。 A.a+b=7 B.a=|b| C.a=b=0 D.(a++)++ 6.已知有声明"char s[20]="Hello";",在程序运行过程中,若要想使数组s中的内容修改为"Good",则以下语句中能够实现此功能的是___d_。 A.s="Good"; B.s[20l="Good"; C.strcat(s,"Good"); D.strcpy(s,"Good"); 7.已知有声明"int a[4][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};",若需要引用值为12的数组元素,则下列选项中错误的是_a___ 。 A.*(a+2)+3 B.*(*(a+2)+3) C.*(a[2]+3) D.a[2][3] 8.已知有声明"int n;float x,y;",则执行语句"y=n=x=3.89;"后,y的值为_b___ 。 A.3 B.3.0 C.3.89 D.4.0 9.已知有声明"int a=12,b=15,c;",则执行表达式"c=(a||(b-=a))"后,变量b和c的值分别为 __b__。 A.3,1 B.15,12 C.15,1 D.3,12 10.下面的函数定义正确的是_____d________ A)float fun (float x ; float y) {return x*y;} B)float fun (float x,y) {return x*y;} C)float fun (x,y) {int x,y;return x*y;} D)int fun (int x, int y) {return x*y;} 11.某程序需要使用一个代表常数3.14的符号常量名P,以下定义中正确的是_d___。 A.#define P 3.14; B.#define P(3.14) C.#define P=3.14; D.#define P 3.14 12.下列四个选项中,属于C语言关键字的是__c__ 。 A.Float B.single C.double D.real 13.已知某编译系统中signed int类型数据的长度是16位,该类型数据的最大值是_D___。 A.32767 B.32768 C.127 D.65535

C语言程序设计试题集与答案解析

一.填空 1. 每个C程序都必须有且仅有一个________ 函数。 2. C语言程序开发到执行通常要经过6个阶段即编辑、预处理、________、链接、加载和执行。 3. 软件是程序,以及______、使用和维护所需要的所有文档。 4. 国标中规定:“计算机程序是按照具体要求产生的适合于计算机处理的_________”。 5. 程序设计语言按照书写形式,以及思维方式的不同一般分为低级语言和________两大类。 6. C语言是由________组成的。 7. C语言的函数可分为主函数main、标准库函数和_________。 8. 一个函数是由两部分组成的,即:________和函数体。 9. 编译是将C语言所编写的源程序________成机器代码,也称为建立目标代码程序的过程。 10. 程序是由某种程序设计语言编制出来,体现了编程者的控制思想和对计算机执行操作 的要求。不同的任务功能,就会需求不同的软件程序,如:控制计算机本身软硬件协调工作,并使其设备充分发挥效力,方便用户使用的系统软件程序,称为操作系统;而为办公自动化(OA)、管理信息系统(MIS)、人工智能、电子商务、网络互联等等应用而开发的软件程序,统称为_________。 11. 机器语言是以__________形式表示的机器基本指令的集合,是计算机系统唯一不需要翻译可以直接识别和执行的程序设计语言。 12. 与机器语言相比,使用汇编语言来编写程序可以用_______来表示指令的操作码和操作对 象,也可以用标号和符号来代替地址、常量和变量。

13. 在编译程序之前,凡以____开头的代码行都先由预处理程序预处理。 14. C程序的执行均是由执行_________开始。 15. 函数体即为包含在{}内的部分。它分为________和为完成功能任务由若干个C 语句 组成的执行部分。 16. C语言程序中一条简单语句是以________字符作为结束符的。 17. C语言是结构化、________的程序设计语言。 18. 由于计算机硬件不能直接识别高级语言中的语句,因此,必须经过“_______程序”,将用高级语言编写的程序翻译成计算机硬件所能识别的机器语言程序方可执行。 19. 用高级语言编写的程序需翻译成计算机硬件所能识别的机器语言程序方可执行。所以 说,用高级语言进行程序设计,其编程效率高,方便易用,但_______没有低级语言高。 20.

C语言程序设计期末考试试题(含答案)

C语言程序设计 期末考试试题及其答案 一、单项选择题(本大题共20题,每题2 分,共40分) 1、以下不是C语言的特点的是( ) A、C语言简洁、紧凑 B、能够编制出功能复杂的程序 C、C语言可以直接对硬件进行操作 D、C语言移植性好 2、以下不正确的C语言标识符是( ) A、ABC B、abc C、a_bc D、ab.c 3、一个C语言程序是由( ) A、一个主程序和若干子程序组成 B、函数组成 C、若干过程组成 D、若干子程序组成 4、一个算法应该具有“确定性”等5个特性,对另外4个特性的描述中错误的是( ) A、有零个或多个输入 B、有零个或多个输出 C、有穷性 D、可行性 5、设变量a是整型,f是实型,i是双精度型,则表达式10+‘a’+i*f值的数据类型为( ) A、int B、float C、double D、不确定 6、在C语言中,char型数据在内存中的存储形式是( ) A、补码 B、反码 C、源码 D、ASCII码 7、有如下程序,输入数据:12345M678<cR>后(表示回车),x的值是( ) 。 #include main(){ int x; float y; scanf("%3d%f",&x,&y); } A、12345 B、123 C、45 D、345 8、若有以下定义int a,b; float x,则正确的赋值语句是( ) A、a=1,b=2 B、b++; C、a=b=5 D、b=int(x); 9、以下程序的执行结果是( )

#include { int i=10,j=10; printf("%d,%d\n",++i,j--); } A、11,10 B、9,10 C、11,9 D、10,9 10、巳知字母A的ASCII码是65,以下程序的执行结果是( ) #include main() { char c1='A',c2='Y'; printf("%d,%d\n",c1,c2); A、A,Y B、65,65 C、65,90 D、65,89 11、下列运算符中优先级最高的是( ) A、< B、十 C、% D、!= 12、设x、y和z是int型变量,且x=3,y=4,z=5,则下面表达式中值为0是( ) 。 A、’x’&&’y’ B、x<=y C、x||y+z&&y-z D、!((x<y)&&!z ||1) 13、判断char型变量cl是否为小写字母的正确表达式为( ) A、’a’<=c1<=f’z’ B、(c1>=a)&&(c1<=z) C、(‘a’>=c1) (‘z’<=c1) D、(c1>=’a’)&&(c1<=’z’) 14、字符串"a"在内存中占据的字节个数为( ) A、0 B、 1 C、 2 D、 3 15、下面有关for循环的正确描述是( ) A、for循环只能用于循环次数已经确定的情况 B、for循环是先执行循环体语句,后判定表达式 C、在for循环中,不能用break语句跳出循环体 D、for循环体语句中,可以包含多条语句,但要用花括号括起来 16、下面程序的运行结果是( ) #include main() {int num=0; while(num<=2) {num++; printf(“%d ,num); } } A、 1 B、 1 2 C、 1 2 3

c语言程序设计试题答案

习题7 7.1选择题。 (1)下列对字符串的定义中,错误的是: A 。 A) char str[7] = "FORTRAN"; B) char str[] = "FORTRAN"; C) char *str = "FORTRAN"; D) char str[] = {'F','O','R','T','R','A','N',0}; (2)以下程序段的输出结果是:____D_________ char a[] = "ABCDE" ; char *p = NULL; for (p=a; p main() { static char a[5]; a = "abcde" ; printf("%s\n", a); }

B) #include <> main() { static char a[7]= "goodbye!"; printf("%s\n", a) ; } C) #include <> main() { char a[5] = "abcde"; printf("%s\n", a) ; } D) #include <> main() { static char a[]="abcde"; printf("%s\n", a) ; } (4)阅读下列函数,函数功能为___A_____。 void Exchange(int *p1, int *p2) { int p; p = *p1; *p1 = *p2; *p2 = p; } A)交换*p1和*p2的值B)正确,但无法改变*p1和*p2的值 C)交换*p1和*p2的地址 D)可能造成系统故障

c语言程序设计第五版习题答案

习题解析与答案 第1章C语言概述 一.简答题 1.概述C语言的主要特点。 【解答】 (1)语言简洁、紧凑,使用方便、灵活。 (2)数据类型丰富,表达能力强。 (3)运算符多样。C语言中的运算符包含的范围非常广泛。 (4)具有结构化的控制语句。如if…else语句、while语句、do while语句、switch 语句、for语句。 (5)允许直接访问物理地址。C语言中含有的位和指针运算,能够直接对内存地址进行访问操作。 (6)所生成的目标代码质量高,可移植性好。 2.构成C语言程序的基本单位是什么?它由哪几部分组成? 【解答】函数是构成C语言程序的基本单位。一个完整的C程序一般由文件包含、宏定义、函数说明、变量和一个或若干个函数组成。 3.C语言程序的运行一般要经过哪几个步骤? 【解答】(1)编辑;(2)编译;(3)连接,生成EXE文件;(4)执行。 二.运行程序写结果 1.输入下面程序并运行。 main() { int a1,a2,x; a1=100; a2=50; x=a1-a2; printf(″x=%d\n″,x); } 【解答】运行结果为:x=50 2.输入下面程序并运行。 main() { int a1,a2,x; a1=10; a2=20; x=a1*a2; printf(″a1=%d,a2=%d\n″,a1,a2); printf(″x=%d\n″,x); } 【解答】运行结果为:a1=10,a2=20 x=200 3.输入下面程序并运行。

#include main() { printf("******\n"); printf(" *****\n"); printf(" ****\n"); printf(" ***\n"); printf(" **\n"); printf(" *\n"); } 【解答】运行结果为:****** ***** **** *** ** * 思考:可以修改程序,使之输出平行四边形,等腰三角形等图形。 三.编程题 1.参照本章例题,编写一个C程序,用于显示如下信息: ************************* I love C programs! ************************* 【分析与提示】 ①要有文件包含语句#include 。C语言中没有数据的输入、输出等功能,数据的输入、输出都是通过调用系统提供的库函数scanf和printf等来实现的。这些函数的说明都包括在stdio.h文件中。 ②main是主函数的名称。用{}括起来的内容是函数体,函数体由若干条语句组成,这是计算机要执行的部分,每条语句以分号“;”结束。 ③注意显示的信息有三行,所以要用到换行符“\n”。 参考代码: #include main() { printf("************************\n"); printf(" I love C programs! \n"); printf("************************\n"); }

04737c程序设计试题及答案20200_图文

全国2009年10月高等教育自学考试 C++程序设计试题 课程代码:04737 一、单项选择题(本大题共20小题,每小题1分,共20分) 在每小题列出的四个备选项中只有一个是符合题目要求的,请将其代码填写在题后的括号内。错选、多选或未选均无分。 1.对C++中主函数描述正确的是( ) A.名称为main,可为多个 B.名称不限,可为多个 C.名称为main,必须有且只能有一个 D.名称不限,必须有且只能有一个 2.调用声明为int result(int a,int b)的函数时,正确的方法是( ) A.result(1,2) B.result(1) C.result(0.1,0.3) D.result(1,2,3) 3.用于包含C++标准库iostream的预处理指令是( ) A.#define B.#include C.#define ‘iostream’ D.#include‘iostream’ 4.无类型标识符是指( ) A.void B.bool C.short D.long 5.从本质上看,引用是被引用变量的( ) A.拷贝 B.别名 C.复制 D.克隆 6.下面关于数组的初始化正确的是( ) A.char str[ ]={'a','b','c'}; B.char str[2]={'a','b','c'}; C.char str[1][2]={{'a','b'},{'e','d'}}; D.char str[ ][ ]={'a','b','c'}; 7.C++类中定义的成员默认访问属性为( ) A.public B.private C.protected D.friend 1文档来源为:从网络收集整理.word版本可编辑.

c语言程序设计期末试题B(含答案)

c语言程序设计期末试题B(含答案) 一单项选择题(每小题1分,共10分) 1. A 2. C 3. D 4. A 5. B 1.以下4组用户定义标识符中,全部合法的一组是() A)_total clu_1 sum B)if -max turb C)txt REAL 3COM D)int k_2 _001 2.以下程序的输出结果是() #include main( ) { int a = 1, b = 2, c = 3; printf(“%d”, c>b>a); } A) 2 B) 1 C) 0 D) 3 3.以下正确的叙述是() A) 在C语言中,main函数必须位于文件的开头 B) C语言每行中只能写一条语句 C) C语言本身没有输入、输出语句 D) 对一个C语言进行编译预处理时,可检查宏定义的语法错误 4.设有定义:int a,*pa=&a; 以下scanf语句中能正确为变量a读入数据的是() A)scanf("%d",pa); B)scanf("%d",a); C)scanf("%d",&pa); D)scanf("%d",*pa); 5.若有以下程序段, int c1=1,c2=2,c3; c3=1.0/c2*c1; 则执行后,c3中的值是() A) 0 B) 0.5 C) 1 D) 2 6. D 7. D 8. A 9. C 10. D 6.能正确表示逻辑关系:“a≥=10或a≤0”的C语言表达式是() A) a>=10 or a<=0 B)a>=0|a<=10 C)a>=10 &&a<=0 D)a>=10‖a<=0 7.执行下面的程序时,将1、2、3、4分别赋给a、b、c、d,正确的输入是() main( ) { int a,b,c,d; scanf(“%d,%d,%d%d”,&a,&b,&c,&d); … } A)1 2 3 4 B)1 2 3,4 C) 1,2,3,4 D) 1,2,3 4

(完整版)C语言程序设计练习及答案

《C语言程序设计》练习及答案 得分评卷人复查人 一、单选题,每小题1分,共60分(将正确答案的序号写在题目的括号中)。 1、结构化程序设计的三种基本控制结构是(D )。 A、主程序、子程序、函数 B、输入、处理、输出 C、调用,返回,转移 D、顺序、选择、循环 2、下列关于C程序变量的叙述, ( D )是错误的。 A、变量名必须由字母或下划线开头。 B、程序中的变量必须在被使用之前定义。 C、不同的基本类型的变量之间可以混合运算。 D、变量的数据类型决定变量的"作用域"。 3、能将C语言编写的源程序转换为目标程序的软件是(C )。 A、编辑程序 B、汇编程序 C、编译程序 D、解释程序 4、以下符号中,合法的用户标识符是( D )。 A、-p B、int C、3ab D、_xt_ 5、以下选项中,与m=n++完全等价的表达式是( C )。 A、m=++n B、m+=n+1 C、m=n, n=n+1 D、n=n+1,m=n 6、若有定义:int aa[8];。则以下表达式中不能代表数组元aa[1]的地址的是(C )。 A、&aa[0]+1 B、&aa[1] C、&aa[0]++ D、aa+1 7、表达式!5&(7+3)&&(4+5)的值是(A)。 A、0 B、1 C、5 D、9 8、以下选项中非法的C语言表达式是(A )。 A、x+1=x+1 B、0<=x<100 C、i=j==0 D、(char)(65+3) 9、在TURBO C中, int类型变量所占字节数是(B )。 A、1 B、2 C、4 D、8 10、C语言中基本的数据类型包括(B)。 A、整型,实型,逻辑型 B、整型,实型,字符型

C语言程序设计试题集及其答案

第一章基础知识 一.填空 1. 每个C程序都必须有且仅有一个________ 函数。 2. C语言程序开发到执行通常要经过6个阶段即编辑、预处理、________、链接、加载和执行。 3. 软件是程序,以及______、使用和维护所需要的所有文档。 4. 国标中规定:“计算机程序是按照具体要求产生的适合于计算机处理的_________”。 5. 程序设计语言按照书写形式,以及思维方式的不同一般分为低级语言和________两大类。 6. C语言是由________组成的。 7. C语言的函数可分为主函数main、标准库函数和_________。 8. 一个函数是由两部分组成的,即:________和函数体。 9. 编译是将C语言所编写的源程序________成机器代码,也称为建立目标代码程序的过程。 10. 程序是由某种程序设计语言编制出来,体现了编程者的控制思想和对计算机执行操作 的要求。不同的任务功能,就会需求不同的软件程序,如:控制计算机本身软硬件协调工作,并使其设备充分发挥效力,方便用户使用的系统软件程序,称为操作系统;而为办公自动化(OA)、管理信息系统(MIS)、人工智能、电子商务、网络互联等等应用而开发的软件程序,统称为_________。 11. 机器语言是以__________形式表示的机器基本指令的集合,是计算机系统唯一不需要翻译可以直接识别和执行的程序设计语言。 12. 与机器语言相比,使用汇编语言来编写程序可以用_______来表示指令的操作码和操作对 象,也可以用标号和符号来代替地址、常量和变量。 13. 在编译程序之前,凡以____开头的代码行都先由预处理程序预处理。 14. C程序的执行均是由执行_________开始。 15. 函数体即为包含在{}内的部分。它分为________和为完成功能任务由若干个C 语句 组成的执行部分。 16. C语言程序中一条简单语句是以________字符作为结束符的。 17. C语言是结构化、________的程序设计语言。 18. 由于计算机硬件不能直接识别高级语言中的语句,因此,必须经过“_______程序”,将用高级语言编写的程序翻译成计算机硬件所能识别的机器语言程序方可执行。 19. 用高级语言编写的程序需翻译成计算机硬件所能识别的机器语言程序方可执行。所以 说,用高级语言进行程序设计,其编程效率高,方便易用,但_______没有低级语言高。

C语言程序设计期末考试试题及答案知识分享

C语言程序设计试题 (2008 /2009 学年第二学期) 一.选择题(满分30分,每题2分) 1.若a、b、c都定义为int类型且初值为0,则以下不正确的赋值语句是 D 。 A. a=b=c+8; B. a+=y+3; C. c++; D. a+b+c 2. 已知int j,i=1;执行语句“j=i++;”后,变量i的值是 B 。 A. 1 B. 2 C. –1 D. -2 3.执行下面程序: #include "stdio.h" void main() { int a=1,b=2,c=3; c=(a+=a+2),(a=b,b+3); printf(“%d,%d,%d”,a,b,c); } 则输出结果是: A 。 A. 2,2,4 B. 4,2,3 C. 5,5,3 D. 4,2,5 4.若要求在if后一对圆括号中表示a不等于0的关系,则能正确表示这一关系的表达式为 D 。 A. a< >0 B. !a C. a=0 D. a 5. for (j=0;j<11;j++);循环结束后,j的值是 B 。 A. 12 B. 11 C. 10 D. 9 6. C语言中函数返回值的类型由 D 决定的。 A. return语句中的表达式类型 B. 调用该函数的主调函数的类型 C. 调用函数时临时决定 D. 定义函数时所指定的函数类型 7. 下列说法中正确的是 B 。 A 在调用用户自定义函数时,必须对其进行声明。 B 函数可以返回一个值,也可以什么值也不返回。 C 说明函数时,必须明确参数的类型和返回值。 D 在程序设计中空函数没有什么作用。8. 若int i=10;执行下列程序后,变量i的正确结果是 D 。 switch ( i ) {case 0: i+=1; case 10: i+=1; case 11: i+=1; default: i+=1; } A. 10 B. 11 C. 12 D. 13 9. 下列语句中不正确的字符串赋值或初始化的是 C 。 A. char str[10]={"strings"}; B.char str[8]={'s','t','r','i','n ','g','s','\0'}; C. char str[10]; str= "strings"; D. char str[]= "strings"; 10. 有如下程序: #include void main() { int a=1,b=0,c=0; if (a

C语言程序设计第二版习题参考答案

C语言程序设计第二版 习题参考答案 Document serial number【LGGKGB-LGG98YT-LGGT8CB-LGUT-

C语言程序设计习题参考答案 习题 1 一、判断题 1.在计算机中,小数点和正负号都有专用部件来保存和表示。 2.二进制是由0和1两个数字组成的进制方式。 3.二进制数的逻辑运算是按位进行的,位与位之间没有进位和借位的关系。 4.在整数的二进制表示方法中,0的原码、反码都有两种形式。 5.有符号数有三种表示法:原码、反码和补码。 6.常用字符的ASCII码值从小到大的排列规律是:空格、阿拉伯数字、大写英文字母、小写英文字母。 解:1.F2.T 3.T 4.T 5.T 6.T 二、单选题 1.在计算机中,最适合进行数值加减运算的数值编码是。 A. 原码 B. 反码 C. 补码 D. 移码 2.已知英文小写字母m的ASCII码为十进制数109,则英文小写字母y的ASCII 码为十进制数。 A. 112 B. 120 C. 121 D. 122 3.关于ASCII码,在计算机中的表示方法准确地描述是。 A. 使用8位二进制数,最右边一位为1 B. 使用8位二进制数,最左边一位为1 C. 使用8位二进制数,最右边一位为0 D. 使用8位二进制数,最左边一位为0 4.设在机器字长4位,X=0111B,Y=1011B,则下列逻辑运算中,正确的是 ___________。 A. X∧Y=1000 B. X∨Y=1111 C. X⊕Y=0011 D. ˉY=1000 5.下列叙述中正确的是()。 A.高级语言就是机器语言 B.汇编语言程序、高级语言程序都是计算机程序,但只有机器语言程序才是计算机可以直接识别并执行的程序 C.C语言因为具有汇编语言的一些特性,所以是汇编语言的一种 D.C源程序经过编译、连接,若正确,执行后就能得到正确的运行结果6.用C语言编写的源程序经过编译后,若没有产生编译错误,则系统将()。 A.生成可执行文件B.生成目标文件 C.输出运行结果D.自动保存源文件 7.下列叙述中不正确的是()。 A.main函数在C程序中必须有且只有一个 B. C程序的执行从main函数开始,所以main函数必须放在程序最前面 C. 函数可以带参数,也可以不带参数。

C语言程序设计试题集及答案

单项选择题 (002) 阅读程序题 (018) 程序填空题 (039) 编写程序题 (070) 一、单项选择题 导读:单项选择题要求从给出的四个备选答案中,选出一个最符合题意的答案。本类习题主要检查对C语言基本概念的掌握情况,读者可根据学习进度选做部分习题。在完成习题的过程中,不但要选出正确的答案,而且要清楚不正确的选项错在何处,以加深对概念的理解。对于掌握不准的问题,应该通过上机实验来检验。 【1.1】以下不正确的C语言标识符是____。 A) int B) a_1_2 C) ab1exe D) _x 【1.2】以下是正确的C语言标识符是____。 A) #define B) _123C) %d D) \n

【1.3】下列四组字符串中都可以用作C语言程序标识符的一组是。 ??? A) print B) i\am C) Pxq D) str_l ??? _3d one_half My->book Cpp ??? oodbs tart$it line# pow ??? aBc 3pai His.age while 【1.4】下面各选项组中,均是C语言关键字的组是。 A) auto,enum,include B) switch,typedef,continue C) signed,union,scanf D) if,struct,type 【1.5】下列不属于C语言关键字的是。 A) default B) register C) enum D) external 【1.6】C语言程序从main()函数开始执行,所以这个函数要写在____。 A) 程序文件的开始B) 程序文件的最后 C) 它所调用的函数的前面D) 程序文件的任何位置 【1.7】下列关于C语言的叙述错误的是____ A) 大写字母和小写字母的意义相同 B) 不同类型的变量可以在一个表达式中 C) 在赋值表达式中等号(=)左边的变量和右边的值可以是不同类型 D) 同一个运算符号在不同的场合可以有不同的含义 【1.8】在C语言中,错误的int类型的常数是。 A) 32768 (超过了范围) B) 0 C) 037 D) 0xAF 【1.9】执行语句printf("%x",-1);屏幕显示____。 A) -1 B) 1 C) –ffff D) ffff 【1.10】已知long i=32768;执行语句printf("%d",i);屏幕显示____。 A) -1 B) -32768C) 1 D) 32768 【1.11】已知long i=65539; 执行语句printf("%d",i);屏幕显示____。 A) 65539 B) -3 C) 3D) 程序不能执行 【1.12】在C语言中,整数-8在内存中的存储形式是。 A) 1111 1111 1111 1000B) 1000 0000 0000 1000 C) 0000 0000 0000 1000 D) 1111 1111 1111 0111 【1.13】C语言中字符型(char)数据在内存中的存储形式是____。

C语言程序设计期末考试试卷

一、单项选择题(本大题共20题,每题2分,共40分) 1、以下不是C语言的特点的是 A、C语言简洁、紧凑 B、能够编制出功能复杂的程序 C、C语言可以直接对硬件进行操作 D、C语言移植性好 2、以下不正确的C语言标识符是 A、ABC B、abc C、a_bc D、ab.c3、一个C语言程序是由。 A、一个主程序和若干子程序组成 B、函数组成 C、若干过程组成 D、若干子程序组成 4、一个算法应该具有“确定性”等5个特性,对另外4个特性的描述中错误的是 A、有零个或多个输入 B、有零个或多个输出 C、有穷性 D、可行性 5、设变量a是整型,f是实型,i是双精度型,则表达式10+‘a’+i*f值的数据类型为

A、int B、float C、double D、不确定6、在C语言中,char型数据在内存中的存储形式是。 A、补码 B、反码 C、源码 D、ASCII码 7、有如下程序,输入数据:12345M678<cR>后(表示回车),x的值是。 #include main(){ int x; float y; scanf("%3d%f",&x,&y); } A、12345 B、123 C、45 D、3458、若有以下定义int a,b; float x,则正确的赋值语句 是。 A、a=1,b=2 B、b++; C、a=b=5 D、b=int(x); 9、以下程序的执行结果是。 #include { int i=10,j=10;

printf("%d,%d\n",++i,j--); } A、11,10 B、9,10 C、11,9 D、10,910、巳知字母A的ASCII码是65,以下程序的执行结果 是。 #include main() { char c1='A',c2='Y'; printf("%d,%d\n",c1,c2); A、A,Y B、65,65 C、65,90 D、65,8911、下列运算符中优先级最高的是。 A、< B、十 C、% D、!=12、设x、y和z是int型变量,且x=3,y=4,z =5,则下面表达式中值为0的是。 A、’x’&&’y’ B、x<=y C、x||y+z&&y-z D、!((x<y)&&!z||1) 13、判断char型变量cl是否为小写字母的正确表达式 为。 A、’a’<=c1<=f’z’ B、(c1>=a)&&(c1<=z) C、(‘a’>=c1)(‘z’<=c1) D、(c1>=’a’)&&(c1<=’z’) 14、字符串"a"在内存中占据的字节个数为。

C语言程序设计期末考试试题及答案

C 语言程序设计 试 题 (2008 /2009 学年 第 二 学期) 一. 选择题(满分30分,每题2分) 1.若a 、b 、c 都定义为int 类型且初值为0,则以下不正确的赋值语句是 D 。 A. a=b=c+8; B. a+=y+3; C. c++; D. a+b+c 2. 已知int j ,i=1;执行语句“j=i++;”后,变量i 的值是 B 。 A. 1 B. 2 C. –1 D. -2 3.执行下面程序: #include "stdio.h" void main() { int a=1,b=2,c=3; c=(a+=a+2),(a=b,b+3); printf(“%d,%d,%d ”,a,b,c); } 则输出结果是: A 。 A. 2,2,4 B. 4,2,3 C. 5,5,3 D. 4,2,5 4.若要求在if 后一对圆括号中表示a 不等于0的关系,则能正确表示这一关系的表达式为 D 。 A. a< >0 B. !a C. a=0 D. a 5. for (j=0;j<11;j++);循环结束后,j 的值是 B 。 A. 12 B. 11 C. 10 D. 9 6. C 语言中函数返回值的类型由 D 决定的。 A. return 语句中的表达式类型 B. 调用该函数的主调函数的类型 C. 调用函数时临时决定 D. 定义函数时所指定的函数类型 7. 下列说法中正确的是 B 。 A 在调用用户自定义函数时,必须对其进行声明。 B 函数可以返回一个值,也可以什么值也不返回。 C 说明函数时,必须明确参数的类型和返回值。 D 在程序设计中空函数没有什么作用。 8. 若int i=10;执行下列程序后,变量i 的正确结果是 D 。 switch ( i ) {case 0: i+=1; case 10: i+=1; case 11: i+=1; default: i+=1; } A. 10 B. 11 C. 12 D. 13 9. 下列语句中不正确的字符串赋值或初始化的是 C 。 A . char str[10]={"strings"}; B.char str[8]={'s','t','r','i','n ','g','s','\0'}; C. char str[10]; str= "strings"; D. char str[]= "strings"; 10. 有如下程序: #include void main() { int a=1,b=0,c=0; if (a

C语言程序设计习题答案

C 语言程序设计习题答案 习题一 C 语言程序设计概述 一、名词解释 (1)程序P1 (2)程序设计P1 (3)机器语言P1 (4)汇编程序P2 (5)高级语言P2 (6)编译程序P3 (7)解释程序P3 (8)算法P4 (9)结构化的程序设计P9 二、简述题 1. 设计程序时应遵循哪些基本原则?P4 答:正确性、可靠性、简明性、有效性、可维护性、可移植性。 2. 算法的要素是什么?算法具有哪些特点? 答:算法的要素是:操作与控制结构;算法的特点有:有穷性、确定性、有效性、有零个或多个输入、有一个或多个输出。 3. 算法的表示形式有哪几种? 答:算法的表示形式有:自然语言、传统流程图、伪代码、结构化的流程图(N_S 流程图,盒图)。 4. 有哪三种基本结构? 答:三种基本结构是:顺序结构、选择结构和循环结构。 5. 传统流程图与N-S 流程图最大的区别是什么? 答:N-S 流程图去掉了在传统流程图中常用的流程线,使得程序的结构显得更加清晰、简单。 三、用传统流程图、N-S 图分别表示求解以下问题的算法。 1. 有3个数a ,b ,c ,要求按由大到小的顺序把它们输出。 2. 依次将10个数输入,求出其中最大的数 和最小的数并输出。 3. 求1+2+3+…+100的值。

5. 求下列分段函数的值。 6. 求100~200之间的所有素数。 7. 求一元二次方程ax 2+bx+c=0的根。分别考虑d=b 2-4ac 大于0、等于0和小于0三种情况。 四、注释下面C 程序的各个组成部分。 main() /*主函数 */ { /*程序开始 */ int a,k,m; /*定义三个用来存放整数的变量 */ a=10; /*将整数10赋值给变量a */ k=2; /*将整数2赋值给变量k */ m=1; /*将整数1赋值给变量1 */ a=(k+m)*k/(k-m); /*先求出算术表达式的值,并将其赋值给变量a */ printf("%d\n",a); /*在屏幕上打印出变量a 的值 */ } /*程序结束 */ 习题二 数据类型、运算符与表达式 一、选择题 1~10:BCDCB DDBCA 11~20: ADDAA DBADC 21~28: DABAD CDD Y= 3X (X<1) 4X-1 (X=1) 5(X-1)+6 (1

相关文档
最新文档