Computing I: Multiple Choice packet 1,2,3

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

15) What is the output of the following code fragment? int x = 0; { int x = 13; printf("%d,", x); } printf("%d\n", x); A) 13,0 B) 13,13 C) 0,13 D) Nothing, there is a syntax error.

a

18) Which of the following is a valid identifier? A) three_com B) 3-com C) 3com D) dollar$ E) 3_com

a

20) What is the output of the following code? int value; value = 33; printf("value\n"); A) value B) garbage C) value\n D) 33

a

45) Executing one or more statements one or more times is known as A) iteration. B) sequence. C) algorithm. D) selection.

a

12) If x is 42, what is the value of the boolean expression (!x == 0)? A) 0 B) 1 C) syntax error D) unable to determine

b

17) Which loop structure always executes at least once? A) sentinel B) do-while C) while D) for

b

18) The expression (double) 3 is called a A) doubler. B) type cast. C) polymorphism. D) multiplier.

b

27) Which of the following are valid case statements in a switch? A) case x < 4: B) case 'ab': C) case 1: D) case 1.5:

c

47) Which of the following lines correctly reads a value from the keyboard and stores it in the integer variable named myInt? A) scanf("myInt"); B) scanf("%d", myInt); C) scanf("%d", &myInt); D) scanf("%d\n", myInt);

c

16) Which of the following data types can be used in a switch controlling expression? A) enum B) char C) double D) int E) A, B, and D

e

32) What is the correct way to write the condition y < x < z? A) ( (y < x) && z) B) ((y < x) && (x < z)) C) ((y > x) ∣∣ (y < z)) D) (y < x < z)

b

29) What is the value of the following? sqrt(sqrt(pow(2.0,4.0))); A) 4 B) 1 C) 2 D) 16

c

16) Using functions in a program is known as A) data abstraction. B) calculus. C) poor programming style. D) procedural abstraction.

d

19) What is the output of the following code fragment? { int x = 13; printf("%d,", x); } printf("%d\n", x); A) 13,0 B) 0,13 C) 13,13 D) Nothing, there is a syntax error.

d

19) What is the value of x after the following statements? int x; x = 15 %4; A) 15 B) 4 C) 3.75 D) 3

d

20) If a programming language does not use short-circuit evaluation, what is the output of the following code fragment if the value of myInt is 0? int other = 3, myInt; if(myInt != 0 && other % myInt != 0) printf("other is odd\n"); else printf("other is even\n"); A) other is odd B) 0 C) other is even D) run-time error, no output

d

40) 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) 10 B) 6 C) 2 D) 8

d

42) What is the output of the following code? int value; value = 33; printf("%d\n", value); A) value\n B) "%d\n",value C) 33\n D) 33

d

41) When testing a program with a loop, which of the following tests should be done? A) one less than the maximum number of iterations B) no iterations of the loops C) the maximum number of iterations D) one more than the maximum number of iterations E) A, B, and C

e

44) What is the final value of x after the following fragment of code executes? int x = 0; do { x++; }while(x > 0); A) 9 B) 10 C) 8 D) 11 E) infinite loop.

e

38) If the variable x of type double has the original value of 3.4, what is the value in x after the following? printf("%d\n", (int) x ); A) 3.4 B) unknown C) 3 D) 4

a

38) What is the value of x after the following statements? int x; x = 15/4; A) 3 B) 3.75 C) 4 D) 15

a

39) Given the following code, what is the final value of i? int i; for(i = 0; i <= 4;i ++ ) { printf("%d\n", i ); } A) 5 B) 3 C) 4 D) 0

a

39) If you have the following variable declaration in your program, const int SIZE = 34; then which of the following statements are legal? A) printf("%d\n", SIZE); B) SIZE = SIZE + 1; C) x = SIZE--; D) SIZE ++;

a

30) Which of the following is not a legal function declaration? A) int ave_3(int a1, int a2, int a3); B) int 3ave(int a, int b, int c); C) int ave3(int a, int b, int c); D) int ave3(int, int, int);

b

31) Which of the following is not a good reason for choosing a certain loop control (while, do-while, or for loop for example)? A) the condition for ending the loop B) if the loop is in a function C) what the loop does D) the minimum number of iterations of the loop

b

13) If you want a loop to quit iterating if x < 10 and y > 3, what would be the proper loop condition test? A) (x< 10 && y > 3) B) (x> 10 || y < 3) C) (x>= 10 || y <= 3) D) (x>=10 && y <= 3)

c

14) How many times is "Hi" printed to the screen? (There are no typos in this problem.) int i; for(i = 0; i < 14; i ++ ); printf("Hi\n"); A) 15 B) 14 C) 1 D) 13

c

17) Which of the following are valid function calls to the pow function? A) pow(int x, int y); B) double pow(1.1,3.0); C) pow(1.1,3.0); D) pow(2);

c

20) The functions pow( ), sqrt( ), and fabs( ) are found in which include file? A) functions.h B) stdio.h C) math.h D) stdlib.h

c

22) Given the following code fragment and the input value of 4.0, what output is generated? double tax; double total; printf("enter the cost of the item\n"); scanf("%lf", &total); if ( total >= 3.0) { tax = 0.10; printf("%f\n", total + (total * tax)); } else { printf("%f\n", total); } A) 3 B) 3.3 C) 4.4 D) 4.0

c

24) What is the output of the following code fragment if x is 15? if(x < 20) if(x < 10) printf("less than 10\n "); else printf("large\n"); A) less than 10 B) no output, syntax error C) large D) nothing

c

25) What is the value of x after the following statement? double x; x = 3.0/4.0 + 3 + 2/5; A) 4.75 B) 5.75 C) 3.75 D) 1.75

c

26) Given the following code fragment and the input value of 2.0, what output is generated? double tax; double total; printf("enter the cost of the item\n"); scanf("%lf", &total); if ( total >= 3.0) { tax = 0.10; printf("%f\n", total + (total * tax)); } else { printf("%f\n", total); } A) 3.1 B) 2.2 C) 2.0 D) 4.4

c

26) If x is 0, what is the value of the boolean expression (!x == 0)? A) 1 B) unable to determine C) 0 D) syntax error

c

18) Which of the following data types may be used in a switch statement? A) int B) enum C) char D) long E) all of the above

e

36) Which of the following are allowed in the third section of the for loop statement? A) i += 2 B) printf("Hello\n"); C) i -- D) i ++ E) all of the above

e

23) What is the value of the following? floor(4.999) + ceil(2.0); A) 6.0 B) 7.0 C) 6.999 D) 8.0

a

43) Given the following code fragment, and an input value of 0, what is the output that is generated? int x; printf("Enter a value\n"); scanf("%d", &x); if(x = 0) { printf("x is zero\n"); } else { printf("x is not zero\n"); } A) unable to determine B) x is not zero. C) x is zero. D) x is 0.

b

21) Given the following code fragment, which of the following expressions is always true? int x; scanf("%d", &x); A) if( x = 1) B) if( x < 3) C) if( x == 1) D) if((x/3) > 1)

a

21) What is the value of i after the doSomething(i) function call? //function definition int doSomething(int value) { value = 35; return value; value = 13; } //fragment of main program int i = 0; printf("%d\n", doSomething(i) ); A) 0 B) 13 C) 48 D) 35

a

21) What is the value of the following boolean expression? (1 && (4/3 || !(6))) A) 1 B) illegal syntax C) 0 D) false

a

22) Information Hiding is analogous to using A) a black-box methodology. B) actual parameters. C) formal parameters. D) an algorithmic design.

a

23) What is the value of x after the following code executes? int x = 10; if(x++ > 10) { x = 13; } A) 11 B) 9 C) 13 D) 10

a

24) What is the value of x after the following code fragment executes? double x = 36.0; x = sqrt(x); A) 6.0 B) 3.0 C) 36.0 D) 2.456

a

25) What is the output of the following program fragment? printf("%g\n", pow(4.0,2.0) ); A) 16 B) 8 C) 4 D) 2

a

26) Multiple arguments to a function are separated by A) commas. B) semicolons. C) colons. D) periods. E) comments.

a

28) What is the value of x after the following statements? int x, y, z; y = 10; z = 3; x = y * z + 3; A) 33 B) 30 C) garbage D) 60

a

28) What is the value returned by the following function? int function( void ) { int value = 35; return value + 5; value += 10; } A) 40 B) 35 C) 50 D) 10

a

29) What is the value of x after the following code executes? int x = 10; if( ++ x > 10) { x = 13; } A) 13 B) 10 C) 11 D) 9

a

31) What is the value of x after the following statements? int x; x = x + 30; A) garbage B) 30 C) 0 D) 33

a

31) When parameters are passed between the calling code and the called function, parameters and arguments are matched by A) their relative positions in the parameter and argument lists. B) their data types. C) their names. D) They are not matched up at all.

a

32) What is the output of the following program fragment? printf("%g\n", (double) (3/4) ); A) 0.0 B) 0.75 C) 0.5 D) 3

a

33) What is the output of the following code fragment? double size, volume = 16.0; size = sqrt(sqrt(volume)) / 3; printf("%.2f\n", size); A) 0.67 B) 0.6666667 C) 0 D) 0.00

a

33) What is the value of x after the following statements? double x; x = 0; x += 3.0 * 4.0; x -= 2.0; A) 10.0 B) 22.0 C) 14.0 D) 12.0

a

34) Given the following code fragment, and an input value of 3, what is the output that is generated? int x; printf("Enter a value\n"); scanf("%d", &x); if(x = 0) { printf("x is zero\n"); } else { printf("x is not zero\n"); } A) x is not zero. B) x is zero. C) unable to determine D) x is 3.

a

35) Which of the following boolean expressions tests to see if x is between 2 and 15 (including 2 and 15)? A) (x>= 2 && x <= 15) B) (2 <= x || x <= 15) C) (2 <= x <= 15) D) (x<= 15 || x >= 2)

a

37) What is the value of x after the following statements? double x; x = 15/4; A) 3.0 B) 60 C) 3.75 D) 4.0

a

32) Which of the following symbols has the highest precedence? A) && B) ++ C) - D) ||

b

33) What is wrong with the following for loop? int i; for(i = 0; i < 10; i -- ) { printf("Hello\n"); } A) i is not initialized. B) infinite loop C) cannot use a for-loop for this D) off-by-one error

b

34) Given the following enumerated data type definition, what is the value of SAT? enum MyType{SUN,MON,TUE,WED,THUR,FRI,SAT,NumDays}; A) 5 B) 6 C) 7 D) 8 E) unknown

b

36) The fabs(double num) function A) returns the negative value of num. B) returns the absolute value of num. C) returns the most fabulous number. D) returns the largest whole number <= num.

b

36) Which of the following statements is NOT legal? A) char ch = 'b'; B) char ch = "cc"; C) char ch = '0'; D) char ch = 65;

b

39) 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) 8 B) 10 C) 2 D) 6

b

40) What is the output of the following program segment? //function body int factorial(int n) { int product = 0; while(n > 0) { product = product * n; n--; } return product; } //program segment printf("%d\n", factorial(4) ); A) 4 B) 0 C) 48 D) 24

b

27) If you need to write a function that will compute the cost of some candy, where each piece costs 25 cents, which would be an appropriate function declaration? A) int calculateCost int count; B) char calculateCost(int count); C) int calculateCost(int count); D) int calculateCost(char name);

c

35) What is the value of x after the following statements? int x; x = 0; x = x + 30; A) garbage B) 0 C) 30 D) 33

c

37) Which of the following are equivalent to (!(x < 15 && y >= 3))? A) (x> 15 && y <= 3) B) (x>= 15 && y < 3) C) (x>= 15 || y < 3) D) (x> 15 || y < 3) E) B and C

c

40) What is wrong with the following switch statement? int ans; printf("Type y for yes on n for no\n"); scanf("%d", &ans); switch (ans) { case 'y': case 'Y': printf("You said yes\n"); break; case 'n': case 'N':printf("You said no\n"); break; default: printf("invalid answer\n"); } A) There are no break statements on 2 cases. B) nothing C) ans is an int. D) break; is illegal syntax.

c

41) Given the following code fragment, what is the output? int x = 5; if( x > 5) printf("x is bigger than 5. "); printf("That is all. "); printf("Goodbye\n"); A) Goodbye B) x is bigger than 5 C) That is all. Goodbye D) x is bigger than 5. That is all

c

42) If you need to write a do-while loop that will ask the user to enter a number between 2 and 5 inclusive, and will keep asking until the user enters a correct number, what is the loop condition? A) (2 > number && number > 5) B) (2 < 5 < number) C) (number < 2 || number > 5) D) (2 <= num <= 5) E) (2 <= number && number <= 5)

c

46) What is the output of the following code? printf( "This is a \\" ); A) Nothing, it is a syntax error. B) "This is a \\" C) This is a \ D) This is a

c

23) Which of the following is not a valid identifer? A) total3 B) myInt C) myInteger D) return

d

24) Another way to write the value 3452211903 is ________. A) 3.452211903e -09 B) 3.452211903x09 C) 3452211903e09 D) 3.452211903e09

d

25) Given the following code, what is the final value of i? int i,j; for(i = 0; i < 4; i++) { for(j = 0; j < 3; j++ ) { if(i == 2) break; } } A) 5 B) 0 C) 3 D) 4

d

27) Given the following code fragment, and an input value of 5, what is the output? int x; printf("Enter a value\n"); scanf("%d", &x); if( x < 3) { printf("small\n"); } else { if( x < 4) { printf("medium\n"); } else { if( x < 6) { printf("large\n"); } else { printf("giant\n"); } } } A) small B) medium C) giant D) large

d

29) What is the value of x after the following statement? double x; x = 3.0/4.0 + (3 + 2)/5; A) 5.75 B) 3.75 C) 4.75 D) 1.75

d

30) Given the following enumerated data type definition, what is the value of SAT? enum MyType{SUN=3,MON=1,TUE=3,WED,THUR,FRI,SAT,NumDays}; A) 8 B) 5 C) 6 D) 7 E) unknown

d

30) What is the output of the following code fragment? int x = 0; while( x < 5) printf("%d\n", x); x ++; printf("%d\n", x); A) 0 B) 4 C) 5 D) an unending list of zeroes

d

34) In the function declaration shown, the mechanism used to pass the parameters in this function is known as: double pow(double base, double exp); A) pass by name B) call by name C) call by value D) pass by value

d

35) When a variable is local to a function, we say that it has ________ of the function. A) constance B) value C) locality D) scope

d

37) What is the output of the following program fragment? printf("%g\n", (double) 3/4 ); A) 0 B) 0.5 C) 3 D) 0.75

d

38) What is the output of the following code fragment? int i = 5; switch(i) { case 0: i = 15;break; case 1: i = 25;break; case 2: i = 35;break; case 3: i = 40; default: i = 0; } printf("%d\n", i); A) 25 B) 40 C) 15 D) 0 E) 35

d


संबंधित स्टडी सेट्स

Ignatavicius Chapter 16: Care of Postoperative Patients

View Set

Combo with "Peds Exam 3a" and 2 others

View Set

Final Exam Review for Insur. Coding over Ch 7,8,10,11 and 12

View Set

Ch. 3.A - Legal Issues: Estate and Interest

View Set

Chapter 65: Caring for Clients with Skin, Hair, and Nail Disorders

View Set