1、chapter26eTRUE/FALSE1.In the following code fragment, x has the value of 3.int x = 3; ANSWER: TRUE2.The body of a do-while loop always executes at least once. ANSWER: TRUE3.The body of a while loop may never execute. ANSWER: TRUE4.The opposite of (x 3 & x 10) is (x 10) ANSWER: FALSE5.The integer 0 i
2、s considered true. ANSWER: FALSE6.Loops are used when we need our program to make a choice between two or more things. ANSWER: FALSE7.It is legal to declare more than one variable in a single statement. ANSWER: TRUE8.Variable names may begin with a number. ANSWER: FALSE9.The opposite of less than is
3、 greater than ANSWER: FALSE10.Every line in a program should have a comment. ANSWER: FALSEShort Answer1. is called the _ operator.ANSWER: insertion2.The braces for a loop define the _ of the loop.ANSWER: body3.A loop that always executes the loop body at least once is known as a _ loop.ANSWER: do-wh
4、ile4.int myValue; is called a _.ANSWER: variable declaration5.What is the opposite of ( x 12)? _ANSWER: (x =20 | x 19 & x is known as the _ operator.ANSWER: extraction10.Is used for input or output? _ANSWER: output11.The stream that is used for input from the keyboard is called _.ANSWER: cin12.The s
5、tream that is used for output to the screen is called _.ANSWER: cout13.Write the loop condition to continue a while loop as long as x is negative. _ANSWER: while(x 0)14.When must we use braces to define the body of a contitional expression? _ANSWER: When there are multiple statements in the body.15.
6、In a compound logical and (&) expression, the evaluation of the expression stops once one of the terms of the expression is false. This is known as _ evaluation.ANSWER: short-circuit evaluationMultiple Choice1.Which of the following is a valid identifier?a.3comb.three_comc.3_comd.3-come.dollar$ANSWE
7、R: C (should be B)2.Which of the following is not a valid identifer?a.returnb.myIntc.myIntegerd.total3ANSWER: A3.What is the value of x after the following statements?int x, y, z;y = 10;z = 3;x = y * z + 3;a.Garbageb.60c.30d.33ANSWER: D4.What is the value of x after the following statements?int x;x
8、= 0;x = x + 30;a.0b.30c.33d.garbageANSWER: B5.What is the value of x after the following statements?int x;x = x + 30;a.0b.30c.33d.garbageANSWER: D6.What is the output of the following code?float value;value = 33.5;cout value endl;a.33.5b.33c.valued.garbageANSWER: A7.What is the output of the followi
9、ng code?float value;value = 33.5;cout value endl;a.33.5b.33c.valued.garbageANSWER: C8.What is the output of the following code?cout This is a myFloat;b.cin myFloat;d.cin myFloat endl;ANSWER: A10.Another way to write the value 3452211903 isa.3.452211903e09b.3.452211903e-09c.3.452211903x09d.3452211903
10、e09ANSWER: A11.Which of the following statements is NOT legal?a.char ch=b;b.char ch=0;c.char ch=65;d.char ch=cc;ANSWER: D12.What is the value of x after the following statements?float x;x = 15/4;a.3.75b.4.0c.3.0d.60ANSWER: C13.What is the value of x after the following statements?int x;x = 15/4;a.15
11、b.3c.4d.3.75ANSWER: B14.What is the value of x after the following statements?int x;x = 15 %4;a.15b.4c.3d.3.75ANSWER: C15.What is the value of x after the following statement?float x;x = 3.0 / 4.0 + 3 + 2 / 5 a.5.75 b.5.75c.1.75d.3.75ANSWER: D16.What is the value of x after the following statement?f
12、loat x;x = 3.0 / 4.0 + (3 + 2 )/ 5 a.5.75 b.5.75c.1.75d.3.75ANSWER: C17.What is the value of x after the following statements?double x;x = 0;x += 3.0 * 4.0;x -= 2.0;a.22.0b.12.0c.10.0d.14.0ANSWER: C18.Given the following code fragment and the input value of 4.0, what output is generated?float tax;fl
13、oat total;cout total;if ( total = 3.0) tax = 0.10; cout total + (total * tax) endl;else cout total endl;a.3b.3.3c.4.0d.4.4ANSWER: D19.Given the following code fragment and the input value of 2.0, what output is generated?float tax;float total;cout total;if ( total = 3.0) tax = 0.10; cout total + (to
14、tal * tax) endl;else cout total endl;a.2.2b.2.0c.3.1d.4.4ANSWER: B20.If x has the value of 3, y has the value of -2, and w is 10, is the following condition true or false?if( x 2 & w y)a.trueb.falseANSWER: B21.What is the correct way to write the condition y x z?a.(y x z)b.( (y x) | (y z)d.(y x) & (
15、x z)ANSWER: D22.Given the following code fragment, and an input value of 3, what is the output that is generated?int x;cout x;if(x=0) cout x is zeron;else cout x is not zeron;a.x is zerob.x is not zeroc.unable to determined.x is 3ANSWER: A (note it is an assignment!)23.Given the following code fragm
16、ent, and an input value of 5, what is the output?int x;if( x 3) cout smalln;else if( x 4) cout mediumn; else if( x 6) cout largen; else cout 5) cout x is bigger than 5. ; cout That is all. ;cout Goodbyen;a.x is bigger than 5. That is allb.x is bigger than 5c.That is all. Goodbyed.GoodbyeANSWER: C25.
17、Executing one or more statements one or more times is known as:a.selectionb.iterationc.sequenced.algorithmANSWER: B26.Given the following code fragment, what is the final value of y?int x, y;x = -1;y = 0;while(x = 3) y += 2; x += 1;a.2b.10c.6d.8ANSWER: B27.Given the following code fragment, what is
18、the final value of y?int x, y;x = -1;y = 0;while(x 3) y += 2; x += 1;a.2b.10c.6d.8ANSWER: D28.What is the output of the following code fragment?int x=0;while( x 5) cout x endl; x +;cout x 0);a.8b.9c.10d.11e.infinite loop.ANSWER: E30.Given the following code fragment, which of the following expressions is always true?int x;cin x;a.if( x 1 )d.if( x = 1)ANSWER: D
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1