The answers are in red. Please explain the answers using C++ logic Use the follo
ID: 3626521 • Letter: T
Question
The answers are in red. Please explain the answers using C++ logic
Use the following function definition for the next 3 questions
bool found( const vector<int> &v, int value )
{
/* Line A */
for ( int i = 0; i < v.size(); ++i )
{
/* Line B */
if ( v[i] == value )
{
/* Line C */
}
else
{
/* Line D */
}
}
/* Line E */
}
4.
is contained
anywhere within
and false otherwise, which line or lines must have the statement:
return true;
?
a.
Line A
b.
Line B
c.
Line C
d.
Line D
e.
Line E
f.
Lines D and E
5.
is contained
anywhere within
and false otherwise, which line or lines must have the statement:
return false;
?
a.
Line A
b.
Line B
c.
Line C
d.
Line D
e.
Line E
f.
Lines D and E
Page 2 of 2
6.
has been
declared and initialized, which of the following statements correctly calls the
function defined on the previous page?
a.
if ( found(v, n) )
cout << "Found" << endl;
b.
if ( found(v(), n) )
cout << "Found" << endl;
c.
if ( v.found(n) == true )
cout << "Found" << endl;
d.
if ( found(v[], n) == true )
cout << "Found" << endl;
e.
if ( found(v[n], 10 )
cout << "Found" << endl;
f.
if ( found(v[v.size()], n) == true )
cout << "Found" << endl;
Explanation / Answer
line c is correct
because in line c your checking codition that element presents or not
line e is correct
if element not found anywhere in vector
at last u have to return false
if found(v,n)
correct prototype for function declaration
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.