A rows j columns i b ro ws i columns j c it depends

Info icon This preview shows pages 6–10. Sign up to view the full content.

View Full Document Right Arrow Icon
A) rows: j; columns: i B) ro ws: i; columns: j C) It depends on the code inside the inner loop Code Block 8 Code Block 9 Code Block 10 for(int i=0; i < 3; i++) { for (int j=i; j >= 0; j-=1) { cout << "* "; } cout << endl; } int x = 4; while (x > 1) { if (x % 2 == 0) { int x = 5; cout << x; } x--; } int count = 0; for (int i = 0; i < 5; ++i) { for (int j = 0; j < i; ++j) { ++count; } } cout << count; 32) What is output by the code block 8? A) * * * B) * * * C) * * * * * * D) * * * * * * * * * E) * * * * * * F) * * * * * * 33) How many times does the loop in Code Block 9 iterate? A) 0 B) 1 C) 2 D) 3 E) 4 F) the loop does not finish (infinite) 34) What is the final value of count, after Code Block 10 completes? A) 0 B) 5 C) 10 D) 11 E) 15 F) 25
Image of page 6

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Name (first and last): _________________________________ Username: ______________ Code Block 13 Code Block 14 void q(int x, int &b) { b = x * 2 + b; x = 4 * b; } int n(int a, int b) { return a + b; } int m(int &x, int &y) { y = x + 3; q(3, y); return x % y; } int main() { int a = 7, b = 11; q(a, b); cout << a << ' ' << b; // Line 1 cout << endl; a = 7, b = 11; b = n(a, b); cout << a << ' ' << b; // Line 2 cout << endl; a = 7, b = 11; a = n(m(a, b), 3); cout << a << ' ' << b; // Line 3 cout << endl; return 0; } void q(int x, int b) { b = x * 2 + b; x = 4 * b; } int n(int a, int b) { return a + b; } int main() { int a = 7, b = 11; a = n(q(a, b), a); // Line 1 a = n(a, a); // Line 2 cout << q(a, b); // Line 3 cout << n(a, b); // Line 4 return 0; } 35) What is output by line 1 of Code Block 13? A) 7 11 B) 7 25 C) 44 11 D) 44 25 E) 11 7 F) compiler error on line 36) What is output by line 2 of Code Block 13? A) 7 18 B) 44 55 C) 7 11 D) 44 69 E) 7 32 F) compiler error on line 37) What is output by line 3 of Code Block 13? A) 7 16 B) 10 10 C) 10 16 D) 17 10 E) 10 11 F) compiler error on line 38) The denoted Line 1 of the code block 14 causes a compiler error. A) true B) false 39) The denoted Line 2 of the code block 14 causes a compiler error. A) true B) false 40) The denoted Line 3 of the code block 14 causes a compiler error. A) true B) false 41) The denoted Line 4 of the code block 14 causes a compiler error. A) true B) false
Image of page 7
Name (first and last): _________________________________ Username: ______________ Code Block 15 Code Block 16 int main() { srand(667); vector <int> roll(4); int die; for(int i=0; i < 4; i++) { die = rand() % roll.size(); <STUDENT CODE HERE> } cout << "Blanks: " << roll.at(0) << endl; cout << "1s: " << roll.at(1) << endl; cout << "2s: " << roll.at(2) << endl; cout << "3s: " << roll.at(3) << endl; return 0; } int main() { vector <int> v(2); v.pop_back(); v.push_back(4); v.push_back(7); v.pop_back(); v.push_back(9); return 0; } 42) We are rolling a 4 sided die, the sides have dots on them to denote a number but one of the sides is blank, the others have one, two, or three dots. Fill in the code block 15 so each roll will be counted and after we can know how many of each we saw. A) roll.at(die) += 1; B) roll.at(i) += 1; C) roll.at(die - 1) += 1; D) roll.at(i - 1) += 1; 43) After the code block 16 is executed, what are the contents of v? A) 4 7 9 B) garbage 4 9 C) garbage 4 7 9 D) 0 4 7 9 E) 0 4 9 F) garbage garbage 4 7 9 44) What is output by the code block? vector <string> v(3); v.at(0) = "pants"; v.at(1) = "spant"; v.at(2) = "peanuts"; for(int i=0; i < v.size(); i++ ){ for (int j=0; j < v.at(i).size(); j=j+3) { cout << v.at(i).at(j); } } A) peanuts B) pantsspantpeanuts C) ptsnpns D) ptsnpn E) nothing F) compiler error
Image of page 8

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Name (first and last): _________________________________ Username: ______________ Code Block 17 Code Block 18 Code Block 19 vector <int> v(5); v.at(0) = 6; v.at(1) = 3; v.at(2) = 1; v.at(3) = 4; v.at(4) = 1; for(int i=0; i < v.size(); i++) { if(v.at(i) % 2 == 0) { v.pop_back(); } else if(v.at(i) % 3 == 0) { v.push_back(3); } } int max(int a, int b) { if (a == b) { return a; } else if (a > b) { return a; } return 0; } vector <string> v(5); v.at(0) = "he"; v.at(1) = "phq"; v.at(2) = "q425"; v.at(3) = "mxxsdf"; v.at(4) = "so352f"; for(int i=1; i < v.size(); i++) { cout << v.at(i).at(i); } 45) Given the definition vector <vector<string > > v; and that none of the at() calls goes out of range.
Image of page 9
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern