What is the color of the pixel at x, y? (Note that getpixel() returns the color of the pixel at the specified coordinate.) int x = 100, y = 100; putpixel(x, y, RED); if (getpixel(x, y) == RED) putpixel(x, y, GREEN); if (getpixel(x, y) == BLUE) putpixel(x, y, YELLOW); if (getpixel(x, y) == GREEN) putpixel(x, y, BLUE); A. RED B. GREEN C. YELLOW **D. BLUE E. PURPLE How many lines of output are produced in the following? int i; int x[5] = {0, 2, 3, 1, 4}; for (i=0; i<3 && x[x[i]] < 3; i++) { cout << "computing\n"; } if (i >= 3) cout << "computing\n"; A. 4 B. 2 **C. 1 D. 0 E. None of the above How many lines of output are produced in the following? int i, j; int x[5] = {0, 2, 3, 1, 4}; for (i=0; i<3 ; i++) { for (j=0; j> str1 >> str2; cout << strelen(str1) + strlen(str2); What will be printed out? A. 33 B. 15 **C. 9 D. 13 E. None of the above Given the following bit of code, which of the following is equivalent to *(q+4)? int a[10], *p, *q; p = a; q = &a[4]; A. *p[8] B. &p[8] C. a+8 **D. a[8] E. a[4]+4 Examine the following code and indicate what will be printed. int index[5] = {3, 1, 2, 0, 4}; char str[] = "This_sucks"; for (int i=1; i<5; ++i) cout << str[index[i-1]+1]; A. This_ B. ishs C. shiT **D. _ish E. This What is the output of the following code ? const int X_SIZE = 600; const int Y_SIZE = 450; void step(int &ant_x, int &ant_y, int dir) { switch (dir) { case 0: ant_x = (ant_x + 1) % X_SIZE; break; case 1: ant_y = (ant_y + 1) % Y_SIZE; break; case 2: ant_x -= 1; if (ant_x < 0) ant_x += X_SIZE; break; case 3: ant_y -= 1; if (ant_y < 0) ant_y += Y_SIZE; break; default: cout << dir << " is undefined\n"; exit (EXIT_FAILURE); } } int main() { int x = 100, y = 200, dir = 0; step(x, y, dir); step(x, y, dir++); cout << x << " " << y << endl; return 0; } A. 100 200 B. 101 200 C. 101 201 D. 100 201 **E. None of the above What is the output of the following code ? void turn_left(int dir) { dir = (dir - 1); } void turn_right(int &p_dir) { p_dir = (p_dir + 1); } int main() { int dir1 = 3, dir2 = 3; turn_left(dir1); turn_right(dir2); cout << dir1 << " " << dir2 << endl; return 0; } A. 3 3 B. 2 0 **C. 3 4 D. 2 3 E. none of the above What is the output of the following code? char c = 'b'; switch(c) { case 'a': cout << "0"; case 'b': cout << "1"; case 'c': cout << "2"; default: cout << "3"; } A. 01 B. 1 **C. 123 D. 12 E. None of the above Consider the following code fragment: if_stream in_stream; in_stream.open("input.txt"); int cat; char dog, pig[100]; Which of the following lines will never read more than one character from the file "input.txt"? A. in_stream >> cat; B. in_stream >> dog; **C. in_stream.get(dog); D. in_stream >> pig; E. Two or more of the above Suppose the file "hello.txt" contains the text "hello, world...". What will the following code fragment print? char ch; int i = 0; ifstream in; in.open("hello.txt"); in.get(ch); while (ch != '.') { ++i; in.get(ch); } cout << i << endl; A. 0 B. 13 **C. 12 D. 2 E. None of the above What will the following program fragment output? int a[10], i; a[0] = a[1] = 1; for (i=2; i<10; ++i) { a[i] = a[i-1] + a[i-2]; } cout << a[5]; A. 0 B. 1 C. 5 **D. 8 E. 13 What picture will this code produce? Reminder: COLOR(r,g,b) is a macro that produces a particular red-green-blue color value. const int SIZE=512; for (int row=0; row 5) return (beavis(hehe-5) * hehe); else return 2; } What does "beavis(6)" evaluate to? A. 2 B. 5 *C. 12 D. 6 E. 30 What is most troublesome about this recursive function: int stan(int kyle) { if (kyle == 0) return 1; return (stan(kyle-2)*2-1); } A. It cannot handle floating point values B. For some inputs, it will return a negative number C. "kyle" is a bad choice of variable name *D. For some inputs, it will recurse forever (i.e., never terminate) E. stan(0) produces the same value as stan(2) What is wrong with this function that is supposed to print out the elements of a linked list? struct link { int data; struct link *next; } void print_link_list(link *l) { cout << l->data << endl; if (l != NULL) print_link_list(l->next); } A. "l->data" and "l->next" should be "l.data" and "l.next" *B. It will blow up if called with a NULL list C. The recursion will never terminate. D. The argument to the function should be "link l" not "link *l" E. The function should be defined as "int print_link_list(...)" not "void print_link_list(...)" Given the print_link_list() function from the question above, what will "print_link_list(&x1)" return, assuming that we have defined the following: link x1, x2, x3; x1.data = 7; x1.next = &x2; x2.data = 4; x2.next = &x3; x3.data = 9; x3.next = NULL; A. 7 9 4 *B. 7 4 9 C. 7 D. 4 9 7 E. none of the above Given the print_link_list() function from question above, what will "print_link_list(&x3)" return, assuming that we have defined the following: link x1, x2, x3; x1.data = 7; x1.next = NULL; x2.data = 4; x2.next = &x1; x3.data = 9; A. 9 4 7 B. 9 7 4 C. 7 D. 9 7 *E. none of the above Given the print_link_list() function from the question above, what will "print_link_list(&x1)" return, assuming that we have defined the following: link x1, x2, x3; x1.data = 7; x1.next = &x2; x2.data = 4; x2.next = &x3; x3.data = 9; A. 7 9 4 B. 9 7 4 C. 7 D. 9 7 *E. cannot be determined Given the print_link_list() function from the question above, what will "print_link_list(&x2)" return, assuming that we have defined the following: link x1, x2, x3; x1.data = 7; x1.next = NULL; x2.data = 4; x2.next = &x3; x3.data = 9; x3.next = &x1; *A. 4 9 7 B. 7 9 4 C. 7 D. 9 7 E. cannot be determined Given the following declarations: int k = 7; struct coords { int x[20]; int y[20]; }; double f = 9.7; coords q[10]; const coords *v = &q[1]; which of the following expressions is invalid? A. q[1].x *B. q[1]->x C. v->y[2] D. &f E. none of the above Given the above declarations, which of the following expressions is invalid? A. int(f) + q[4].y[0] B. *(q[2].x) C. &v *D. &(k+3) E. none of the above Given the above declarations, which of the following expressions is invalid? *A. x[4] B. (*v).x[4] C. *(&f) D. q[k].x[k] E. none of the above In the following code, what will be printed? enum {DOG, CAT, PIG, HORSE} animal; animal = PIG; cout << animal << endl; A. PIG B. pig C. 0 D. 1 *E. 2 What is most troublesome about the following declaration? enum {TRUE, FALSE} flag; A. The enumeration should include UNDEFINED B. The United States flag is red, white, and blue *C. TRUE will have value 0, and elsewhere in the C/C++ language non-zero values are considered true. D. TRUE will have value 1, and elsewhere in the C/C++ language zero values are considered true. E. flag is not assigned an initial value What will "update(FROSH)" return given the following function definition? enum {FROSH, SOPH, JUNIOR, SENIOR, POSTGRAD} year; year update(year y) { switch(y) { case FROSH: return SENIOR; case JUNIOR: return POSTGRAD; case SOPH: return FROSH; default: return JUNIOR; } } A. FROSH B. SOPH C. JUNIOR *D. SENIOR E. POSTGRAD Given the definition from the previous question, what will "update(update(FROSH))" return? A. FROSH B. SOPH *C. JUNIOR D. SENIOR E. POSTGRAD (17) Given the definition from the previous question, what will "update(update(SOPH))" return? A. FROSH B. SOPH C. JUNIOR *D. SENIOR E. POSTGRAD What does the following code output? int x = 7; cout << x++ << " "; cout << x << endl; A. 8 8 B. 8 7 C. 7 7 *D. 7 8 E. none of the above What does the following code output? int x = 7; cout << --x << " "; cout << x << endl; *A. 6 6 B. 6 7 C. 7 7 D. 7 6 E. none of the above What will the following code output? struct student { char last_name[50]; char grade; } student class[4] = {{"Mozer",'B'},{"Howe",'A'},{"Daniel",'C'},{"Feng",'A'}}; int i, ct = 0; for (i=0; i<4; ++i) ct += (class[i].grade == 'A'); cout << ct << endl; A. 0 B. 1 *C. 2 D. 3 E. 4 If we change the loop of the previous question as follows, what will the code output? for (i=0; i<3; ++i) ct += (class[i].grade == 'B' && class[i+1].grade == 'C'); *A. 0 B. 1 C. 2 D. 3 E. 4 If we change the loop of the earlier question as follows, what will the code output? for (i=0; i<4; i+=2) if (class[i].grade == 'A') ++ct; *A. 0 B. 1 C. 2 D. 3 E. 4 If we change the loop of the earlier question as follows, what will the code output? for (i=0; i<4; ++i) if (class[i].last_name[1] == 'e') ++ct; A. 0 B. 1 *C. 2 D. 3 E. 4 Which of the following declarations make the most sense to represent a set of 25 lines in a graphics program, each line defined by a pair of (x,y) coordinates? A. struct { int x[25], y[25]; } lines[2]; D. struct { int p[25][4]; } lines; *B. struct { int x[2], y[2]; } lines[25]; E. struct { int p[25]; } lines[4]; C. struct { int x[25][2]; } lines; Which of the following is equivalent to int scores[5]; A. int *scores; B. int scores; *scores = new int[5]; *C. int *scores; *scores = new int[5]; D. int scores; scores = new [5] int; E. int *scores; scores = & new int[5]; Which of the following expressions evaluates to be a pointer, given the declaration below? int homer[40], *bart, marge; A. *bart D. marge B. homer[12] *E. none of the above C. *(homer+1) Which of the following expressions evaluates to be an integer value, given the declarations of the previous question? A. &marge D. homer+2 *B. homer[7] E. none of the above C. bart Which of the following is not a pointer, given the declaration below? int fred[30][2], wilma[9], dino, *pebbles; A. fred[7] *D. *(fred[4]) B. &fred[7][1] E. pebbles C. wilma+8 What does the expression (7 % 4) - 9 / 3 evaluate to? A. -3 B. -2 *C. 0 D. 2 E. 3 What does the expression (9 > 4 && 6 <= 4) evaluate to? *A. 0 B. 1 C. 4 D. 6 E. 9 What does (f1 / f2 + d) evaluate to given the definitions below? double f1 = 4, f2 = 8; int d = 8; A. 0 *D. 8.5 B. 0.25 E. cannot be determined C. 8 What will be printed by the following code: if (7 || 9 > 10) cout << "don't make me "; if (9 != 12 - 3) cout << "kick "; else cout << "your ash"; A. kick your ash D. don't make me kick your ash B. don't make me *E. don't make me your ash C. don't make me kick Which of the following is equivalent to (x > y || y > x) ? A. x == y D. x && y *B. x != y E. x > (y || y) > x C. x < y && y < x What will be output by the following code? int i = 2, j = 0; while (j <= 5) { cout << j << " "; if (i) { ++j; --i; } ++j; } A. 0 2 4 D. 0 1 2 3 4 B. 0 1 2 3 4 5 E. 0 2 4 6 8 10 *C. 0 2 4 5 How many times will "give up" be printed in the following code? for (int i=1; i<4; ++i) { for (int j=3; j>0; --j) { cout << "give up "; } } A. 16 B. 3 C. 12 *D. 9 E. 4 Which of the following are true of the function orange given the prototype "char *orange(int banana, double pear)"? A. returns a character *B. returns a pointer to a character C. returns an integer value D. returns a double value E. none of the above (41) Which loop construct is equivalent to while (i < 7) { ... ++i; } *A. for (;i<7;++i) { ... } D. two or more of the above B. for (i=0; i<7; ++i) { ... } E. none of the above C. do { ... ++i; } while (i<7); Given two variables m1 and m2, which code will guarantee that the larger of the two is placed into mmax? A. if (m1 > m2) D. if (m1 > mmax) mmax = m1; mmax = m2; else B. if (m1 < m2) mmax = m1; mmax = m2; *E. mmax = (m1 > m2 ? m1 : m2); C. mmax = m1; if (m2 > mmax) mmax = m1; What will "ff(4+3)-2*ff(5)" evaluate to, given the definition: int ff (int x) { return x*2; } A. -10 *B. -6 C. 6 D. 10 E. -3 Given the following code, what will be output? #define SUM(x,y) x+y cout << 5 * SUM(2,3) * 2 << endl; A. 50 *B. 16 C. 11 D. 0 E. 100 How many lines of output are produced by the following code? int x[5] = {2, 4, 1, 0, 3}; for (i=0; i<5 && x[4-i] < 4; i++) cout << "computing\n"; A. 0 B. 1 C. 2 *D. 3 E. 4 How many lines of output are produced in the following? int x[5] = {0, 4, 2, 3, 1}; for (int i=3; i>=0 ; i--) { for (int j=0; j