UCR_CS10_Spr15_Final (Solution).docx

# Sfindi a 4 b 5 c 6 d 7 e stringnpos f does not

• Test Prep
• 12

This preview shows pages 2–5. Sign up to view the full content.

s.find('i') A) 4 B) 5 C) 6 D) 7 E) string::npos F) does not compile 10) Given string s has the value "mythicising", what is the result of the following expression? s.find("myths") A) 0 B) 1 C) 3 D) 4 E) string::npos F) runtime error 11) Which of the options is equivalent to this expression? !(myChar >= 'a' && myChar <= 'z') A) myChar < 'a' || myChar > 'z' B) myChar <= 'a' || myChar >= 'z' C) myChar < 'a' && myChar > 'z' D) myChar <= 'a' && myChar >= 'z'

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

Name (first and last): _________________________________ Username: ______________ Code Block 1 Code Block 2 //Passes in a vector full of integers //and an value to look for. //Returns the location of the first //instance of val within v, //or returns -1 if val not found int find( const vector<int> &v, int val ){ for ( int i = 0; i < v.size(); ++i ){ /* Line A */ if (v.at(i) == val){ /* Line B */ } else{ /* Line C */ } /* Line D*/ } /* Line E */ } string s = "H3110 W0R1D"; for(int x = 0; [CONDITIONAL] ; x++) { cout << s.at(x); } 12) Which expression is true only when double x is non-negative? A) x > 0 B) x != 0 C) x >= 0 D) x > -1 E) x >= -1 F) 0 > x 13) isalpha is a function that takes a char argument and returns true if that char is alphabetic (i.e. a letter of the alphabet), false if it is anything else (numeric, punctuation, etc.) Which of these loop conditionals will correctly control the loop in Code Block 2 to print the string, stopping at the first non-alpha character? A) x < s.size() || isalpha(s.at(x)) B) x < s.size() && isalpha(s.at(x)) C) x <= s.size() || isalpha(s.at(x)) D) x > s.size() || isalpha(s.at(x)) E) x <= s.size() && isalpha(s.at(x)) F) none of the listed answers fill the requirements 14) What does this expression evaluate to? 0 % 6 A) 6 B) 0 C) -1 D) garbage E) runtime error F) compile error 15) What does this expression evaluate to? 6 % 0 A) 6 B) 0 C) -1 D) garbage E) runtime error F) compile error 16) What does this expression evaluate to? 10.5 - 9 / 2 A) 6.0 B) 5.5 C) 6.5 D) 0.75 E) garbage F) compile error 17) For the function find ( Code Block 1 ) to work correctly, which line or lines must have the statement: return i ; ? A) Line A B) Line B C) Line C D) Line D E) Line E F) Lines C and E 18) For the function find ( Code Block 1 ) to work correctly, which line or lines must have the statement: return -1; ? A) Line A B) Line B C) Line C D) Line D E) Line E F) Lines C and E
Name (first and last): _________________________________ Username: ______________ Code Block 3 Code Block 4 double temp; cin >> temp; bool fever = (temp >= 100.4); <CODE HERE> vector<int> v(10); for (int i = 0; i < v.size(); ++i){ if (i-1 >= 0 && v.at(i-1) < 500){ /*Line A*/ v.at(i) = v.at(i-1) + v.at(i); /*Line B*/ } if (v.at(i+1) < 500 && i+1 < v.size()){ /*Line C*/ v.at(i+1) = v.at(i+1) + v.at(i); /*Line D*/ } } 19) Given a user entered value in temp, and given that "fever" means a temperature equal to or greater than 100.4 F, which code block at <CODE HERE> in Code Block 3 will correctly output "fever"? A) if (fever){ cout << "fever"; } B) if (fever == temp){ cout << "fever"; } C) if (fever = true){ cout << "fever"; } D) if (temp){ cout << "fever"; } 20) Which line in Code Block 4 will cause a runtime error? (out_of_range) A) Line A B) Line B C) Line C D) Line D 21) A programmer attempts to compile code containing a function with the statement double x = sqrt(y); generating the compiler error error: 'sqrt' was not declared in this scope What is a possible cause of this error?

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

This is the end of the preview. Sign up to access the rest of the document.
• Winter '18

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern