A the variable y was not declared in the function b

Info icon This preview shows pages 4–7. Sign up to view the full content.

View Full Document Right Arrow Icon
A) The variable y was not declared in the function B) The cmath library was not included in the program header C) sqrt was declared in main, but not in the function D) The cmath library was not included in main 22) Which expression gets a random number between -4 and 2 inclusive? A) -4 + rand() % 7 B) -4 + rand() % 6 C) rand() % (-4 + 2) D) rand() % 2 23) You are building a function to test whether a vector of ints is sorted in ascending order (i.e. every element is equal to or greater than its preceding value). Which of the following options is the best choice for the function header? (Note that some options may "work", but still not be the best choice) A) bool test(vector<int> v) B) bool isAscending(vector<int> & v) C) vector<int> Ascending(const vector<int> & v) D) void Ascending(vector<int> & v) E) bool isAscending(const vector<int> & v) F) void Ascending(const vector<int> & v) 24) Assuming 'y' is not a vowel, the following expression is true only when char c contains a vowel. c == 'a' || 'e' || 'i' || 'o' || 'u' A) true B) false
Image of page 4

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 5 Code Block 6 Code Block 7 int x = 7; while (x > 1) { if (x % 2 == 0) { x--; } else { x = x - 3; } } int x = 7; while (x > 1) { if (x / 2 > 1) { --x; } } int x = 4; while (x > 1) { if (x % 2 == 0) { int x = 5; cout << x; } --x; } 25) What is the value of x after the Code Block 5 executes? A) -3 B) -2 C) -1 D) 0 E) 1 F) the loop does not finish (infinite) 26) How many times does the loop in Code Block 6 iterate? A) 0 B) 6 C) 7 D) the loop does not finish (infinite) 27) What is output by Code Block 7? A) 55 B) 54 C) 52 D) 42 E) no output F) the loop does not finish (infinite) 28) You are building a function to print out a table; the data is held in a 2-dimensional vector: vector< vector<double> > table; with each row of the table stored as a vector<double> (Note that not all rows are guaranteed to be the same length). Which of the following options is the best choice for the function header? (Note that some options may "work", but still not be the best choice) A) void displayTable(vector< vector<double> > & tbl) B) void displayTable(const vector< vector<double> > & tbl) C) double displayTable(vector< vector<double> > tbl) D) double displayTable(const vector< vector<double> > & tbl) E) bool displayTable(vector< vector<double> > & tbl) 29) In the function of the previous question, you will need a nested loop: which of these options is the correct loop header for the outer loop? A) for (int i = 0; i < tbl.at(0).size(); ++i) B) for (int i = 0; i < tbl.at(i).size(); ++i) C) for (int i = 0; i < tbl.size(); ++i) D) for (int i = 1; i < tbl.size() - 1; ++i) E) for (int i = 0; i <= tbl.size(); ++i)
Image of page 5
Name (first and last): _________________________________ Username: ______________ 30) In the function of the previous questions: which of these options is the correct loop header for the inner loop? A) for ( int j = 0; j < tbl.at(i).size(); ++j) B) for (int j = 0; j < tbl.at(0).size(); ++j) C) for (int j = 0; j < tbl.at(j).size(); ++j) D) for( int j = 0; j < tbl.size(); ++j) E) for( int j = 0; j < tbl.at(i).size(); ++i) 31) In the loops of the previous two questions, which indices index the rows, and which the columns?
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
Image of page 7
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