100% found this document useful (2 votes)
3K views

CPP Chapter 1 To 9 Assessment

The document provides an overview of advanced C++ programming concepts including: - Templates and generic programming which allow functions and classes to work with different data types. - Standard Template Library (STL) containers like vector, deque, list, set, and map which provide common data structures. - Iterators which provide a uniform way to access elements in STL containers. - Algorithms like sort, binary_search, and find which operate on iterators to perform actions on STL containers. The document discusses how to use templates, STL containers, iterators, and algorithms to write flexible, reusable C++ code. Examples are provided to illustrate key concepts.

Uploaded by

aj yanson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
3K views

CPP Chapter 1 To 9 Assessment

The document provides an overview of advanced C++ programming concepts including: - Templates and generic programming which allow functions and classes to work with different data types. - Standard Template Library (STL) containers like vector, deque, list, set, and map which provide common data structures. - Iterators which provide a uniform way to access elements in STL containers. - Algorithms like sort, binary_search, and find which operate on iterators to perform actions on STL containers. The document discusses how to use templates, STL containers, iterators, and algorithms to write flexible, reusable C++ code. Examples are provided to illustrate key concepts.

Uploaded by

aj yanson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 252

https://source4educ.blogspot.com/p/cpp-advance-programming-c.

html
Score for this attempt: 24 out of 30
Submitted Dec 10 at 2:59pm
This attempt took 7 minutes.
 
Question 1
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>

int main ()
{
    std::vector<int>    v1;        // LINE I
    v1.push_back(10);            // LINE II
    std::cout<<v1.front()<<":"<<v1.back()<<std::endl;        // LINE III
    return 0;
}

  
compilation fails due to error in line II
 

  
program displays 0:10
 

  
compilation fails due to error in line I
 

  
compilation fails due to error in line III
 

  
code compiles and executes successfully
 
 
Question 2
1 / 1 pts
Which statement is true about the code below?

#include <vector>
#include <iostream>
using namespace std;
int main ()
{
    vector<int>    v1(4, 3);
    v1.push_back(4);
    for(vector<int>::iterator i = v1.rbegin(); i != v1.rend(); ++i)
    {
        cout << *i << " ";
    }
    cout<< endl;
    return 0;
}

  
v1.capacity() and v1.size() return the same value
 

  
program displays 3 3 3 3 4
 

  
program displays 4 3 3 3 3
 

  
program displays 4 4 4 4
 

  
program will not compile
 
 
Question 3
1 / 1 pts
Which sentences are 100% true about the code below (multiple choice) when control
reaches return. Choose all that apply.

#include <vector>
#include <iostream>

using namespace std;

int main ()
{
    vector<int>    v1(10, -1);
    vector<int> v2;
    v2.reserve(10);
    for(unsigned i=0; i < 10; i++)
    {
        v2.push_back(i);
    }
    return 0;
}

  
both vectors v1 and v2 have the same capacity
 

  
size of vector v2 less than 20
 

  
value returned by size() is the same for vectors v1 and v2
 

  
code will not compile
 
 
Question 4
1 / 1 pts
Which sentence is 100% true about the code below when control reaches return?

#include <vector>
#include <iostream>
#include <stdexcept>

using namespace std;

int main ()
{
    int tab[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    vector<int> v1(tab, tab+10);
    vector<int> v2(v1.size(), 0);
    try
    {
        for(unsigned i=0; i<=v1.size(); ++i)
        {
            int tmp = v1[i];                // LINE I
            v1[i] = v1.at(v1.size()-i);        // LINE    II
            v1.at(i) = tmp;                    // LINE III
            cout<<v1[i] << " ";
        }
    }
    catch(...)
    {
        cout<<"Exception!"<<endl;
    }

    return 0;
}

  
program will run and print output: Exception!
 

  
the exception will be thrown at line LINE III
 

  
program will run and print output: 10 9 8 7 6 5 4 3 2 1 Exception!
 

  
the exception will be thrown at line LINE I
 

  
this program will not compile
 
 
Question 5
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <deque>
#include <iostream>

using namespace std;

template<typename T> ostream & print(T & start, T & end)


{
    for(; start != end; ++start)
    {
        cout<< *start<< " ";
    }
    return cout;
}

int main()
{
    int tab[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    deque<int> d1(tab, tab+10);
    deque<int> d2;
    deque<int>::iterator it;
    for(it = d1.begin(); it != d1.end(); ++it)
    {
        d2.push_back(d1[d1.end()-it-1]);    //LINE I
    }
    print(d2.rbegin(), d2.rend()) << endl;    //LINE II
    return 0;
}

  
program will run successfully and display: 10 9 8 7 6 5 4 3 2 1
 

  
code will not compile due to error in line LINE II
 

  
code will not compile due to error in line LINE I
 

  
program will run successfully and display: 1 2 3 4 5 6 7 8 9 10
 

  
the result of program execution is unpredictable or there might be runtime exception
 
 
Question 6
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <deque>
#include <iostream>

using namespace std;

template<typename T> ostream & print(T const & start, T const & end)
{
    for (T i = start; i != end; ++i)
    {
        cout << *i << " ";
    }
    return cout;
}

int main()
{
    int tab[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    deque<int> d1(tab, tab+10);
    
    deque<int>::const_iterator it = d1.begin()+3;
    d1.erase(it, it + 1);
    print(d1.begin(), d1.end());
    d1.clear();
    cout<<d1.size()<<endl;
    return 0;
}

  
program will run successfully and display: 1 2 3 6 7 8 9 10 8
 

  
program will run successfully and display: 1 2 3 5 6 7 8 9 10 0
 

  
program will run successfully and display: 1 2 3 5 6 7 8 9 10 9
 

  
program will run successfully and display: 1 2 3 6 7 8 9 10 0
 

  
code will not compile
 
 
PartialQuestion 7
0.5 / 1 pts
Which methods from the std::deque class can be used to check if there are elements in
the container? Choose all that apply.
 

  
there is no such method
 

  
is_empty()
 

  
empty()
 

  
size()
 

  
clear()
 
 
Question 8
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <deque>
#include <iostream>

using namespace std;

template<typename T> ostream & print(const T & start, const T & end)
{
    T tmp = start;
    for(; tmp != end; ++tmp)
    {
        cout<< *tmp<< " ";
    }
    return cout;
}

int main()
{
    int tab[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    deque<int> d1(tab, tab+10);
    deque<int> d2;

    while(!d1.empty())
    {
        d2.push_front(d1.back());        //    LINE I
        d1.pop_front();                    //    LINE II
    }
    print(d2.begin(), d2.end())<<": "<<d2.size()<<endl;
    return 0;
}

  
program will run successfully and display: 10 10 10 10 10 10 10 10 10 10 : 10
 

  
code will not compile due to error in line marked LINE II
 

  
code will not compile due to error in line marked LINE I
 

  
program will run successfully and display: 1 2 3 4 5 6 7 8 9 10 : 10
 

  
program will run successfully and display: 1 1 1 1 1 1 1 1 1 1 : 10
 
 
Question 9
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <list>
#include <deque>
#include <iostream>

using namespace std;

template<typename T> ostream & print(const T & start, const T & end)
{
    T tmp = start;
    for(; tmp != end; ++tmp)
    {
        cout<< *tmp<< " ";
    }
    return cout;
}
class A
{
public:
    int a;
public:
    A(int a):a(a) {}
    A(const A & a) {}
};

ostream & operator<<(ostream & c, const A & o)


{
    c<<o.a;
    return c;
}

int main()
{
    int tab[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    list<A> l1(tab, tab+10);
    deque<A> d1;
    list<A>::iterator it;
    for(it = l1.begin(); it != l1.end(); ++it)
    {
        d1.insert(d1.begin(), it[0]);
    }
    print(d1.begin(), d1.end())<<endl;
    return 0;
}

  
code will not compile
 

  
program will run successfully and display: 1 2 3 4 5 6 7 8 9 10
 

  
program will run successfully but the result displayed cannot be predicted
 

  
program will run successfully and display: 10 9 8 7 6 5 4 3 2 1
 
 
Question 10
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <list>
#include <deque>
#include <iostream>

using namespace std;

template<typename T> ostream & print(const T & start, const T & end)
{
    T tmp = start;
    for(; tmp != end; ++tmp)
    {
        cout<< *tmp<< " ";
    }
    return cout;
}
class A
{
public:
    int a;
public:
    A(int a):a(a) {}
    A(const A & a) {}
};

ostream & operator<<(ostream & c, const A & o)


{
    c<<o.a;
    return c;
}

int main()
{
    int tab[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    list<A> l1(tab, tab+10);
    deque<A> d1;
    list<A>::iterator it;

    for(it = l1.begin(); it != l1.end(); ++it)


    {
        d1.insert(d1.begin(), it[0]);
    }
    print(d1.begin(), d1.end())<<endl;
    return 0;
}

  
program will run successfully and display: 1 2 3 4 5 6 7 8 9 10
 

  
program will run successfully but the result displayed cannot be predicted
 

  
program will run successfully and display: 10 9 8 7 6 5 4 3 2 1
 

  
code will not compile
 
 
PartialQuestion 11
0.5 / 1 pts
What will happen when you attempt to compile and run the following code? Choose all
that apply.
#include <list>
#include <iostream>

using namespace std;

template<typename T> ostream & print(T & start, T & end)


{
    for(; start != end; ++start)
    {
        cout<< *start<< " ";
    }
    return cout;
}

int main()
{
    int tab[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    list<int> l1(tab, tab+10);
    list<int> l2;
    list<int>::iterator it;
    for(it = l1.begin(); it != l1.end(); ++it)
    {
        l2.push_back(l1[l1.end()-it-1]);    //LINE I
    }
    print(l2.begin(), l2.end()) << endl;    //LINE II
    return 0;
}

  
the result of program execution is unpredictable or there might be runtime exception
 

  
program will run successfully and display: 1 2 3 4 5 6 7 8 9 10
 

  
program will run successfully and display: 10 9 8 7 6 5 4 3 2 1
 

  
code will not compile due to error in line LINE II
 

  
code will not compile due to error in line LINE I
 
 
PartialQuestion 12
0.5 / 1 pts
What will happen when you attempt to compile and run the following code? Choose all
that apply.

#include <list>
#include <iostream>
#include <functional>

using namespace std;

template<typename T> ostream & print(T const & start, T const & end)
{
    for (T i = start; i != end; ++i)
    {
        cout << *i << " ";
    }
    return cout;
}

int main()
{
    int tab[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    list<int> l1(tab, tab+10);
    
    list<int>::const_iterator it = l1.begin()+3;    //LINE I
    l1.erase(it, advance(it,1));                    //LINE II
    print(l1.begin(), l1.end());
    l1.clear();                                        //LINE III
    cout<<l1.size()<<endl;
    return 0;
}

  
code will not compile due to error in line LINE III
 

  
program will run successfully and display: 1 2 3 5 6 7 8 9 10 0
 

  
program will run successfully and display: 1 2 3 5 6 7 8 9 10 9
 

  
code will not compile due to error in line LINE II
 

  
code will not compile due to error in line LINE I
 
 
PartialQuestion 13
0.5 / 1 pts
Which methods from the std::list class can delete all the elements from the collection in
one call? Choose all that apply.

  
erase()
 

  
delete()
 

  
there is no such method
 

  
clear()
 

  
empty()
 
 
IncorrectQuestion 14
0 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <list>
#include <iostream>

using namespace std;

template<typename T> ostream & print(const T & start, const T & end)
{
    T tmp = start;
    for(; tmp != end; ++tmp)
    {
        cout<< *tmp<< " ";
    }
    return cout;
}

int main()
{
    int tab[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    list<int> l1(tab, tab+10);
    list<int> l2;
    l2.resize(10);

    while(!l1.empty())
    {
        
        l2.insert(l2.end(), l1.front());
        l1.pop_front();
    }
    print(l2.begin(), l2.end())<<": "<<l2.size()<<endl;
    return 0;
}

  
program will run successfully and display: 1 2 3 4 5 6 7 8 9 10 : 10
 

  
none of these
 

  
program will run successfully and display: 10 9 8 7 6 5 4 3 2 1 : 20
 

  
program will run successfully and display: 10 9 8 7 6 5 4 3 2 1 : 10
 

  
program will run successfully and display: 1 2 3 4 5 6 7 8 9 10 : 20
 

  
code will not compile
 
 
Question 15
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <list>
#include <iostream>

using namespace std;

template<typename T> ostream & print(const T & start, const T & end)
{
    T tmp = start;
    for(; tmp != end; ++tmp)
    {
        cout<< *tmp<< " ";
    }
    return cout;
}
class A
{
public:
    int a;
public:
    A(int a):a(a) {}
};

ostream & operator<<(ostream & c, const A & o)


{
    c<<o.a;
    return c;
}

int main()
{
    int tab[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    list<A> l1(tab, tab+10);
    list<A> l2;
    list<A>::iterator it;
    for(it = l1.begin(); it != l1.end(); ++it)
    {
        l2.push_front(it);
    }
    print(l2.begin(), l2.end())<<endl;
    return 0;
}

  
program will run successfully but the result displayed cannot be predicted
 

  
program will run successfully and display: 10 9 8 7 6 5 4 3 2 1
 

  
program will run successfully and display: 1 2 3 4 5 6 7 8 9 10
 

  
code will not compile
 
 
PartialQuestion 16
0.5 / 1 pts
What will happen when you attempt to compile and run the following code? Choose all
that apply.

#include <list>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

template<typename T> ostream & print(const T & start, const T & end)
{
    T tmp = start;
    for(; tmp != end; ++tmp)
    {
        cout<< *tmp<< " ";
    }
    return cout;
}
class A
{
public:
    int a;
public:
    A(int a):a(a) {}
};

void fill (const int table[], unsigned size, vector<A*> & v)


{
    for(unsigned i = 0; i < size; ++i)
    {
        v.push_back(new A(table[i]));
    }
}

ostream & operator<<(ostream & c, const A & o)


{
    c<<o.a;
    return c;
}

int main()
{
    int tab[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    vector<A*> v1;
    fill(tab, 10, v1);
    
    vector<A*>::iterator it;
    list<A> l1;
    for(it = v1.begin(); it != v1.end(); ++it)
    {
        l1.push_front(**it);
    }
    print(l1.begin(), l1.end())<<endl;
    return 0;        //LINE I
}

  
code will not compile
 

  
program will run successfully and display: 1 2 3 4 5 6 7 8 9 10
 

  
when program reaches LINE I there will be 10 objects of type A
 

  
program will run successfully but the result displayed cannot be predicted
 

  
when program reaches LINE I there will be 20 objects of type A
 
 
PartialQuestion 17
0.5 / 1 pts
Which container class can be used as underlying container for priority_queue? Choose
all that apply.
 

  
deque
 

  
list
 

  
map
 

  
set
 

  
vector
 
 
PartialQuestion 18
0.33 / 1 pts
Which of the following examples show the proper way to create a new priority_queue
container assuming all necessary declarations have been performed? Choose all that
apply.

  
queue<int> q;
 

  
deque<int> d; priority_queue<int> q(d.begin(), d.end());
 

  
vector<int> v; priority_queue<int> q(v);
 

  
deque<int> d; priority_queue<int> q(d);
 

  
list<int> l; priority_queue<int> q(l);
 
 
Question 19
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <queue>
#include <iostream>

using namespace std;

int main()
{
    int t[] = {3, 5, 1, 4, 2};
    vector<int>    v(t, t+5);
    priority_queue<int> q(v.begin(), v.end());
    cout<<q.top()<<" ";
    q.push(0);
    cout<<q.top()<<endl;
    return 0;
}

  
program will display: 5 5
 

  
program will display: 3 0
 

  
program will display: 1 1
 

  
program will display: 2 0
 

  
program will display: 3 3
 
 
PartialQuestion 20
0.67 / 1 pts
Which container class can be used as underlying container for queue? Choose all that
apply.

  
deque
 

  
set
 

  
map
 

  
vector
 
  
list
 
 
PartialQuestion 21
0.5 / 1 pts
Which of the following examples show the proper way to create a new queue container,
assuming all necessary declarations have been performed? Choose all that apply.
 

  
vector<int> v; queue<int> q(v);
 

  
queue<int> q;
 

  
deque<int> d; queue<int> q(d);
 

  
list<int> l; queue<int> q(l);
 

  
deque<int> d; queue<int> q(d.begin(), d.end());
 
 
Question 22
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <queue>
#include <deque>
#include <iostream>

using namespace std;

int main()
{
    int t[] = {1, 5, 3, 4, 2};
    deque<int>    d(t, t+5);
    queue<int> q(d);
    cout<<q.front()<<" "<<q.back()<<" ";
    q.pop();
    cout<<q.front()<<" "<<q.back()<<endl;
    return 0;
}

  
program will display: 2 1 4 1
 

  
program will display: 5 1 4 1
 

  
program will display: 1 5 2 5
 

  
program will display: 1 2 5 4
 

  
program will display: 1 2 5 2
 
 
PartialQuestion 23
0.5 / 1 pts
Which container class can be used as underlying container for the stack? Choose all
that apply.

  
list
 

  
set
 

  
map
 

  
deque
 

  
vector
 
 
Question 24
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <stack>
#include <deque>
#include <iostream>

using namespace std;

int main()
{
    int t[] = {1, 5, 3, 4, 2};
    deque<int>    d(t, t+5);
    stack<int> s(d);
    cout<<s.top()<<" ";
    d.push_front(6);
    cout<<s.top()<<endl;
    return 0;
}

  
program will display: 2 6
 

  
program will display: 2 2
 

  
program will display: 1 6
 

  
program will display: 1 1
 

  
program will cause runtime exception
 
 
Question 25
1 / 1 pts
What will happen when you attempt to compile and run the following code?
#include <vector>
#include <iostream>

using namespace std;

template<typename T> ostream & print(T & start, T & end)


{
    for(; start != end; ++start)
    {
        cout<< *start<< " ";
    }
    return cout;
}

int main()
{
    int tab[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    vector<int> v1(tab, tab+10);
    vector<int> v2;
    vector<int>::iterator it;
    for(it = v1.begin(); it != v1.end(); ++it)
    {
        v2.push_back(v1[v1.end()-it-1]);    //LINE I
    }
    print(v2.rbegin(), v2.rend()) << endl;    //LINE II
    return 0;
}

  
program will run successfully and display: 10 9 8 7 6 5 4 3 2 1
 

  
program will run successfully and display: 1 2 3 4 5 6 7 8 9 10
 

  
code will not compile due to error in line LINE II
 

  
code will not compile due to error in line LINE I
 

  
the result of program execution is unpredictable or there might be run time exception
 
 
Question 26
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>

using namespace std;

template<typename T> ostream & print(T const & start, T const & end)
{
    for (T i = start; i != end; ++i)
    {
        cout << *i << " ";
    }
    return cout;
}

int main()
{
    int tab[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    vector<int> v1(tab, tab+10);
    
    vector<int>::const_iterator it = v1.begin()+3;
    v1.erase(it, it + 1);
    print(v1.begin(), v1.end());
    v1.empty();
    cout<<v1.size()<<endl;
    return 0;
}

  
program will run successfully and display: 1 2 3 5 6 7 8 9 10 9
 

  
program will run successfully and display: 1 2 3 6 7 8 9 10 8
 

  
program will run successfully and display: 1 2 3 6 7 8 9 10 0
 

  
code will not compile
 

  
program will run successfully and display: 1 2 3 5 6 7 8 9 10 0
 
 
Question 27
1 / 1 pts
Which method from the std::vector class can delete an element of the vector using only
its position within the vector (not iterator) as parameter?

  
clear()
 

  
remove()
 

  
delete()
 

  
erase()
 

  
there is no such method
 
 
Question 28
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>

using namespace std;

template<typename T> ostream & print(const T & start, const T & end)
{
    T tmp = start;
    for(; tmp != end; ++tmp)
    {
        cout<< *tmp<< " ";
    }
    return cout;
}

int main()
{
    int tab[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    vector<int> v1(tab, tab+10);
    vector<int> v2;
    v2.reserve(10);
    while(!v1.empty())
    {
        v2.insert(v2.begin(), v1.pop_back());
    }
    print(v2.rbegin(), v2.rend())<<": "<<v2.size()<<endl;
    return 0;
}

  
program will run successfully and display: 10 9 8 7 6 5 4 3 2 1 : 20
 

  
code will not compile
 

  
program will run successfully and display: 1 2 3 4 5 6 7 8 9 10 : 10
 

  
program will run successfully and display: 10 9 8 7 6 5 4 3 2 1 : 10
 

  
program will run successfully and display: 1 2 3 4 5 6 7 8 9 10 : 20
 
 
Question 29
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>

using namespace std;

template<typename T> ostream & print(const T & start, const T & end)
{
    T tmp = start;
    for(; tmp != end; ++tmp)
    {
        cout<< *tmp<< " ";            //LINE II
    }
    return cout;
}
class A
{
public:
    int a;
public:
    A(int a):a(a) {}
};

ostream & operator<<(const A & o, ostream & c)


{
    c<<o.a;
    return c;
}

int main()
{
    int tab[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    vector<A> v1(tab, tab+10);        //LINE I
    v1.insert(v1.end(), A(0));
    print(v1.begin(), v1.end())<<endl;
    return 0;
}

  
code will not compile due to error in line marked LINE I
 

  
program will run successfully and display: 1 2 3 4 5 6 7 8 9 10 0
 

  
program will run successfully and display: 0 1 2 3 4 5 6 7 8 9 10
 

  
code will not compile due to error in line marked LINE II
 

  
program will run successfully and display: 1 2 3 4 5 6 7 8 9 10
 
 
Question 30
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

template<typename T> ostream & print(const T & start, const T & end)
{
    T tmp = start;
    for(; tmp != end; ++tmp)
    {
        cout<< *tmp<< " ";
    }
    return cout;
}
class A
{
public:
    int a;
public:
    A(int a):a(a) {}
};

ostream & operator<<(ostream & c, const A & o)


{
    c<<o.a;
    return c;
}

void fill (const int table[], unsigned size, vector<A*> & v)


{
    for(unsigned i = 0; i < size; ++i)
    {
        v.push_back(new A(table[i]));            //LINE I
    }
}

void del(A * p)
{
    delete p;
}
int main()
{
    int tab[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    vector<A*> v1;
    fill(tab, 10, v1);

    print(v1.rbegin(), v1.rend())<<endl;        //LINE II


    for_each(v1.begin(), v1.end(), del);
    return 0;
}

  
program will run successfully and display: 1 2 3 4 5 6 7 8 9 10
 
  
code will not compile due to error in line marked LINE I
 

  
program will run successfully and display: 10 9 8 7 6 5 4 3 2 1
 

  
none of these
 

  
code will not compile due to error in line marked LINE II
 

Score for this attempt: 9.5 out of 28


Submitted Dec 13 at 9:02pm
This attempt took 12 minutes.
 
IncorrectQuestion 1
0 / 1 pts
What happens when you attempt to compile and run the following code? Choose all that
apply.

#include <iostream>
#include <set>
#include <vector>
#include <functional>
using namespace std;

int main(){
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5 };
    vector<int>    v(mynumbers, mynumbers+7);
    set<int> set1(v.begin(),v.end());
    set<int, greater<int> > set2(v.begin(), v.end()); //LINE I
    for(set<int, int>::iterator i=set2.begin();i!= set2.end(); i++)
        cout<<*i<<" ";
    for(set<int>::iterator i=set1.begin();i!= set1.end(); i++)
        cout<<*i<<", ";
    cout<<endl;
    return 0;
}

  
compilation fails due to error in line I
 

  
program outputs: 0 0 1 2 3 4 5 9, 1, 2, 3, 4, 5, 9,
 

  
program outputs: 9 5 4 3 2 1 0, 1, 2, 3, 4, 5, 9,
 

  
code compiles and executes successfully
 

  
program outputs: 9 5 4 3 2 1 0 0, 1, 2, 3, 4, 5, 9,
 
 
IncorrectQuestion 2
0 / 1 pts
What happens when you attempt to compile and run the following code? Choose all that
apply.

#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main(){
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5 };
    vector<int>    v(mynumbers, mynumbers+7);
    set<int> s1(v.begin(),v.end());
    s1.insert(v.begin(),v.end());
    s1.insert(10);
    s1.erase(s1.lower_bound(4),s1.upper_bound(6));
    s1.insert(v.begin(),v.end());
    for(set<int>::iterator i=s1.begin();i!= s1.end(); i++)
        cout<<*i<<", ";
    return 0;
}

  
the size of the s1 set is 8
 

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
the size of the s1 set is 7
 
  
program outputs: 0, 1, 2, 3, 4, 5, 9, 10,
 

  
program outputs: 0, 1, 2, 3, 4, 5, 10,
 
 
IncorrectQuestion 3
0 / 1 pts
What happens when you attempt to compile and run the following code?

#include <iostream>
#include <set>
#include <vector>
using namespace std;
class A {
    int a;
public:
    A(int a):a(a){}
    int getA() const { return a;}
};

int main(){
    A mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5 };
    vector<A>    v(mynumbers, mynumbers+7);
    set<A> s1(v.begin(),v.end()); //LINE I
    s1.insert(v.begin(),v.end());
    s1.erase(s1.lower_bound(3),s1.upper_bound(6));
    for(set<A>::iterator i=s1.begin();i!= s1.end(); i++) {
        cout<<i->getA()<<" ";
    }
    cout<<endl;
    return 0;
}

  
compilation fails because there is no bool operator < defined in class A
 

  
the exception will be thrown at line LINE I because there is no bool operator < defined in
class A
 

  
code compiles and executes successfully
 
  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5,
 
 
IncorrectQuestion 4
0 / 1 pts
What happens when you attempt to compile and run the following code?

#include <iostream>
#include <set>
#include <list>
using namespace std;
int main(){
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5, 4 };
    list<int> v(mynumbers, mynumbers+7);//LINE I
    set<int> s1(v.begin(),v.end());
    if (s1.count(4) == 2) {
        s1.erase(4);
    }
    for(set<int>::iterator i=s1.begin();i!= s1.end(); i++) {
        cout<<*i<<", ";
    }
    return 0;
}

  
compilation error in LINE I
 

  
program outputs: 0, 1, 2, 3, 5, 9,
 

  
program outputs: 0, 1, 2, 3, 4, 5, 9, 4
 

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
program outputs: 0, 1, 2, 3, 5, 9, 4
 
 
Question 5
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main(){
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v(mynumbers, mynumbers+7);
    set<int> s1(v.begin(),v.end());
    s1.insert(v.begin(),v.end());
    s1.insert(v.begin(),v.end());//LINE I
    set<int>::iterator found = s1.find(9);
    for (; found!=s1.end(); ++found)
        cout << *found << ", ";
    return 0;
}

  
program outputs: 9,
 

  
the exception will be thrown at line LINE I
 

  
code will not compile
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5
 

  
program outputs: 9, 0, 2, 1, 4, 5
 
 
PartialQuestion 6
0.5 / 1 pts
What will happen when you attempt to compile and run the following code? Choose all
that apply.
#include <iostream>
#include <set>
#include <vector>
using namespace std;
template<class T> void print(T start, T end) {
    while (start != end) {
        std::cout << *start << ", "; start++;
    }
}
int main(){
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v(mynumbers, mynumbers+7);
    set<int> s(v.begin(),v.end());
    for(int i=10; i>0; i  ) {
        int x = s.top(); //LINE I
        s.pop();         //LINE II
        v.push_back(i+x);//LINE III
    }
    print(v.begin(), v.end()); print(s.begin(), s.end());cout<<endl;
    return 0;
}

  
The output will be: 0, 1, 2, 3, 4, 5, 9, 0, 1, 2, 3, 4, 5, 9,
 

  
compilation error in LINE III
 

  
The output will be: 0, 1, 2, 3, 4, 5, 9, 9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 9,
 

  
The output will be: 0, 1, 2, 3, 4, 5, 9, 9, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 9,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 
 
Question 7
1 / 1 pts
What will happen when you attempt to compile and run the following code?
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main(){
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v(mynumbers, mynumbers+7);
    set<int> s(v.begin(),v.end());
    s.insert(v.begin(),v.end());
    v.push_back(5);
    s.insert(8);
    pair<set<int>::iterator,set<int>::iterator> range;
    range = s.equal_range(5);//LINE I
    cout<<*range.first<<", "<<*range.second<<endl;
    return 0;
}

  
compilation error in LINE I
 

  
The output will be: 5, 8
 

  
The output will be: 8, 5
 

  
The output will be: 4 5
 

  
The output will be: 2 5
 
 
IncorrectQuestion 8
0 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <set>
#include <vector>
#include <functional>
using namespace std;
int main(){
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v(mynumbers, mynumbers+7);
    multiset<int> s1(v.begin(),v.end());
    multiset<int, greater<int> > s2(v.begin(), v.end());//LINE I
    s2.insert(9);//LINE II
    for(multiset<int>::iterator i=s1.begin();i!= s1.end(); i++)
        cout<<*i<<", ";
    for(multiset<int, greater<int> >::iterator i=s2.begin();i!= s2.end(); i++)
        cout<<*i<<", ";
    cout<<endl;
    return 0;
}

  
compilation error in LINE I
 

  
the exception will be thrown at line LINE II
 

  
The output will be: 0, 1, 2, 3, 4, 5, 9, 9, 9, 5, 4, 3, 2, 1, 0,
 

  
The output will be: 0, 1, 2, 3, 4, 5, 9, 9, 5, 4, 3, 2, 1, 0, 9,
 
 
IncorrectQuestion 9
0 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main(){
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5 };
    set<int>    s1(mynumbers, mynumbers+7);
    multiset<int> s2(s1.begin(),s1.end());
    s2.insert(s1.begin(),s1.end());
    s2.erase(s2.lower_bound(1),s2.upper_bound(4));//LINE I
    for(multiset<int>::iterator i=s2.begin();i!= s2.end(); i++) {
        cout<<*i<<", ";
    }
    return 0;
}
  
The output will be: 0, 1, 2, 3, 4, 5, 9,
 

  
the exception will be thrown at line LINE I
 

  
The output will be: 0, 5, 9,
 

  
The output will be: 0, 1, 4, 5, 9,
 

  
The output will be: 0, 1, 4, 5, 9, 0, 1, 4, 5, 9,
 

  
The output will be: 0, 0, 5, 5, 9, 9,
 
 
IncorrectQuestion 10
0 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <set>
#include <vector>
using namespace std;
class A {
    int a;
public:
    A(int a):a(a){}
    int getA() const { return a;}
    operator int() const { return a;}
    bool operator < (const A & b) const { return b.a<a;} //LINE I
};

int main(){
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5 };
    set<A>    s(mynumbers, mynumbers+7);            //LINE II
    multiset<A> s1(s.begin(),s.end());    //LINE III
    s1.insert(s.begin(),s.end());
    s1.erase(s1.lower_bound(5),s1.upper_bound(2));//LINE IV
    multiset<A>::iterator i=s1.begin();    
    for( ;i!= s1.end(); i++)
    {
        cout<<i->getA()<<", ";
    }
    cout<<endl;
    return 0;
}

  
The output will be: 0, 1, 9
 

  
compilation error in LINE I
 

  
the exception will be thrown at line LINE I
 

  
the exception will be thrown at line LINE IV
 

  
The output will be: 9, 9, 1, 1, 0, 0,
 
 
IncorrectQuestion 11
0 / 1 pts
What happens when you attempt to compile and run the following code?

#include <iostream>
#include <set>
#include <list>
using namespace std;
int main(){
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5, 5 };
    list<int> v(mynumbers, mynumbers+7);//LINE I
    multiset<int> s1(v.begin(),v.end());
    if (s1.count(5) == 1)//LINE II
        s1.erase(5);
    for(multiset<int>::iterator i=s1.begin();i!= s1.end(); i++)
        cout<<*i<<", ";
    return 0;
}

  
program outputs: 0, 1, 2, 3, 4, 9,
 

  
program outputs: 0, 1, 2, 3, 4, 5, 5, 9,
 

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
the exception will be thrown at line LINE I
 

  
compilation error in LINE II
 
 
Question 12
1 / 1 pts
What happens when you attempt to compile and run the following code?

#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main(){
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5, 7 };
    multiset<int> s1(mynumbers, mynumbers+7);//LINE I
    s1.insert(s1.find(3), 6);                 //LINE II
    for(multiset<int>::iterator i=s1.begin();i!= s1.end(); i++)
        cout<<*i<<", ";
    return 0;
}

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
program outputs: 0, 1, 2, 3, 4, 5, 6, 7, 9,
 

  
the exception will be thrown at line LINE I
 

  
program outputs: 0, 1, 2, 3, 6, 4, 5, 9,
 

  
program outputs: 0, 1, 2, 3, 4, 5, 6, 9,
 

  
compilation error in LINE II
 
 
IncorrectQuestion 13
0 / 1 pts
What happens when you attempt to compile and run the following code?

#include <iostream>
#include <set>
#include <vector>
using namespace std;
template<class T> void print(T start, T end) {
    while (start != end) {
        std::cout << *start << ", "; start++;
    }
}
int main(){
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5, 7};
    vector<int> v(mynumbers, mynumbers+7);
    multiset<int> s1(mynumbers, mynumbers+7);
    for(int i=9; i>0; i  ) {
        double x=s1.pop();//LINE I
        v.push_back(i+x);  //LINE II
    }
    print(v.begin(), v.end()); cout<<endl;
    return 0;
}

  
compilation error in LINE I
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5, 7, 12, 16, 5, 6, 4, 6, 6, 7,
 

  
the exception will be thrown at line LINE I, because of too many calls to pop method
 

  
the exception will be thrown at line LINE II
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5, 12, 14, 4, 5, 3, 5, 5,
 

  
compilation error in LINE II
 
 
Question 14
1 / 1 pts
What happens when you attempt to compile and run the following code?

#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main(){
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5, 7};
    vector<int> v(mynumbers, mynumbers+7);
    multiset<int> s1(v.begin(),v.end());
    s1.insert(v.begin(),v.end());
    s1.insert(v.begin(),v.end());//LINE I
    pair<multiset<int>::iterator,multiset<int>::iterator> range;
    range = s1.equal_range(5);
    while (range.first != range.second) {
        cout<<*range.first<<", ";
        range.first++;
    }
    return 0;
}

  
program outputs: 5, 5, 9, 9,
 

  
program outputs: 5, 5,
 

  
compilation error in LINE I
 

  
program outputs: 5,
 
  
program outputs: 5, 7, 9,
 

  
program outputs: 5, 5, 5,
 
 
Question 15
1 / 1 pts
What happens when you attempt to compile and run the following code?

#include <iostream>
#include <map>
#include <vector>
#include <sstream>
#include <string>
using namespace std;
int main(){
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5, 8};
    vector<int> v(mynumbers, mynumbers+7);
    map<int,string> m;
    for(map<int, string>::iterator i=m.begin();i!= m.end(); i++)
        cout<<*i<<", ";//LINE I
    return 0;
}

  
program outputs: 3, 9, 0, 2, 1, 4, 5, 8,
 

  
empty output
 

  
compilation error in LINE I
 

  
the exception will be thrown at line LINE I
 

  
program outputs: 0 , 1 , 2 , 3 , 4 , 5 , 9 ,
 

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
program outputs: 0, 1, 2, 3, 4, 5, 8, 9,
 
 
IncorrectQuestion 16
0 / 1 pts
What happens when you attempt to compile and run the following code?

#include <iostream>
#include <map>
#include <vector>
#include <string>
using namespace std;
int main(){
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5 };
    string words[] = {"three", "nine", "zero", "two", "one", "four", "five"};
    map<int,string> m;
    for(int i=0; i<9; i++)
        m.insert(pair<int,string>(mynumbers[i], words[i]));//LINE I
    m[0]="ten";                                               //LINE II
    m.insert(pair<int,string>(1,"eleven"));                //LINE III
    for(map<int, string>::iterator i=m.begin();i!= m.end(); i++)
        cout<<i->second<<", ";
    return 0;
}

  
program outputs: zero, one, two, three, four, five, nine,
 

  
compilation error in LINE II
 

  
the exception will be thrown at line LINE III
 

  
program outputs: zero, one, two, three, four, five, nine, ten, eleven
 

  
program outputs: three, nine, zero, two, one, four, five,
 
  
program outputs: three, nine, zero, two, one, four,
 

  
the exception will be thrown at line LINE I
 

  
program outputs: ten, one, two, three, four, five, nine, eleven
 
 
IncorrectQuestion 17
0 / 1 pts
What happens when you attempt to compile and run the following code?

#include <iostream>
#include <map>
#include <string>
using namespace std;
int main(){
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5 };
    string words[] = {"three", "nine", "zero", "two", "one", "four", "five"};
    map<int,string> m;
    for(int i=0; i<7; i++)
        m.insert(pair<int,string>(mynumbers[i], words[i]));//LINE I
    if (m[10] == "ten")//LINE II
        cout<<"tenth element";
    for(map<int, string>::iterator i=m.begin();i!= m.end(); i++)
        cout<<i->second<<", ";
    cout<<m.size();//LINE III
    return 0;
}

  
the exception will be thrown at line LINE II
 

  
program outputs: zero, one, two, three, four, five, nine, , 8
 

  
program outputs: zero, one, two, three, four, five, nine, , 7
 

  
compilation error in LINE III
 

  
compilation error in LINE I
 

  
program outputs: one, two, three, four, five, nine, , 7
 
 
IncorrectQuestion 18
0 / 1 pts
What changes, introduced independently, will allow the code to compile and display
"zero, one, two, five, nine, "? Choose all that apply.

#include <iostream>
#include <map>
#include <string>
using namespace std;
class A {
    int a;
public:
    A(int a):a(a){}
    int getA() const { return a;}
    bool operator < (const A & b) const { return a<b.a;}//LINE I
};

int main(){
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5 };
    string words[] = {"three", "nine", "zero", "two", "one", "four", "five"};
    map<A, string> m;        
    for(int i=0; i<7; i++) {
        m.insert(pair<A,string>(A(mynumbers[i]), words[i]));
    }
    m.erase(m.lower_bound(3), m.upper_bound(4));//LINE II
    map<A, string>::iterator i=m.begin();  
    for( ;i!= m.end(); i++)
            cout<<i->second<<", ";
    return 0;
}

  
change the code at LINE I to bool operator < (const A & b) const { return b.a<a;}
 

  
change LINE II to m.erase(m.lower_bound(3), m.upper_bound(5));
 

  
change LINE II to m.erase(m.lower_bound(3), m.upper_bound(4));
 

  
code compiles and executes successfully but the results are other than expected
 

  
code compiles and executes successfully with the expected result
 
 
Question 19
1 / 1 pts
What happens when you attempt to compile and run the following code?

#include <iostream>
#include <map>
using namespace std;
int main() {
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5, 5 };
    string words[] = {"three", "nine", "zero", "two", "one", "four", "five", "five"};
    map<int, string> m;
    for (int i = 0; i < 8; i++) {
        m.insert(pair<int, string>(mynumbers[i], words[i]));
    }
    if (m.count(5) == 2)
        m.erase(2);
    for (map<int, string>::iterator i = m.begin(); i != m.end(); i++) {
        cout << i->first << ", ";
    }
    return 0;
}

  
program outputs: 0, 1, 3, 4, 5, 9,
 

  
program outputs: zero, one, two, three, four, five, nine
 

  
program outputs: 0, 1, 3, 4, 5, 5, 9,
 

  
program outputs: zero, one, three, four, five, nine
 
  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
program outputs: 0, 1, 2, 3, 4, 5, 5, 9,
 
 
IncorrectQuestion 20
0 / 1 pts
What happens when you attempt to compile and run the following code?

#include <iostream>
#include <map>
using namespace std;
int main() {
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5 };
    string words[] = {"three", "nine", "zero", "two", "one", "four", "five"};

    map<int, string> m;
    for (int i = 0; i < 10; i++)
        m.push_back(pair<int, string>(mynumbers[i], words[i]));//LINE I

    for (map<int, string>::iterator i = m.begin(); i != m.end(); i++)//LINE II


        cout << i->first << ", ";
    return 0;
}

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5,
 

  
the exception will be thrown at line LINE I
 

  
compilation error in LINE II because of redeclaration of the i variable
 

  
compilation error in LINE I
 
 
IncorrectQuestion 21
0 / 1 pts
What happens when you attempt to compile and run the following code?

#include <iostream>
#include <map>
#include <vector>
#include <sstream>
#include <string>
using namespace std;
int main() {
    int mynumbers[] =    { 3, 9, 3, 2, 1, 4, 5 };
    vector<int> v(mynumbers, mynumbers+7);
    map<int, string> m;
    for (vector<int>::iterator i = v.begin(); i != v.end(); i++) {
        stringstream s;    
        s << *i;
        m.insert(pair<int, string>(*i, s.str()));
    }
    pair<map<int, string>::iterator, map<int, string>::iterator> range;
    range = m.equal_range(3);
    map<int, string>::iterator i = range.first;//LINE 1
    for (; i != range.second; i++) {
        cout << i->first << ", ";
    }
    return 0;
}

  
program outputs: 3, 3, 4, 5, 9,
 

  
program outputs: 4, 5, 9,
 

  
compilation error in LINE I
 

  
program outputs: 3, 4, 5, 9,
 

  
program outputs: 3,
 

  
program outputs: 3, 3,
 
 
IncorrectQuestion 22
0 / 1 pts
What happens when you attempt to compile and run the following code?

#include <iostream>
#include <map>
#include <vector>
#include <sstream>
#include <string>
using namespace std;
int main(){
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v(mynumbers, mynumbers+7);
    multimap<int,string> m;
    for(vector<int>::iterator i=v.begin(); i!=v.end(); i++) {
        stringstream s;
        s<<*i<<*i;
        m.insert(pair<int,string>(*i,s.str()));
    }
    for(multimap<int, string>::iterator i=m.begin();i!= m.end(); i++) {
        cout<<i->first<<", ";//LINE I
    }
    return 0;
}

  
program outputs: 11, 22, 33, 44, 55, 99,
 

  
compilation error in LINE I
 

  
program outputs: 00, 11, 22, 33, 44, 55,
 

  
program outputs: 00, 11, 22, 33, 44, 55, 99,
 

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 
 
IncorrectQuestion 23
0 / 1 pts
What will be the output of the program when you attempt to compile and run the
following code?

#include <iostream>
#include <map>
#include <vector>
#include <string>
using namespace std;
int main(){

    int mynumbers[] =    { 3, 9, 0, 2, 1 };


    string words[] = {"three", "nine", "zero", "two", "one"};
    multimap<int,string> m;
    for(int i=0; i<4; i++) {
        m.insert(pair<int,string>(mynumbers[i], words[i]));
        m.insert(pair<int,string>(mynumbers[i], words[i]));
    }
    m[0]="ten";        //LINE I
    for(multimap<int, string>::iterator i=m.begin();i!= m.end(); i++)
        cout<<i->second<<", ";
    return 0;
}

  
ten, ten, two, two, three, three, nine, nine
 

  
zero, zero, two, two, three, three, nine, nine,
 

  
zero, zero, two, two, three, three, nine, nine, ten, ten
 

  
compilation error in LINE I
 

  
ten, zero, two, two, three, three, nine, nine,
 
 
Question 24
1 / 1 pts
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main(){
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5 };
    string words[] = {"three", "nine", "zero", "two", "one", "four", "five"};
    multimap<int,string> m;
    for(int i=0; i<7; i++)
        m.insert(pair<int,string>(mynumbers[i],words[i]));
    if (m.find(0)->second == "zero")//LINE I
        cout<<"found expected ";
    for(multimap<int, string>::iterator i=m.begin();i!= m.end(); i++)
        cout<<i->second<<", ";
    cout<<m.size();
    return 0;
}

  
the exception will be thrown at line LINE I
 

  
program outputs: found expected zero, one, two, three, four, five, nine, 7
 

  
program outputs: zero, one, two, three, four, five, nine, 8
 

  
program outputs: found expected zero, one, two, three, four, five, nine, 8
 

  
compilation error in LINE I
 
 
IncorrectQuestion 25
0 / 1 pts
What changes introduced independently will allow the code to compile and display
“zero, one, nine,”?

#include <iostream>
#include <map>
#include <string>
using namespace std;
class A {
    int a;
public:
    A(int a):a(a){}
    int getA() const { return a;}
    //LINE I
};
int main(){
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5 };
    string words[] = {"three", "nine", "zero", "two", "one", "four", "five"};
    multimap<A,string> m;
    for(int i=0; i<7; i++)
        m.insert(pair<A,string>(A(mynumbers[i]),words[i]));
    m.erase(m.lower_bound(2),m.upper_bound(5));
    m.erase(m.lower_bound(2),m.upper_bound(5));
    multimap<A, string>::iterator i=m.begin();//LINE II
    for( ; i!= m.end(); i++)
            cout<<i->second<<", ";
    cout<<endl;
    return 0;
}

  
multimap<A, string>::iterator i=m.end(); inserted at LINE II
 

  
code compiles and executes successfully
 

  
bool operator < (const A & b) const { return a<b.a;} inserted at LINE I
 

  
bool operator < (const A & b) const { return b.a<a;} inserted at LINE I
 
 
Question 26
1 / 1 pts
What happens when you attempt to compile and run the following code?

#include <iostream>
#include <map>
using namespace std;
int main() {
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5, 5 };
    string words[] = {"three", "nine", "zero", "two", "one", "four", "five",
"fiveandhalf"};
    multimap<int, string> m;
    for (int i = 0; i < 8; i++)
        m.insert(pair<int, string>(mynumbers[i], words[i]));
    if (m.count(5) == 1)
        m.erase(2);
    for (multimap<int, string>::iterator i = m.begin(); i != m.end(); i++)
        cout << i->first << ", ";
    return 0;
}

  
program outputs: 0, 1, 3, 4, 5, 5, 9,
 

  
program outputs: 0, 1, 3, 4, 5, 9,
 

  
program outputs: 0, 1, 2, 3, 4, 5, 5, 9,
 

  
program outputs: 0, 1, 2, 3, 4, 5,
 
 
Question 27
1 / 1 pts
What happens when you attempt to compile and run the following code?

#include <iostream>
#include <map>
using namespace std;
int main() {
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5 };
    string words[] = {"three", "nine", "zero", "two", "one", "four", "five"};
    multimap<int, string> m;
    for (int i = 0; i < 3; i++)
        m.push_back(pair<int, string>(mynumbers[i], words[i])); //LINE I

    for (multimap<int, string>::iterator i = m.begin(); i != m.end(); i++)


        cout << i->first << " "; //LINE II
    return 0;
}

  
the exception will be thrown at line LINE I
 
  
program outputs: 0, 1, 2,
 

  
the exception will be thrown at line LINE II
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
program outputs: 0, 1, 2, 3,
 
 
IncorrectQuestion 28
0 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <map>
#include <vector>
#include <sstream>
#include <string>
using namespace std;
int main() {
    int mynumbers[] =    { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v(mynumbers, mynumbers+7);
    multimap<int, string> m;
    for (vector<int>::iterator i = v.begin(); i != v.end(); i++) {
        stringstream s;    
        s << *i << *i << *i;
        m.insert(pair<int, string>(*i, s.str()));//LINE I
    }
    pair<multimap<int, string>::iterator, multimap<int, string>::iterator>
range;//LINE II
    range = m.equal_range(4);
    for (multimap<int, string>::iterator i = range.first; i != range.second; i++) {
        cout << i->first << ", ";
    }
    return 0;
}

  
the exception will be thrown at line LINE I
 

  
4,
 

  
5, 9
 

  
the exception will be thrown at line LINE II
 

  
4, 5, 9
 

Score for this attempt: 26 out of 28


Submitted Dec 31 at 3:08pm
This attempt took 9 minutes.
 
Question 1
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
using namespace std;

void myprint(int i) {
    cout << i << ", ";// Line I
}

int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    set<int> s1(mynumbers, mynumbers + 7);
    deque<int> d1(mynumbers, mynumbers + 7);
    d1.pop_front();// Line II
    for_each(v1.begin(), v1.end(), myprint); // Line III
    for_each(s1.begin(), s1.end(), myprint);
    for_each(d1.begin(), d1.end(), myprint);
    return 0;
}
  
program outputs: 3, 9, 0, 2, 1, 4, 5, 0, 1, 2, 3, 4, 5, 9, 3, 9, 0, 2, 1, 4, 5,
 

  
the exception will be thrown at LINE III
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5, 0, 1, 2, 3, 4, 5, 9, 9, 0, 2, 1, 4, 5,
 

  
compilation error in LINE I
 

  
the exception will be thrown at LINE II
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5, 0, 1, 2, 3, 4, 5, 9, 3, 9, 0, 2, 1, 4,
 

  
compilation error in LINE II
 
 
Question 2
1 / 1 pts
What will happen when you attempt to compile and run the following code? Choose all
that apply.

#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
using namespace std;

struct myprinter {
  void operator() (int i) {cout << i << ", ";}
};

int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    deque<int> d1(mynumbers, mynumbers + 7);
    set<int> s1(mynumbers, mynumbers + 7);
    v1.pop_back(5);// Line I
    for_each(s1.begin(), s1.end(), myprinter());  // Line II
    for_each(d1.begin(), d1.end(), *(new myprinter()));  // Line III
    for_each(v1.begin(), v1.end(), myprinter);  //Line IV
    return 0;
}

  
program outputs: 3, 9, 0, 2, 1, 4, 5, 0, 1, 2, 3, 4, 5, 9, 9, 0, 2, 1, 4, 5, 3, 9, 0, 2, 1, 4, 5,
 

  
compilation error in LINE I
 

  
compilation error in LINE IV
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5, 0, 1, 2, 3, 4, 5, 9, 9, 0, 2, 1, 4, 5, 3, 9, 0, 2, 1, 4,
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5, 0, 1, 2, 3, 4, 5, 9, 9, 0, 2, 1, 4, 5, 3, 9, 0, 2, 1, 4, 5, 5
 

  
compilation error in LINE II
 

  
compilation error in LINE III
 
 
Question 3
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
using namespace std;
class A {
    int a;
public:
    A(int a):a(a) {}
    int getA() const { return a;} void setA(int a){ this->a = a;}
    bool operator < ( const A & b) const { return a<b.a;}
};
struct myprinter { void operator() (const A & a) {cout << a.getA() << ", ";} };
struct doubler
{
    void operator() (A a) { a.setA(a.getA()*2) ;}//LINE I
};

int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<A> v1(mynumbers, mynumbers + 7);
    set<A> s1(mynumbers, mynumbers + 7);
    for_each(v1.begin(), v1.end(), doubler()); for_each(v1.begin(), v1.end(),
myprinter());//LINE II
    for_each(s1.begin(), s1.end(), doubler()); for_each(s1.begin(), s1.end(),
myprinter());//LINE III
    return 0;
}

  
compilation error in LINE II
 

  
compilation error in LINE III
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5, 0, 1, 2, 3, 4, 5, 9,
 

  
compilation error in LINE I
 

  
program outputs: 6, 18, 0, 4, 2, 8, 10, 6, 18, 0, 4, 2, 8, 10,
 

  
the exception will be thrown at LINE I
 

  
program outputs: 6, 18, 0, 4, 2, 8, 10, 0, 2, 4, 6, 8, 10, 18,
 
 
Question 4
1 / 1 pts
What will happen when you attempt to compile and run the following code? Choose all
that apply.

#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
using namespace std;

int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    deque<int> d1(mynumbers, mynumbers + 7);
    set<int> s1(mynumbers, mynumbers + 7);
    vector<int>::iterator found = find(v1.begin(), v1.end(), 3);//LINE I
    if(found!=v1.end())//LINE II
        cout << "found" <<", ";
    cout<<find(d1.begin(), d1.end(), 9)<<", ";//LINE III
    cout<<find(s1.begin(), s1.end(), 6);//LINE IV
    return 0;
}

  
program outputs: found, 9, 6
 

  
program outputs: found, 9,
 

  
compilation error in LINE I
 

  
compilation error in LINE III
 

  
the exception will be thrown at LINE I
 

  
program outputs: 3, 9, 6
 
  
compilation error in LINE II
 

  
compilation error in LINE IV
 
 
Question 5
1 / 1 pts
Which sentences are true about the code below?

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
class A {
    int a;
public:
    A(int a) :    a(a) {}
    int getA() const { return a; }
    void setA(int a) { this->a = a; }
    bool operator ==(const A & b) const {return (this->a != b.a); }//LINE I
};

struct doubler { void operator()(A & a) { a.setA(a.getA() * 2); } };//LINE II

int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<A> v1(mynumbers, mynumbers + 7);
    for_each(v1.begin(), v1.end(), doubler());
    vector<A>::iterator it = find(v1.begin(), v1.end(), A(7));
    cout << it->getA() << endl;//LINE III
    return 0;
}

  
it will compile and print 14
 

  
it will compile and print 7
 

  
it will compile and print 6
 
  
compilation error in LINE I
 

  
it will compile and print 3
 

  
compilation error in LINE III
 

  
compilation error in LINE II
 
 
Question 6
1 / 1 pts
Which sentences are true about the code below? Choose all that apply.

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
class Founder {
public:
    int val;
    Founder(int  v):val(v){}
    bool operator() (int v) {return (v == val);}//LINE I
};

int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    if (find(v1.begin(), v1.end(), 7) == find(v1.begin(), v1.end(), Founder(7).val))
{//LINE II
        cout<<"Found!\n";
    } else {
        cout<<"Not found!\n";
    }
    return 0;
}

  
it will display: Found!
 

  
compilation error in LINE I
 

  
it will compile successfully
 

  
compilation error in LINE II
 

  
it will display: Not found!
 
 
Question 7
1 / 1 pts
What will happen when you attempt to compile and run the following code? Choose all
that apply.

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
class A {
    int a;
public:
    A(int a) :    a(a) {}
    int getA() const { return a; }    void setA(int a) { this->a = a; }
    bool operator < (const A & b) const  { return a<b.a;}
};
class Founder {
    A val;
public:
    Founder(A & v):val(v){}
    bool operator() (A & v) {return (v.getA() == val.getA());}
};
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<A> v1(mynumbers, mynumbers + 7);//LINE I
    set<A> s1(mynumbers, mynumbers + 7);
    A a(5);    
    Founder f(a);
    find_if(s1.begin(), s1.end(), f.val);//LINE II
    if (find_if(v1.begin(), v1.end(), f) !=v1.end()) {//LINE III
        cout<<"Found!\n";
    } else {
        cout<<"Not found!\n";
    }
    return 0;
}

  
compilation error in LINE I
 

  
it will display: Not found!
 

  
it will display: Found!
 

  
compilation error in LINE III
 

  
it will not compile successfully
 

  
it will compile successfully
 

  
compilation error in LINE II
 
 
Question 8
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main () {
  int mynumbers [] = { 3, 9, 0, 2, 1, 4, 5 };
  vector<int> v (mynumbers, mynumbers + 7);
  vector<int>::iterator it;
  int m1[] = {9, 0, 2 };
  it = find_end (v.begin(), v.end(), m1, m1+3);//LINE I
  if (it != v.end())
    cout << "Found at position: " << it-v.begin() << endl;
  return 0;
}

  
compilation error in LINE I
 

  
no output
 

  
program outputs: Found at position: 9
 

  
program outputs: Found at position: 1
 

  
program outputs: Found at position: 2
 

  
program outputs: Found at position:
 
 
Question 9
1 / 1 pts
What will happen when you attempt to compile and run the following code? Choose all
that apply.

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
class A {
    int a;
    int getA() const { return a; }    void setA(int a) { this->a = a; }
public:
    A(int a) :    a(a) {}
    bool operator==(A & b) { return a == b.a; }
};
struct Comparer{
    bool operator()(const A & a, const A & b) {return a.getA()==b.getA();};//LINE I
};
int main () {
  int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
  vector<A> v (mynumbers, mynumbers + 7);
  vector<A>::iterator it;
  A m1[] = {A(2), A(3), A(4)};
  it = find_end (v.begin(), v.end(), m1, m1+3, Comparer());//LINE II
  cout << "Found at position: " << it+v.begin() << endl;//LINE III
  return 0;
}

  
compilation error in LINE II
 

  
program outputs: Found at position: 0
 

  
program outputs: Found at position: 7
 

  
program outputs: Found at position: 2
 

  
compilation error in LINE I
 

  
program outputs: Found at position: 1
 

  
compilation error in LINE III
 
 
Question 10
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main () {
  int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
  vector<int> v (mynumbers, mynumbers + 7);
  vector<int>::iterator it;
  int m1[] = {9, 0, 2};
  it = find_first_of (v.begin(), v.end(), m1, m1+3);//LINE I
  cout << "First found at position: " << it-v.begin() << endl;//LINE II
  return 0;
}

  
program outputs: First found at position: 2
 

  
program outputs: First found at position: 9
 

  
program outputs: First found at position: 1
 

  
compilation error in line I
 

  
the exception will be thrown at line LINE II
 

  
compilation error in line II
 

  
program outputs: First found at position: 0
 
 
Question 11
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool compare(int a, int b) { return a == b; }
int main () {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v (mynumbers, mynumbers + 7);
    vector<int>::iterator it = v.begin();
    int m1[] = {9, 0, 2};

    while ( (it = find_first_of (it, v.end(), m1, m1+3)) != v.end()) {//LINE I


        cout<<it-v.begin()<<", ";//LINE II
        it++;
    }
    cout<< endl;
    return 0;
}

  
the exception will be thrown at LINE I
 

  
compilation error in LINE I
 

  
program outputs: 1, 2, 3,
 

  
compilation error in LINE II
 

  
program outputs: 9, 0, 2,
 

  
program will run forever
 
 
Question 12
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main () {
  int mynumbers[] =  { 3, 9, 0, 2, 2, 2, 5 };
  vector<int> v (mynumbers, mynumbers + 7);
  vector<int>::iterator it = v.begin();

  while ( (it = adjacent_find (it, v.end())) != v.end()) {//LINE I


      cout<<it-v.begin()<<", ";it--;//LINE II
  }
  cout<< endl;
  return 0;
}

  
compilation error in LINE I
 

  
program outputs: 3, 4,
 

  
the exception will be thrown at LINE I
 

  
program outputs: 2, 3,
 

  
program will run forever
 

  
compilation error in LINE II
 

  
program outputs: 5, 6,
 

  
program outputs: 2, 2, 2,
 
 
Question 13
1 / 1 pts
What will happen when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
class A {
    int a;
public:
    A(int a) :    a(a) {}
    int getA() const { return a; }    void setA(int a) { this->a = a; }
    bool operator==(const A & b) const { return a == b.a; }
};
bool compare(const A & a, const A & b) { return a == b; }
int main () {
    int mynumbers[] =  { 3, 9, 0, 2, 2, 2, 5 };
    vector<A> v (mynumbers, mynumbers + 7);
    vector<A>::iterator it = v.begin();

    while ( (it = adjacent_find (it, v.end(), compare)) != v.end()) {//LINE I


        cout<<it-v.begin()<<", ";it++;//LINE II
    }
    cout<< endl;
    return 0;
}

  
program outputs: 2, 2, 2,
 

  
program will run forever
 

  
program outputs: 2, 3,
 

  
the exception will be thrown at LINE II
 

  
compilation error in LINE I
 

  
program outputs: 3, 4,
 

  
program outputs: 4, 5,
 

  
compilation error in LINE II
 
 
Question 14
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main () {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5, 6, 6, 9, 8, 2 };
    vector<int> v (mynumbers, mynumbers +12);

    int found = count(v.begin(), v.end(), 6);//LINE I


    cout<< found << endl;
    return 0;
}

  
the exception will be thrown at LINE I
 

  
Program outputs: 1
 

  
Program outputs: 4
 

  
Program outputs: 3
 

  
Program executes and outputs nothing
 

  
compilation error in LINE I
 

  
Program outputs: 2
 
 
Question 15
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <deque>
using namespace std;
class A {
    int a;
public:
    A(int a) :    a(a) {}
    int getA() const { return a; }    void setA(int a) { this->a = a; }
};
int main () {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5, 6, 6, 9, 8, 2 };
    deque<int> d (mynumbers, mynumbers +12);
    int count = count(d.begin(), d.end(), 6);//LINE I
    cout<< count << endl;
    return 0;
}

  
compilation error in LINE I
 

  
Program outputs: 4
 

  
Program outputs: 2
 

  
Program outputs: 1
 

  
the exception will be thrown at LINE I
 

  
Program executes and outputs nothing
 
  
Program outputs: 3
 
 
IncorrectQuestion 16
0 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct Compare {
    bool operator ()(int a) {return (a > 0);}//LINE I
};
int main () {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5, 6, 6, 9, 8, 2 };
    vector<int> v (mynumbers, mynumbers +12);

    int count = std::count(v.begin(), v.end(), Compare());//LINE II


    cout<< count <<endl;
    return 0;
}

  
Program outputs: 1
 

  
compilation error in LINE II
 

  
Program executes and outputs nothing
 

  
Program outputs: 3
 

  
Program outputs: 2
 

  
the exception will be thrown at LINE I
 
  
compilation error in LINE I
 

  
Program outputs: 4
 
 
Question 17
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
class A {
    int a;
public:
    A(int a) :    a(a) {}
    int getA() const { return a; }    void setA(int a) { this->a = a; }
    bool operator < (const A & b) const  { return a<b.a;}//LINE I
};
struct Compare {
    bool operator ()(A a) {    return (a.getA() < 6); }
};
int main () {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5, 6, 6, 9, 8, 2 };
    set<A> d (mynumbers, mynumbers +12);
    int count = count_if(d.begin(), d.end(), Compare());//LINE II
    cout<< count <<endl;
    return 0;
}

  
compilation error in LINE I
 

  
program outputs: 6
 

  
compilation error in LINE II
 

  
program outputs: 2
 
  
the exception will be thrown at LINE I
 

  
program outputs: 4
 

  
program outputs: 1
 
 
Question 18
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
struct Pair {
    bool operator ()(int a) {
        return (a % 2)!=0;    //LINE I
    }
};
int main () {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5, 6, 6, 9, 8, 2 };
    set<int> s(mynumbers, mynumbers +12);

    int count = count_if(s.begin(), s.end(), Pair());//LINE II


    cout<< count <<endl;
    return 0;
}

  
compilation error in LINE II
 

  
the exception will be thrown at line LINE II
 

  
compilation error in LINE I
 

  
program outputs: 3
 

  
program outputs: 2
 

  
program outputs: 4
 

  
program outputs: 1
 
 
Question 19
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5, 6, 6, 9, 8, 2 };
    vector<int> v1(mynumbers, mynumbers + 12);
    set<int> s1(mynumbers, mynumbers + 12);
    v1.push_back(10);//LINE I
    pair<set<int>::iterator, vector<int>::iterator> resultSet = mismatch(s1.begin(),
s1.end(), v1.begin());//LINE II
    cout<<*resultSet.first<<", "<<*resultSet.second<<endl;//LINE III

    return 0;
}

  
compilation error in LINE I
 

  
program outputs: 10, 10
 

  
program outputs: 0, 0
 

  
the exception will be thrown at LINE II
 

  
compilation error in LINE II
 

  
program outputs: 0, 3
 

  
program outputs: 0, 10
 

  
compilation error in LINE III
 
 
Question 20
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
using namespace std;
bool identical(int a, int b) {
    return b == a;//LINE I
}
int main() {
    int mynumbers[]    = { 3, 9, 0, 2, 1, 4, 5, 6, 6, 9, 8, 2 };
    int othernumbers[] = { 3, 9, 0, 3, 1, 4, 3, 6, 6, 9, 8, 3 };
    vector<int> v1(mynumbers, mynumbers + 12);
    deque<int> d1(othernumbers, othernumbers + 12);

    pair<deque<int>::iterator, vector<int>::iterator > result;//LINE II


    result = mismatch(d1.begin(), d1.end(), v1.begin(), identical);     //LINE III
    if (result.first == d1.end() && result.second == v1.end())
        cout<<"Identical\n";
    else
        cout<<"Not identical\n";
    return 0;
}

  
the exception will be thrown at LINE III
 
  
program outputs: Identical
 

  
compilation error in LINE II
 

  
compilation error in LINE III
 

  
compilation error in LINE I
 

  
program outputs: Not identical
 
 
Question 21
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5, 6, 6, 9, 8, 2 };
    vector<int> v1(mynumbers, mynumbers + 12);
    set<int> s1(mynumbers, mynumbers + 12);
    v1.push_back(10);
    pair<set<int>::iterator, vector<int>::iterator > resultSet =
std::equal(s1.begin(), s1.end(), v1.begin());//LINE I
    cout<<*resultSet.first<<", "<<*resultSet.second<<endl;//LINE II

    return 0;
}

  
compilation error in LINE I
 

  
program outputs: 4
 

  
program outputs: 1
 

  
the exception will be thrown at LINE I
 

  
program outputs: 6
 

  
program outputs: 2
 

  
compilation error in LINE II
 
 
Question 22
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
class A {
    int a;
public:
    A(int a) :    a(a) {}
    operator int() const {return a;}//LINE I
};

int main () {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5, 6, 6, 9, 8, 2 };
    set<A> s (mynumbers, mynumbers + 12);
    cout << equal(s.begin(), s.end(), s.begin()) << endl;//LINE II

    return 0;
}

  
program outputs: false
 
  
program outputs: 0
 

  
compilation error in LINE II
 

  
program outputs: 1
 

  
compilation error in LINE I
 

  
the exception will be thrown at LINE I
 

  
program outputs: true
 
 
Question 23
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main () {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v (mynumbers, mynumbers + 7);
    vector<int>::iterator it;
    int m1[] = {9, 0, 2};
    it = search (v.begin(), v.end(), m1, m1+3);//LINE I
    cout << "found at position: " << it-v.begin() << endl;//LINE II
    return 0;
}

  
the exception will be thrown at LINE I
 

  
program outputs: found at position: 2
 

  
program outputs: found at position: 1
 

  
program outputs: found at position: 0
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 
 
Question 24
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
class A {
    int a;
public:
    A(int a) :    a(a) {}
    int getA() const { return a; }    void setA(int a) { this->a = a; }
    bool operator==(A & b) { return a == b.a; }
};
struct Compare{
    bool operator()(const A & a, const A & b) {return a.getA()==b.getA();};
};
int main () {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<A> v (mynumbers, mynumbers + 7);
    vector<A>::iterator it;
    A m1[] = {A(2), A(3), A(4)};
    it = search (v.begin(), v.end(), m1, m1+3, Compare());//LINE I
    cout << "First found at position: " << it-v.begin() << endl;//LINE II
    return 0;
}

  
compilation error in LINE II
 

  
the exception will be thrown at LINE I
 

  
program outputs: First found at position: 6
 

  
program outputs: First found at position: 7
 

  
program outputs: First found at position: 8
 

  
compilation error in LINE I
 

  
program outputs: First found at position: 5
 
 
Question 25
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main () {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5, 6, 6, 9, 8, 2 };
    vector<int> v (mynumbers, mynumbers + 12);

    vector<int>::iterator it = search_n(v.begin(), v.end(), 2, 1);//LINE I


    cout<< it-v.begin()<<endl;//LINE II
    return 0;
}

  
the exception will be thrown at LINE I
 

  
program outputs: 3
 

  
program outputs: 4
 

  
program outputs: 5
 

  
compilation error in LINE II
 

  
compilation error in LINE I
 

  
program outputs: 12
 
 
Question 26
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <deque>
using namespace std;
class A {
    int a;
public:
    A(int a) :    a(a) {}
    int getA() const { return a; }    void setA(int a) { this->a = a; }
};
struct Equals {
    bool operator ()(const A & a, const A &b) {    return
(a.getA()==b.getA());}//LINE I
};
int main () {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5, 6, 6, 9, 8, 2 };
    deque<int> d (mynumbers, mynumbers +12);
    deque<int>::iterator it = search_n(d.begin(), d.end(), 2, 1, Equals());//LINE II
    cout<< it-d.begin()<<endl;//LINE III
    return 0;
}
  
compilation error in LINE II
 

  
program outputs: 11
 

  
compilation error in LINE III
 

  
program outputs: 12
 

  
program outputs: 4
 

  
compilation error in LINE I
 

  
the exception will be thrown at LINE II
 

  
program outputs: 3
 
 
Question 27
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    map<int, int> m;
    for(int i=0; i < 7; i++) {
        m[i]=mynumbers[i];
    }
    pair<const int,int> p(4,1);
    map<int, int>::iterator it = find(m.begin(), m.end(), p);//LINE I
    if (it != m.end())
        cout<<it->first<<endl;
    else
        cout<<"Not found!\n";
    return 0;
}

  
program outputs: Not found!
 

  
program outputs: 1
 

  
program outputs: 4
 

  
compilation error in LINE I
 

  
program outputs: 5
 

  
the exception will be thrown at LINE I
 
 
IncorrectQuestion 28
0 / 1 pts
What will happen when you attempt to compile and run the following code? Choose all
that apply.

#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

void myprint(pair<int, int> i) {


    cout << i.first << ", " ;
}

int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    map<int, int> m;
    for(int i=0; i < 7; i++) {
        m[i]=mynumbers[i];//LINE I
    }

    for_each(m.begin(), m.end(), myprint);//LINE II


    return 0;
}

  
size of map m is 8
 

  
size of map m is 6
 

  
compilation error in LINE II
 

  
program outputs: 0
 

  
program outputs: 0, 1, 2, 3, 4, 5, 6,
 

  
size of map m is 7
 

  
program outputs: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
 

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
the exception will be thrown at LINE II
 

  
the exception will be thrown at LINE I
 
Score for this attempt: 23.5 out of 27
Submitted Dec 31 at 2:57pm
This attempt took 8 minutes.
 
IncorrectQuestion 1
0 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    copy(mynumbers, mynumbers + 7, v1.end());//LINE I
    for_each(v1.begin(), v1.end(), printer);//LINE II
    return 0;
}

  
runtime error at LINE II
 

  
compilation error in LINE I
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5,
 

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
program outputs: 3, 9, 0, 2, 1, 4,
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 
 
Question 2
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    copy_backward(mynumbers, mynumbers + 7, v1.rend());//LINE I
    for_each(v1.begin(), v1.end(), printer);//LINE II
    return 0;
}

  
compilation error in LINE I
 

  
program outputs: 5, 4, 1, 2, 9, 0,
 

  
program outputs: 3, 9, 0, 2, 1, 4,
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5,
 

  
runtime error at LINE I
 

  
compilation error in LINE II
 

  
program outputs: 5, 4, 1, 2, 0, 9, 3,
 

  
runtime error at LINE II
 
 
Question 3
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    set<int> s1(mynumbers, mynumbers + 7);
    vector<int> v1(s1.rbegin(), s1.rend());
    swap(s1, v1);//LINE I
    for_each(v1.begin(), v1.end(), printer);//LINE II
    return 0;
}

  
program outputs: 3, 9, 0, 2, 1, 4,
 

  
compilation error in LINE II
 

  
runtime error at LINE II
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5,
 

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
program outputs: 0, 1, 2, 3, 4, 5,
 

  
runtime error at LINE I
 

  
compilation error in LINE I
 
 
Question 4
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    deque<int> d1(mynumbers, mynumbers + 7);
    vector<int> v1(d1.rbegin(), d1.rend());
    swap_ranges(v1.begin(), v1.end(), d1.begin());//LINE I
    sort(d1.begin(), d1.end());//LINE II
    for_each(d1.begin(), d1.end(), printer);
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
compilation error in LINE II
 

  
program outputs: 5, 4, 1, 2, 0, 9, 0, 1, 2, 3, 4, 5,
 

  
program outputs: 5, 4, 1, 2, 0, 9, 3, 0, 1, 2, 3, 4, 5, 9,
 

  
runtime error at LINE I
 
  
program outputs: 0, 1, 2, 3, 4, 5, 9, 3, 9, 0, 2, 1, 4, 5,
 

  
runtime error at LINE II
 

  
program outputs: 0, 1, 2, 3, 4, 5, 3, 0, 2, 1, 4, 5,
 

  
compilation error in LINE I
 
 
Question 5
1 / 1 pts
What will happen when you attempt to compile and run the following code? Choose all
that apply.

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    set<int> s1(mynumbers, mynumbers + 7);
    vector<int> v1(s1.rbegin(), s1.rend());
    swap_ranges(v1.begin(), s1.end(), v1.begin());//LINE I
    swap_ranges(s1.begin(), v1.end(), s1.begin());//LINE II
    for_each(s1.begin(), s1.end(), printer);
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
compilation error in LINE II
 

  
compilation error in LINE I
 
  
program outputs: 0, 1, 2, 3, 4, 5, 9, 9, 5, 4, 3, 2, 1, 0,
 

  
program outputs: 9, 5, 4, 3, 2, 1, 0, 9, 5, 4, 3, 2, 1, 0,
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 

  
program outputs: 0, 1, 2, 3, 4, 5, 9, 0, 1, 2, 3, 4, 5, 9,
 
 
Question 6
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
void multiply (int a) {
    a*2;//LINE I
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    for_each(v1.begin(), v1.end(), multiply);
    iter_swap(v1.begin(), mynumbers+6);//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
program outputs: 5, 9, 0, 2, 1, 4, 5,
 

  
runtime error at LINE II
 

  
program outputs: 5, 9, 0, 2, 1, 4, 3,
 

  
runtime error at LINE I
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5,
 
 
Question 7
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int  multiply (int a) {
    return a*2;//LINE I
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    set<int> s1(mynumbers, mynumbers + 7);
    transform(s1.begin(), s1.end(), v1.begin(), multiply);//LINE II
    for_each(s1.begin(), s1.end(), printer);
    return 0;
}

  
program outputs: 0, 1, 2, 3, 4, 5,
 

  
runtime error at LINE II
 

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5,
 

  
compilation error in LINE II
 

  
compilation error in LINE I
 

  
runtime error at LINE I
 
 
Question 8
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int  multiply (int a) {
    return a*2;//LINE I
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    set<int> s1(mynumbers, mynumbers + 7);
    transform(s1.begin(), s1.end(), v1.begin(), multiply);//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}
  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
program outputs: 0, 2, 4, 6, 8, 10, 18,
 

  
runtime error at LINE II
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
program outputs: 6, 18, 0, 4, 2, 8, 10,
 

  
runtime error at LINE I
 
 
Question 9
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <deque>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int add (int a, int b)
{    
    return a+b;
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    set<int> s1(mynumbers, mynumbers + 7);
    deque<int> d1;
    transform(s1.begin(), s1.end(), v1.begin(), d1.begin(), add);//LINE I
    for_each(d1.begin(), d1.end(), printer); //LINE II
    return 0;
}

  
compilation error in LINE I
 

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
program outputs: 3, 10, 2, 5, 5, 9, 14,
 

  
runtime error at LINE I or undefined (probably empty) output
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5,
 

  
compilation error in LINE II
 

  
runtime error at LINE II
 
 
Question 10
1 / 1 pts
What will happen when you attempt to compile and run the following code? Choose all
that apply.

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    set<int> s1(mynumbers, mynumbers + 7);
    replace(v1.begin(), v1.end(), 9, 3);//LINE I
    for_each(v1.begin(), v1.end(), printer);//LINE II
    return 0;
}

  
runtime error at LINE I
 

  
runtime error at LINE II
 

  
compilation error in LINE II
 

  
compilation error in LINE I
 

  
program outputs: 3, 3, 0, 2, 1, 4, 5,
 

  
you can't call the replace function on the s1 set
 

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
program outputs: 9, 3, 0, 2, 1, 4, 5,
 
 
Question 11
1 / 1 pts
What will happen when you attempt to compile and run the following code? Choose all
that apply.
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
bool classifier(int v) {
    return v-3>0;
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    set<int> s1(mynumbers, mynumbers + 7);
    replace_if(v1.begin(), v1.end(), classifier, 7);//LINE I
    for_each(v1.begin(), v1.end(), printer);//LINE II
    return 0;
}

  
runtime error at LINE II
 

  
runtime error at LINE I
 

  
you can't call the replace function with the classifier function as the third parameter
 

  
compilation error in LINE II
 

  
program outputs: 0, 1, 2, 3, 7, 7, 7,
 

  
program outputs: 3, 7, 0, 2, 1, 7, 7,
 

  
compilation error in LINE I
 

  
program outputs: 7, 7, 0, 2, 1, 7, 7,
 
 
Question 12
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
bool classifier(int v) {
    return v-3>0;
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    set<int> s1(mynumbers, mynumbers + 7);
    replace(v1.begin(), v1.end(), classifier, 7);//LINE I
    for_each(v1.begin(), v1.end(), printer);//LINE II
    return 0;
}

  
compilation error in LINE II
 

  
runtime error at LINE II
 

  
compilation error in LINE I
 

  
program outputs: 7, 7, 0, 2, 1, 7, 7,
 

  
runtime error at LINE I
 

  
program outputs: 3, 7, 0, 2, 1, 7, 7,
 

  
program outputs: 0, 1, 2, 3, 7, 7, 7,
 
 
Question 13
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    vector<int> v1(7,1);
    fill(v1.begin()+3, v1.end()-1, 8);//LINE I
    fill_n(v1.begin()+4, 2, 7);//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
program outputs: 1, 1, 1, 8, 7, 7, 7,
 

  
runtime error at LINE I
 

  
compilation error in LINE I
 

  
program outputs: 1, 1, 1, 8, 7, 7, 1,
 

  
program outputs: 1, 1, 1, 8, 2, 7, 2,
 

  
compilation error in LINE II
 

  
runtime error at LINE II
 
 
IncorrectQuestion 14
0 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    vector<int> v1(7,1);
    fill(v1.begin()+3, v1.end()-1, 8);//LINE I
    fill_n(v1.begin()+4, 5, 7);//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
program outputs: 1, 1, 1, 8, 2, 7, 2,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
runtime error at LINE II
 

  
program outputs: 1, 1, 1, 8, 7, 7, 7,
 

  
program outputs: 1, 1, 1, 8, 7, 7, 1,
 
  
runtime error at LINE I
 
 
Question 15
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
void printer(int i) {    
    cout << i << ", ";
}
struct sequence {
    int val,inc;
public:
    sequence(int s, int i):val(s),inc(i){}
    operator int() const{//LINE I
        int r = val;
        return r;
    }
};
int main() {
    vector<int> v1(7);
    fill(v1.begin(), v1.end(), sequence(1,2));//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
runtime error at LINE I
 

  
runtime error at LINE II
 

  
compilation error in LINE II
 

  
compilation error in LINE I
 

  
program outputs: 1, 1, 1, 1, 1, 1, 1,
 

  
program outputs: 1, 3, 5, 7, 9, 11, 13,
 

  
program outputs: 2, 2, 2, 2, 2, 2, 2,
 

  
program outputs: 1, 2, 3, 4, 5, 6, 7,
 
 
Question 16
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void print(int v) {
    cout<<v<<", ";
}
struct Sequence {
    int start;
    Sequence(int start):start(start){}
    int operator()() {
        return start++;//LINE I
    }
};
int main() {
    vector<int> v1(7);
    generate_n(v1.begin(), 7, Sequence(1));//LINE II
    for_each(v1.begin(), v1.end(), print);
    return 0;
}

  
program outputs: 1, 1, 1, 1, 1, 1, 1,
 

  
runtime error at LINE II
 

  
compilation error in LINE II
 

  
program outputs: 7, 7, 7, 7, 7, 7, 7,
 

  
compilation error in LINE I
 

  
program outputs: 1, 2, 3, 4, 5, 6, 7,
 

  
runtime error at LINE I
 
 
Question 17
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void print(int v) {
    cout<<v<<", ";
}
struct Sequence {
    int start;
    Sequence(int start):start(start){}
    int operator()() {
        return start++;//LINE I
    }
};
int main() {
    vector<int> v1(7);
    generate_n(v1.begin(), 7, Sequence());//LINE II
    for_each(v1.begin(), v1.end(), print);
    return 0;
}

  
program outputs: 1, 1, 1, 1, 1, 1, 1,
 

  
compilation error in LINE II
 

  
runtime error at LINE II
 

  
runtime error at LINE I
 

  
program outputs: 1, 2, 3, 4, 5, 6, 7,
 

  
program outputs: 7, 7, 7, 7, 7, 7, 7,
 

  
compilation error in LINE I
 
 
PartialQuestion 18
0.5 / 1 pts
What will happen when you attempt to compile and run the following code? Choose all
that apply.

#include <vector>
#include <set>
#include <iostream>
#include <algorithm>
using namespace std;
void print(int v)
{    
    cout<<v<<", ";
}
struct Sequence {
    int start;
    Sequence(int start):start(start){}
    int operator()() { return start++; }
};
bool predicate(int v) { return v%2==0; }
int main() {
    vector<int> v1(7);
    generate_n(v1.begin(), 7, Sequence(1));//LINE I
    remove_if(v1.begin(), v1.end(), predicate);//LINE II
    for_each(v1.begin(), v1.end(), print);
    return 0;
}

  
you can't call the remove_if function on set
 

  
program outputs: 1, 3, 5, 7,
 

  
compilation error in LINE I
 

  
program outputs: 1, 3, 5, 7, 5, 6, 7,
 

  
program outputs: 2, 4, 6,
 

  
runtime error at LINE II
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 
 
Question 19
1 / 1 pts
What will happen when you attempt to compile and run the following code?  Choose all
that apply.

#include <vector>
#include <set>
#include <iostream>
#include <algorithm>
using namespace std;
void print(int v)
{    
    cout<<v<<", ";
}
struct Sequence {
    int start;
    Sequence(int start):start(start){}
    int operator()() { return start++; }
};
bool predicate(int v) { return v%2==0; }
int main() {
    vector<int> v1(7);
    generate_n(v1.begin(), 7, Sequence());//LINE I
    remove_if(v1.begin(), v1.end(), predicate);//LINE II
    for_each(v1.begin(), v1.end(), print);
    return 0;
}

  
program outputs: 1, 3, 5, 7, 5, 6, 7,
 

  
compilation error in LINE I
 

  
runtime error at LINE I
 

  
program outputs: 1, 3, 5, 7,
 

  
program outputs: 2, 4, 6,
 

  
compilation error in LINE II
 

  
you can't call the remove_if function on set
 

  
runtime error at LINE II
 
 
Question 20
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
template<class T>struct Out {
    ostream  & out;
    Out(ostream & o): out(o){}
    void operator()(const T & val ) {
        out<<val<<", ";
    }
};
struct Sequence {
    int start;
    Sequence(int start):start(start){}
    int operator()()
    {
        return 3*(start++ % 2);//LINE I
    }
};
int main() {
    vector<int> v1(7);
    generate(v1.begin(), v1.end(), Sequence(10));//LINE II
    unique(v1.begin(),v1.end());
    for_each(v1.begin(), v1.end(), Out<int>(cout) );
    return 0;
}

  
compilation error in LINE II
 

  
compilation error in LINE I
 

  
program outputs: 0, 3, 0, 3, 0, 3, 0, 3, 0, 3,
 

  
program outputs: 0, 3, 0, 3, 0, 3, 0,
 

  
program outputs: 3, 0, 3, 0, 3, 0, 3,
 

  
runtime error at LINE II
 

  
runtime error at LINE I
 

  
you can't call the unique function on vector
 
 
Question 21
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
template<class T>struct Out {
    ostream  & out;
    Out(ostream & o): out(o){}
    void operator()(const T & val ) {
        out<<val<<", ";
    }
};
struct Sequence {
    int start;
    Sequence(int start):start(start){}
    int operator()()
    {
        return 3*(start++ % 2);
    }
};
int main() {
    vector<int> v1(4);
    vector<int> v2(4);
    generate(v1.begin(), v1.end(), Sequence(10));//LINE I
    sort(v1.rbegin(), v1.rend());
    unique_copy(v1.begin(),v1.end(), v2.begin());//LINE II
    for_each(v2.begin(), v2.end(), Out<int>(cout) );
    for_each(v1.begin(), v1.end(), Out<int>(cout) );
    return 0;
}

  
compilation error in LINE I
 

  
program outputs: 3, 0, 3, 0, 3, 0, 3, 0,
 

  
runtime error at LINE II
 

  
runtime error at LINE I
 

  
you can't call the unique_copy function on these vectors (v1, v2)
 

  
compilation error in LINE II
 

  
program outputs: 3, 0, 0, 0, 3, 3, 0, 0, 3, 0, 0, 0, 3, 3, 0, 0,
 

  
program outputs: 3, 0, 0, 0, 3, 3, 0, 0,
 
 
IncorrectQuestion 22
0 / 1 pts
What will happen when you attempt to compile and run the following code? Choose all
that apply.

#include <vector>
#include <iostream>
#include <set>
#include <deque>
#include <algorithm>
using namespace std;
template<class T>struct Out {
    ostream  & out;
    Out(ostream & o): out(o){}
    void operator()(const T & val ) {
        out<<val<<", ";
    }
};
struct Sequence {
    int start;
    Sequence(int start):start(start){}
    int operator()()
    {
        return start++ % 7;
    }
};
int main() {
    vector<int> v1(3);
    generate(v1.begin(), v1.end(), Sequence(10));//LINE I
    set<int> s1(v1.rbegin(), v1.rend());
    deque<int> d1(s1.rbegin(), s1.rend());
    reverse(v1.begin(),v1.end());
    reverse(d1.begin(), d1.end());//LINE II
    for_each(s1.begin(), s1.end(), Out<int>(cout) );
    for_each(v1.begin(), v1.end(), Out<int>(cout) );
    for_each(d1.begin(), d1.end(), Out<int>(cout) );
    return 0;
}

  
you can't call the reverse function on the d1 deque
 

  
program outputs: 3, 4, 5, 5, 4, 3, 3, 4, 5,
 

  
compilation error in LINE I
 

  
program outputs: 5, 4, 3, 3, 4, 5, 3, 4, 5,
 

  
runtime error at LINE II
 

  
you can't call the reverse function on the s1 set
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
program outputs: 3, 4, 5, 3, 4, 5, 3, 4, 5,
 
 
Question 23
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;
template<class T>struct Out {
    ostream  & out;
    Out(ostream & o): out(o){}
    void operator()(const T & val ) {
        out<<val<<", ";
    }
};
struct Sequence {
    int start;
    Sequence(int start):start(start){}
    int operator()()
    {
        return start++ % 7;
    }
};
int main() {
    vector<int> v1(4);
    vector<int> v2(4);
    generate(v1.begin(), v1.end(), Sequence(10));
    reverse_copy(v1.begin(),v1.end(), v2.rbegin());//LINE I
    sort(v2.begin(), v2.end(), less_equal<int>());;//LINE II
    for_each(v2.begin(), v2.end(), Out<int>(cout) );
    return 0;
}

  
runtime error at LINE I
 

  
program outputs: 0, 1, 2, 3,
 

  
compilation error in LINE II
 

  
program outputs: 3, 4, 5, 6,
 

  
program outputs: 10, 11, 12, 13,
 

  
you can't call thr sort function on the v2 vector
 

  
compilation error in LINE I
 

  
runtime error at LINE II
 

  
you can't call the reverse_copy function on the v1 and v2 vectors
 
 
Question 24
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;
template<class T>struct Out {
    ostream  & out;
    Out(ostream & o): out(o){}
    void operator()(const T & val ) {
        out<<val<<", ";
    }
};
struct Sequence {
    int start;
    Sequence(int start):start(start){}
    int operator()()
    {
        return start++ % 7;
    }
};
int main() {
    vector<int> v1(4);
    generate(v1.rbegin(), v1.rend(), Sequence(10));//LINE I
    rotate(v1.begin(),v1.begin() + 1, v1.end() );//LINE II
    for_each(v1.begin(), v1.end(), Out<int>(cout) );
    return 0;
}

  
runtime error at LINE I
 

  
program outputs: 5, 4, 3, 6,
 

  
program outputs: 10, 11, 12, 13
 

  
compilation error in LINE II
 

  
compilation error in LINE I
 

  
program outputs: 12, 11, 10, 13
 

  
runtime error at LINE II
 

  
you can't call the rotate function on the v1 vector
 

  
program outputs: 3, 4, 5, 6,
 
 
Question 25
1 / 1 pts
What will happen when you attempt to compile and run the following code?
#include <vector>
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;
template<class T>struct Out {
    ostream  & out;
    Out(ostream & o): out(o){}
    void operator()(const T & val ) {
        out<<val<<", ";
    }
};
struct Sequence {
    int start;
    Sequence(int start):start(start){}
    int operator()()
    {
        return start++ % 7;
    }
};
int main() {
    vector<int> v1(4);
    generate(v1.rbegin(), v1.rend(), Sequence(10));//LINE I
    random_shuffle(v1.begin(),v1.begin());//LINE II
    for_each(v1.begin(), v1.end(), Out<int>(cout) );
    return 0;
}

  
runtime error at LINE II
 

  
you can't call the random_shuffle function on the v1 vector
 

  
runtime error at LINE I
 

  
program outputs: 3, 4, 5, 6,
 

  
program outputs: 6, 5, 3, 4,
 

  
program outputs: 6, 5, 4, 3,
 
  
compilation error in LINE II
 

  
you can't predict the results of this code
 

  
compilation error in LINE I
 
 
Question 26
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;
template<class T>struct Out {
    ostream  & out;
    Out(ostream & o): out(o){}
    void operator()(const T & val ) {
        out<<val<<", ";
    }
};
struct Sequence {
    int start;
    Sequence(int start):start(start){}
    int operator()()
    {
        return start++ % 7;
    }
};
struct Odd {    bool operator()(int v) { return v%2==0; }};
int main() {
    vector<int> v1(4);
    generate(v1.rbegin(), v1.rend(), Sequence(10));//LINE I
    partition(v1.begin(),v1.begin(), Odd());//LINE II
    for_each(v1.begin(), v1.end(), Out<int>(cout) );
    return 0;
}

  
program outputs: 6, 5, 4, 3,
 

  
program outputs: 3, 4, 5, 6,
 

  
compilation error in LINE I
 

  
runtime error at LINE I
 

  
you can't predict the results of this code
 

  
you can't call the partition function on the v1 vector
 

  
runtime error at LINE II
 

  
compilation error in LINE II
 

  
program outputs: 6, 5, 3, 4,
 
 
Question 27
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;
template<class T>struct Out {
    ostream  & out;
    Out(ostream & o): out(o){}
    void operator()(const T & val ) {
        out<<val<<", ";
    }
};
struct Sequence {
    int start;
    Sequence(int start):start(start){}
    int operator()()
    {
        return start++ % 7;
    }
};
struct Odd {    bool operator()(int v) { return v%2==0; }};
int main() {
    vector<int> v1(4);
    generate(v1.rbegin(), v1.rend(), Sequence(10));//LINE I
    stable_partition(v1.begin(),v1.begin(), Odd());//LINE II
    for_each(v1.begin(), v1.end(), Out<int>(cout) );
    return 0;
}

  
compilation error in LINE I
 

  
program outputs: 6, 5, 3, 4,
 

  
runtime error at LINE II
 

  
you can't call the stable_partition function on the v1 vector
 

  
runtime error at LINE I
 

  
program outputs: 6, 5, 4, 3,
 

  
you can't predict the results of this code
 

  
program outputs: 3, 4, 5, 6,
 

Score for this attempt: 23 out of 24


Submitted Dec 31 at 4:01pm
This attempt took 5 minutes.
 
Question 1
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <set>
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    sort(v1.begin(), v1.end(), greater<int>());//LINE I
    for_each(v1.begin(), v1.end(), printer);//LINE II
    return 0;
}

  
program outputs: 9, 5, 4, 3, 2, 1, 0,
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5,
 

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
you can't call the sort function on the v1 vector
 

  
runtime error at LINE I
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 
 
Question 2
1 / 1 pts
What will happen when you attempt to compile and run the following code? Choose all
that apply.

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
bool Compare(int _Left, int _Right) { return _Left < _Right; }
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    remove(v1.begin(), v1.end(), 1);//LINE I
    sort(v1.begin(), v1.end(), Compare);//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
program outputs: 0, 2, 3, 4, 5, 5, 9,
 

  
program outputs: 0, 2, 3, 4, 5, 9,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
the size of the v1 vector is 6
 

  
the size of the v1 vector is 7
 
 
Question 3
1 / 1 pts
What will happen when you attempt to compile and run the following code? Choose all
that apply.

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void printer(double i) {
    cout << i << ", ";
}
bool Compare(double a, double b) { return int(a)<int(b);}
int main() {
    double mynumbers[] = { 3.33, 9.19, 0.22, 2.12, 1.14, 4.45, 5.55 };
    vector<double> v1(mynumbers, mynumbers + 7);
    stable_sort(v1.begin(), v1.end(), Compare);//LINE I
    remove(v1.begin(), v1.end(), 2.12);//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
program outputs: 0.22, 1.14, 3.33, 4.45, 5.55, 9.19,
 

  
program outputs: 0.22, 1.14, 3.33, 4.45, 5.55, 9.19, 9.19,
 

  
program outputs: 0.22, 1.14, 2.22, 3.33, 4.45, 5.55, 9.19,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
the size of the v1 vector is 6
 

  
the size of the v1 vector is 7
 
 
Question 4
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <deque>
#include <iostream>
#include <algorithm>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 0, 1, 2, 3, 4, 5, 6 };
    deque<int> d1(mynumbers, mynumbers + 7);
    d1.push_back(9);//LINE I
    deque<int>::iterator it = lower_bound(d1.begin(), d1.end(), 4);
    for_each(it, d1.end(), printer);//LINE II
    return 0;
}

  
program outputs: 4, 5, 6, 9,
 

  
program outputs: 4, 5,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 
 
Question 5
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <deque>
#include <iostream>
#include <algorithm>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    deque<int> d1(mynumbers, mynumbers+7);
    sort(d1.begin(), d1.end());
    d1.push_back(6);
    deque<int>::iterator it = upper_bound(d1.begin(), d1.end(), 3);//LINE I
    for_each(it, d1.end(), printer);//LINE II
    return 0;
}

  
program outputs: 4, 5, 6,
 

  
program outputs: 4, 5, 6, 9,
 

  
program outputs: 4, 5, 9,
 

  
program outputs: 4, 5, 9, 6,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 
 
IncorrectQuestion 6
0 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <deque>
#include <iostream>
#include <algorithm>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    deque<int> d1(mynumbers, mynumbers + 7);
    sort(d1.begin(), d1.end());
    d1.push_back(3);//LINE I
    pair<deque<int>::iterator, deque<int>::iterator > result =
equal_range(d1.begin(), d1.end(), 3);//LINE II
    for_each(result.first, result.second, printer);
    return 0;
}

  
program outputs: 3,
 

  
program outputs: 3, 3
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 
 
Question 7
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <deque>
#include <iostream>
#include <algorithm>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    deque<int> d1(mynumbers, mynumbers + 7);
    d1.push_back(3);//LINE I
    sort(d1.begin(), d1.end());
    pair<deque<int>::iterator, deque<int>::iterator > result =
equal_range(d1.begin(), d1.end(), 3);//LINE II
    for_each(result.first, result.second, printer);
    return 0;
}

  
program outputs: 3,
 

  
program outputs: 3, 3,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 
 
Question 8
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <deque>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    deque<int> d1(mynumbers, mynumbers + 7);
    set<int> s1(mynumbers, mynumbers+7);
    cout<<binary_search(s1.begin(),s1.end(), 1)<<", "//LINE I
        <<binary_search(d1.begin(),d1.end(), 6)<<endl;//LINE II
    return 0;
}

  
program outputs: 1, 1,
 

  
program outputs: 1, 0,
 

  
program outputs: 0, 0,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 
 
Question 9
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<Pocket> v1(mynumbers, mynumbers + 7);
    sort(v1.begin(), v1.end());//LINE I
    remove(v1.begin(), v1.end(), 2);//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
program outputs: 0, 1, 3, 4, 5, 9,
 

  
program outputs: 0, 2, 3, 4, 5, 9,
 

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 
  
runtime error at LINE I
 

  
runtime error at LINE II
 
 
Question 10
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator > (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<Pocket> v1(mynumbers, mynumbers + 7);
    sort(v1.begin(), v1.end(), greater<Pocket>());//LINE I
    for_each(v1.begin(), v1.end(), printer);//LINE II
    return 0;
}

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
program outputs: 1, 2, 3, 4, 5, 9,
 
  
program outputs: 9, 5, 4, 3, 2, 1, 0,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 
 
Question 11
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
template<typename T>
class Pocket {
    T value;
public:
    Pocket(T value):value(value){}
    T getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
template<typename T>
ostream & operator <<(ostream & stream, const Pocket<T> & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket<double> i) {
    cout << i << ", ";
}
bool Compare(const Pocket<double> &_Left, const Pocket<double> &_Right)
{ return int(_Left.getValue()) < int(_Right.getValue());}
int main() {
    double mynumbers[] = { 3.33, 9.19, 0.22, 2.12, 1.14, 4.45, 5.55 };
    vector<double> v1(mynumbers, mynumbers + 7);//LINE I
    stable_sort(v1.begin(), v1.end(), Compare);//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
program outputs: 0.22, 1.14, 2.12, 3.33, 4.45, 5.55, 9.19,
 

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
program outputs: 3.33, 9.19, 0.22, 2.12, 1.14, 4.45, 5.55,
 

  
you can't call the sort function on vector with the elements of the 'double' type
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 
 
Question 12
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <deque>
#include <iostream>
#include <algorithm>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 0, 1, 2, 3, 4, 5, 6};
    deque<Pocket> d1(mynumbers, mynumbers + 7);
    d1.push_back(9);//LINE I
    deque<Pocket>::iterator it = lower_bound(d1.begin(), d1.end(), 4);//LINE II
    for_each(it, d1.end(), printer);
    return 0;
}

  
program outputs: 4, 5,
 

  
program outputs: 3, 4, 5, 6, 9,
 

  
program outputs: 3, 4, 5,
 

  
program outputs: 4, 5, 6, 9,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 
  
runtime error at LINE I
 

  
runtime error at LINE II
 
 
Question 13
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <deque>
#include <iostream>
#include <algorithm>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    deque<Pocket> d1(mynumbers, mynumbers + 7);
    sort(d1.begin(), d1.end());
    deque<Pocket>::iterator it = upper_bound(d1.begin(), d1.end(), Pocket(2));//LINE
I
    for_each(it+1, d1.end(), printer); //LINE II
    return 0;
}

  
program outputs: 4, 5, 9
 

  
program outputs: 3, 4, 5, 9,
 
  
program outputs: 3, 4, 5,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 
 
Question 14
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <deque>
#include <iostream>
#include <algorithm>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    deque<Pocket> d1(mynumbers, mynumbers + 7);
    d1.push_back(3);
    sort(d1.begin(), d1.end());//LINE I
    pair<deque<Pocket> ::iterator, deque<Pocket>::iterator > result =
equal_range(d1.begin(), d1.end(), Pocket(4));//LINE II
    for_each(result.first, result.second, printer);
    return 0;
}

  
program outputs: 4,
 

  
program outputs: 4, 4,
 

  
program outputs: 3, 4,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 
 
Question 15
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <deque>
#include <iostream>
#include <algorithm>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    deque<Pocket> d1(mynumbers, mynumbers + 7);
    d1.push_back(3);//LINE I
    sort(d1.begin(), d1.end());
    pair<deque<Pocket> ::iterator, deque<Pocket>::iterator > result =
equal_range(d1.begin(), d1.end(), Pocket(3));//LINE II
    for_each(result.first, result.second, printer);
    return 0;
}

  
program outputs: 3,
 

  
program outputs: 3, 3,
 

  
program outputs: 3, 4,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 
 
Question 16
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <deque>
#include <set>
#include <iostream>
#include <algorithm>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    deque<Pocket> d1(mynumbers, mynumbers + 7);
    sort(d1.begin(), d1.end());//LINE I
    set<Pocket> s1(mynumbers, mynumbers + 7);
    cout<<binary_search(s1.begin(),s1.end(), Pocket(3))<<", "//LINE II
        <<binary_search(d1.begin(),d1.end(), Pocket(2))<<endl;
    return 0;
}

  
program outputs: 3, 2
 

  
program outputs: 2, 3,
 

  
program outputs: 1, 0,
 
  
program outputs: 1, 1,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 
 
Question 17
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <set>
#include <iostream>
#include <algorithm>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    set<Pocket> s1(mynumbers, mynumbers + 7);
    sort(s1.begin(), s1.end());//LINE I
    for_each(s1.begin(), s1.end(), printer);//LINE II
    return 0;
}

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
program outputs: 0, 1, 2, 3, 4, 5,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 
 
Question 18
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<Pocket> s1(mynumbers, mynumbers + 7);//LINE I
    sort(s1.begin(), s1.end(), greater<Pocket>());//LINE II
    for_each(s1.begin(), s1.end(), printer);
    return 0;
}

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
program outputs: 9, 5, 4, 3, 2, 1, 0,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 
 
Question 19
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator > (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<Pocket> s1(mynumbers, mynumbers + 7);//LINE I
    sort(s1.begin(), s1.end(), greater<Pocket>());//LINE II
    for_each(s1.begin(), s1.end(), printer);
    return 0;
}

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
program outputs: 9, 5, 4, 3, 2, 1, 0,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 
 
Question 20
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <ctype.h>
using namespace std;
template<typename T>
class Pocket {
    T value;
public:
    Pocket(T value):value(value){}
    T getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
template<typename T>
ostream & operator <<(ostream & stream, const Pocket<T> & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket<string> i) {
    cout << i << ", ";
}
string tolower(const string & s) {
    string tmp(s);
    for(unsigned i = 0; i< tmp.size(); ++i){
        tmp[i] = tolower(tmp[i]);     }
    return tmp; }
bool Compare(const Pocket<string> &_Left, const Pocket<string> &_Right)
    {return tolower(_Left.getValue())<tolower(_Right.getValue()); }
int main() {
    string t[]={"zzz", "zzZ","yyY", "Zzz", "Yyy", "zZz", "yyy","yYy"};//LINE I
    vector<Pocket<string> > v1; v1.assign(t, t+8);//LINE II
    stable_sort(v1.begin(), v1.end(), Compare);
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
program outputs: YYY, YYY, YYY, YYY, ZZZ, ZZZ, ZZZ, ZZZ,
 

  
program outputs: yyy, yyy, yyy, yyy, zzz, zzz, zzz, zzz,
 

  
program outputs: yyY, Yyy, yyy, yYy, zzz, zzZ, Zzz, zZz,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 
 
Question 21
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <deque>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator > (const Pocket & _Right) const
    { return value > _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    deque<Pocket> d1(mynumbers, mynumbers + 7);
    sort(d1.begin(), d1.end(), greater<Pocket>());//LINE I
    deque<Pocket>::iterator it = lower_bound(d1.begin(), d1.end(), 3,
greater<Pocket>());//LINE II
    for_each(it, d1.end(), printer);
    return 0;
}

  
program outputs: 3, 2, 1, 0
 

  
program outputs: 3, 4, 5, 9,
 

  
program outputs: 0, 1, 2, 3,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 
 
Question 22
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <deque>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
    bool operator > (const Pocket & _Right) const
    {     return _Right < value; } //LINE I
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    deque<Pocket> d1(mynumbers, mynumbers + 7);
    sort(d1.begin(), d1.end());
    deque<Pocket>::iterator it = upper_bound(d1.begin(), d1.end(), Pocket(5),
greater<Pocket>());//LINE II
    for_each(it, d1.end(), printer);
    return 0;
}

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
program outputs: 5, 9,
 

  
program outputs: 5,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 
 
Question 23
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <deque>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
    bool operator > (const Pocket & _Right) const
    { return value > _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    deque<Pocket> d1(mynumbers, mynumbers + 7);
    d1.push_back(3);
    sort(d1.begin(), d1.end(), greater<Pocket>());//LINE I
    pair<deque<Pocket> ::iterator, deque<Pocket>::iterator > result =
        equal_range(d1.begin(), d1.end(), Pocket(3), greater<Pocket>());//LINE II
    for_each(result.first, result.second, printer);
    return 0;
}

  
program outputs: 3,
 

  
program outputs: 3, 4,
 

  
program outputs: 3, 3,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 
 
Question 24
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <deque>
#include <set>
#include <iostream>
#include <algorithm>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    deque<Pocket> d1(mynumbers, mynumbers + 7);
    sort(d1.begin(), d1.end());
    set<Pocket> s1(mynumbers, mynumbers + 7);
    cout<<binary_search(s1.begin(),s1.end(), Pocket(3))<<", "//LINE I
        <<binary_search(d1.begin(),d1.end(), Pocket(5))<<endl;//LINE II
    return 0;
}

  
program outputs: 3, 5
 

  
program outputs: 3, 3,
 

  
program outputs: 1, 1,
 

  
program outputs: 1, 0,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

Quiz Score: 23 out of 24
Score for this attempt: 29.17 out of 30
Submitted Dec 31 at 2:47pm
This attempt took 8 minutes.
 
Question 1
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers1[]={3, 9, 0, 2};
    int mynumbers2[]={6, 1, 4, 5};
    vector<int> v1(7);
    sort(mynumbers2, mynumbers2 + 4);
    sort(mynumbers1, mynumbers1 + 4);//LINE I
    merge(mynumbers1, mynumbers1+4, mynumbers2, mynumbers2+3, v1.begin());//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
runtime error at LINE II
 

  
program outputs: 1, 2, 3, 4, 5, 9, 0,
 

  
compilation error in LINE II
 

  
program outputs: 0, 1, 2, 3, 4, 5, 9,
 

  
program outputs: 6, 1, 4, 5, 3, 9, 0, 2,
 

  
program outputs: 3, 9, 0, 2, 6, 1, 4, 5,
 

  
compilation error in LINE I
 
 
Question 2
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers1[]={3, 9, 0, 2};
    int mynumbers2[]={6, 1, 4, 5};
    vector<int> v1(7);
    sort(mynumbers2, mynumbers2 + 4);
    sort(mynumbers1, mynumbers1 + 4);//LINE I
    merge(mynumbers1, mynumbers1+3, mynumbers2, mynumbers2+3, v1.begin());//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
program outputs: 0, 1, 2, 4, 5, 6,
 

  
compilation error in LINE II
 

  
program outputs: 0, 1, 2, 3, 4, 5, 0,
 

  
compilation error in LINE I
 

  
program outputs: 0, 1, 2, 0, 4, 5,
 

  
runtime error at LINE II
 

  
program outputs: 0, 0, 1, 2, 4, 5, 6,
 
 
Question 3
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers1[]={3, 9, 0, 2};
    int mynumbers2[]={6, 1, 4, 5};
    vector<double> v1(7);
    sort(mynumbers2, mynumbers2 + 4);
    sort(mynumbers1, mynumbers1 + 4);//LINE I
    merge(mynumbers1, mynumbers1+3, mynumbers2, v1.begin());//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
program outputs: 0, 1, 2, 4, 5, 6,
 

  
runtime error at LINE II
 

  
program outputs: 0, 0, 1, 2, 4, 5, 6,
 

  
compilation error in LINE I
 

  
program outputs: 0, 1, 2, 3, 4, 5, 0,
 

  
compilation error in LINE II
 

  
program outputs: 0, 1, 2, 0, 4, 5,
 
 
Question 4
1 / 1 pts
What will happen when you attempt to compile and run the following code?
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers1[]={ 3, 9, 0, 2};
    int mynumbers2[]={6, 1, 4, 5};
    vector<int> v1(14);
    vector<int> v2(34);
    sort(mynumbers2, mynumbers2 + 4);
    sort(mynumbers1, mynumbers1 + 4);
    copy(mynumbers1, mynumbers1+4, v1.begin());
    copy(mynumbers2, mynumbers2+4, v1.begin()+5);//LINE I
    sort(v1.begin(), v1.end());
    merge(v1.begin(), v1.end(), v1.begin(), v1.end(), v2.begin());//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
runtime error at LINE II
 

  
program outputs: 0, 0, 0, 1, 2, 3, 4, 5, 6, 9,
 

  
compilation error in LINE II
 

  
program outputs: 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 9,
 

  
program outputs: 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 9,
 

  
compilation error in LINE I
 

  
program outputs: 0, 1, 2, 3, 4, 5, 6, 9,
 
 
Question 5
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers1[]={ 3, 9, 0, 2};
    int mynumbers2[]={6, 1, 4, 7};
    vector<int> v1(10);
    vector<int> v2(20);
    sort(mynumbers2, mynumbers2 + 4);
    sort(mynumbers1, mynumbers1 + 4);
    copy(mynumbers1, mynumbers1+4, v1.begin());
    copy(mynumbers2, mynumbers2+4, v1.begin()+5);//LINE I
    sort(v1.begin(), v1.end());
    merge(v1.begin(), v1.end(), v1.begin(), v1.end(), v2.begin());//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
program outputs: 0, 0, 0, 1, 2, 3, 4, 6, 7, 9,
 

  
program outputs: 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 9,
 

  
runtime error at LINE II
 

  
program outputs: 0, 1, 2, 3, 4, 7, 9,
 

  
compilation error in LINE I
 

  
program outputs: 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 9,
 
  
compilation error in LINE II
 
 
Question 6
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <deque>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
int main() {
    int mynumbers1[]={3, 9, 0, 2};
    int mynumbers2[]={6, 1, 4, 5};
    sort(mynumbers1, mynumbers1 + 4);
    sort(mynumbers2, mynumbers2 + 4);
    deque<int> d1(mynumbers1, mynumbers1+3);//LINE I
    set<int> s1(mynumbers2, mynumbers2+3);//LINE II
    sort(d1.begin(), d1.end());
    cout<<includes(s1.begin(), s1.end(), mynumbers1, mynumbers1+4) <<", "
        <<includes(d1.begin(), d1.end(), mynumbers1, mynumbers1+4)
        <<endl;
    return 0;
}

  
program outputs: FALSE, FALSE
 

  
program outputs: false, false
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
program outputs: 0, 1,
 

  
program outputs: 0, 0,
 

  
runtime error at LINE II
 
 
Question 7
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers1[]={3, 9, 0, 2};
    int mynumbers2[]={6, 1, 4, 5};
    vector<int> v1(7);
    sort(mynumbers2, mynumbers2 + 4);//LINE I
    sort(mynumbers1, mynumbers1 + 4);
    set_union(mynumbers1, mynumbers1+3, mynumbers2, mynumbers2+3, v1.begin());//LINE
II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
program outputs: 0, 1, 2, 3, 4, 5, 0,
 

  
program outputs: 0, 1, 2, 3, 4, 5,
 

  
runtime error at LINE I
 

  
program outputs: 0, 2, 3, 4, 5,
 

  
runtime error at LINE II
 
  
compilation error in LINE II
 

  
program outputs: 1, 2, 3, 4, 5,
 
 
Question 8
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers1[]={3, 9, 0, 2};
    int mynumbers2[]={6, 1, 4, 5};
    vector<int> v1(7);
    sort(mynumbers2, mynumbers2 + 4);//LINE I
    sort(mynumbers1, mynumbers1 + 4);
    set_union(mynumbers1, mynumbers1+3, mynumbers2, mynumbers2+3, v1.begin());//LINE
II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
program outputs: 0, 0, 1, 2, 3, 4, 5,
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
program outputs: 1, 2, 3, 4, 5,
 

  
program outputs: 0, 2, 3, 4, 5,
 

  
program outputs: 0, 1, 2, 3, 4, 5, 0,
 

  
runtime error at LINE II
 
 
Question 9
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers1[]={3, 9, 0, 2};
    int mynumbers2[]={6, 1, 4, 2};
    vector<int> v1(7);
    sort(mynumbers2, mynumbers2 + 4);
    sort(mynumbers1, mynumbers1 + 4);//LINE I
    set_intersection(mynumbers1, mynumbers1+3, mynumbers2, mynumbers2+3,
v1.begin());//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
compilation error in LINE II
 

  
program outputs: 0, 0, 0, 0, 0, 0, 0,
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 
  
program outputs: 9, 1,
 

  
program outputs: 0, 0, 0, 0, 0,
 

  
program outputs: 2, 0, 0, 0, 0, 0,
 
 
Question 10
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers1[]={3, 9, 0, 2};
    int mynumbers2[]={6, 1, 4, 5};
    vector<int> v1(7);
    sort(mynumbers2, mynumbers2 + 4);
    sort(mynumbers1, mynumbers1 + 4);//LINE I
    set_intersection(mynumbers1, mynumbers1+3, mynumbers2, mynumbers2+3,
v1.begin());//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
program outputs: 0, 0, 0, 0, 0, 0,
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
program outputs: 0, 0, 0, 0, 0, 0, 0,
 

  
program outputs: 9, 1,
 

  
runtime error at LINE II
 

  
program outputs: 0, 0, 0, 0, 0,
 
 
Question 11
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers1[]={3, 9, 0, 2};
    int mynumbers2[]={6, 1, 4, 5};
    vector<int> v1(7);
    sort(mynumbers2, mynumbers2 + 4);
    sort(mynumbers1, mynumbers1 + 4);//LINE I
    set_difference(mynumbers1, mynumbers1+4, mynumbers2, mynumbers2+4,
v1.begin());//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
program outputs: 0, 2, 3, 9, 0, 0, 0,
 

  
program outputs: 0, 3, 9, 0, 0, 0, 0,
 

  
runtime error at LINE I
 
  
program outputs: 0, 0, 0, 0, 0, 0, 0,
 

  
compilation error in LINE II
 

  
program outputs: 0, 3, 9, 0, 0, 0,
 

  
runtime error at LINE II
 
 
Question 12
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers1[]={3, 9, 0, 2};
    int mynumbers2[]={6, 1, 4, 5};
    vector<int> v1(7);
    sort(mynumbers2, mynumbers2 + 3);
    sort(mynumbers1, mynumbers1 + 3);
    set_difference(mynumbers1, mynumbers1+3, mynumbers2, mynumbers2+3, v1.begin());
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
runtime error at LINE II
 

  
runtime error at LINE I
 

  
program outputs: 0, 3, 9, 0, 0, 0,
 

  
program outputs: 0, 0, 0, 0, 0, 0, 0,
 

  
program outputs: 0, 3, 9, 0, 0, 0, 0,
 

  
compilation error in LINE II
 

  
program outputs: 0, 3, 9,
 
 
Question 13
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers1[]={3, 9, 0, 2};
    int mynumbers2[]={6, 1, 4, 5};
    vector<int> v1(5);
    sort(mynumbers2, mynumbers2 + 3);
    sort(mynumbers1, mynumbers1 + 3);//LINE I
    set_symmetric_difference(mynumbers1, mynumbers1+3, mynumbers2, mynumbers2+2,
v1.begin());//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
program outputs: 0, 1, 3, 4, 9, 0, 0,
 

  
program outputs: 0, 1, 3, 4, 9, 0,
 
  
program outputs: 0, 3, 9, 0, 0, 0, 0,
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
program outputs: 0, 1, 3, 4, 9,
 

  
runtime error at LINE II
 
 
Question 14
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    sort(v1.begin(), v1.end(), greater<int>());//LINE I
    cout<< *min_element(v1.begin(), v1.end()) << ", ";//LINE II
    return 0;
}

  
program outputs: 0,
 

  
runtime error at LINE I
 

  
program outputs: 3, 9, 0,
 
  
runtime error at LINE II
 

  
program outputs: 3,
 

  
compilation error in LINE II
 

  
program outputs: 0, 0, 0,
 
 
Question 15
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);//LINE I
    cout<< *min_element(v1.begin(), v1.end()) << ", ";//LINE II
    return 0;
}

  
you can't call the min_element function on the non-ordered v1 vector
 

  
program outputs: 0,
 

  
program outputs: 3, 9, 0,
 

  
program outputs: 3,
 
  
runtime error at LINE II
 

  
program outputs: 0, 0, 0,
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 
 
Question 16
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);//LINE I
    cout<< *max_element(v1.begin(), v1.end()) << ", ";//LINE II
    return 0;
}

  
runtime error at LINE I
 

  
program outputs: 0,
 

  
program outputs: 5,
 

  
compilation error in LINE II
 
  
you can't call the max_element function on the non-ordered v1 vector
 

  
program outputs: 9,
 

  
program outputs: 3,
 

  
runtime error at LINE II
 
 
Question 17
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {
    cout << i << ", ";
}
int main() {
    Pocket mynumbers1[]={3, 9, 0, 2};
    Pocket mynumbers2[]={6, 1, 4, 5};
    vector<Pocket> v1(mynumbers1, mynumbers1+4);//LINE I
    sort(mynumbers2, mynumbers2 + 4);
    sort(mynumbers1, mynumbers1 + 4);
    merge(mynumbers1, mynumbers1+2, mynumbers2, mynumbers2+2, v1.begin());//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
program outputs: 3, 9, 0, 2, 6, 1, 4, 5,
 

  
runtime error at LINE I
 

  
program outputs: 3, 9, 0, 6, 1, 4, 5,
 

  
compilation error in LINE II
 

  
you can't call the merge function on slices of the mynumbers arrays
 

  
runtime error at LINE II
 

  
program outputs: 3, 9, 0,
 

  
program outputs: 0, 1, 2, 4,
 
 
PartialQuestion 18
0.67 / 1 pts
What will happen when you attempt to compile and run the following code? Choose all
that apply.

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {
    cout << i << ", ";
}
int main() {
    Pocket mynumbers1[]={ 3, 9, 0, 2};
    Pocket mynumbers2[]={6, 1, 4, 5};
    vector<Pocket> v1(7, 0);
    sort(mynumbers2, mynumbers2 + 4);
    copy(mynumbers1, mynumbers1+4, v1.begin());
    copy(mynumbers2, mynumbers2+4, v1.begin()+3);
    sort(v1.begin(), v1.begin() + 5);//LINE I
    inplace_merge(v1.begin(), v1.begin()+5, v1.end());//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
compilation error in LINE II
 

  
you shouldn't call the inplace_merge function on the non-ordered v1 vector
 

  
program outputs: 3, 9, 0, 6, 1, 4,
 

  
runtime error at LINE II
 

  
runtime error at LINE I
 

  
program outputs: 0, 1, 3, 4, 5, 6, 9,
 
  
program outputs: 3, 9, 0,
 

  
program outputs: 3, 9, 0, 6, 1, 4, 5,
 
 
Question 19
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {
    cout << i << ", ";
}
int main() {
    Pocket mynumbers1[]={ 3, 9, 0, 2};
    sort(mynumbers1, mynumbers1 + 4);//LINE I
    vector<Pocket> v1(mynumbers1, mynumbers1+3);
    inplace_merge(v1.begin(), v1.begin()+3, v1.end());//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
compilation error in LINE II
 

  
program outputs: 0, 2, 3, 9
 
  
program outputs: 0, 2, 3,
 

  
runtime error at LINE II
 

  
program outputs: 0, 0, 0, 0,
 

  
program outputs: 0, 0, 0,
 

  
runtime error at LINE I
 
 
Question 20
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <deque>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
int main() {
    Pocket mynumbers1[] = { 3, 9, 0, 2, 1, 4, 5 };
    Pocket mynumbers2[]={Pocket(3),Pocket(2),Pocket(4),Pocket(1)};
    deque<Pocket> d1(mynumbers1, mynumbers1+7);
    set<Pocket> s1(mynumbers1, mynumbers1+7);
    sort(d1.begin(), d1.end());
    sort(mynumbers1, mynumbers1+5);
    sort(mynumbers2, mynumbers2+4);
    cout<<includes(d1.begin(),d1.end(), mynumbers1, mynumbers1+4)<<", "//LINE I
        <<includes(s1.begin(),s1.end(), mynumbers2, mynumbers2+4)//LINE II
        <<endl;
    return 0;
}

  
program outputs: 1, 0
 

  
program outputs: 1, 1
 

  
program outputs: 0, 1
 

  
program outputs: 0, 0
 

  
runtime error at LINE I
 

  
compilation error in LINE II
 

  
runtime error at LINE II
 
 
Question 21
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <deque>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
int main() {
    Pocket mynumbers1[] = { 3, 9, 0, 2, 1, 4, 5 };
    Pocket mynumbers2[]={Pocket(3),Pocket(2),Pocket(4),Pocket(1)};
    deque<Pocket> d1(mynumbers1, mynumbers1+7);
    set<Pocket> s1(mynumbers1, mynumbers1+7);
    sort(d1.begin(), d1.end());
    sort(mynumbers1, mynumbers1+5);
    sort(mynumbers2, mynumbers2+4);
    cout<<includes(d1.begin(),d1.end(), mynumbers1, mynumbers1+4)<<", "//LINE I
        <<includes(s1.begin(),s1.end(), mynumbers2, mynumbers2+3)//LINE II
        <<endl;
    return 0;
}

  
compilation error in LINE II
 

  
program outputs: 1, 0
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 

  
program outputs: 0, 0
 

  
program outputs: 1, 1
 

  
program outputs: 0, 1
 
 
Question 22
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
    bool operator < (const int & _Right) const
    { return value < _Right; }
    operator int() const
    { return value;    }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {
    cout << i << ", ";
}
int main() {
    Pocket mynumbers1[]={ 3, 9, 0, 2};
    int mynumbers2[]={6, 1, 4, 5};
    vector<Pocket> v1(7,0);
    sort(mynumbers2, mynumbers2 + 4);
    sort(mynumbers1, mynumbers1 + 4);//LINE I
    set_union(mynumbers1, mynumbers1+3, mynumbers2, mynumbers2+3, v1.begin());//LINE
II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
program outputs: 6, 1, 4, 5
 

  
program outputs: 3, 9, 0, 2
 
  
compilation error in LINE II
 

  
program outputs: 0, 1, 2, 3, 4, 5,
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 

  
program outputs: 0, 1, 2, 3, 4, 5, 0
 
 
Question 23
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
    bool operator < (const int & _Right) const
    { return value < _Right; }
    operator int() const
    { return value;    }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {
    cout << i << ", ";
}
int main() {
    Pocket mynumbers1[]={ 3, 9, 0, 2};
    int mynumbers2[]={6, 1, 4, 2};
    vector<Pocket> v1(7,0);
    sort(mynumbers2, mynumbers2 + 4);
    sort(mynumbers1, mynumbers1 + 4);//LINE I
    set_intersection(mynumbers1, mynumbers1+3, mynumbers2, mynumbers2+3,
v1.begin());//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
runtime error at LINE II
 

  
program outputs: 0, 0, 0, 0, 0, 0, 0
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 

  
program outputs: 0, 0, 0, 0, 0, 0,
 

  
program outputs: 5, 7, 8,
 

  
program outputs: 2, 0, 0, 0, 0, 0, 0,
 
 
Question 24
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
    bool operator < (const int & _Right) const
    { return value < _Right; }
    operator int() const
    { return value;    }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {
    cout << i << ", ";
}
int main() {
    Pocket mynumbers1[]={ 3, 9, 0, 2};
    int mynumbers2[]={6, 1, 4, 2};
    vector<Pocket> v1(7,0);
    sort(mynumbers2, mynumbers2 + 4);
    sort(mynumbers1, mynumbers1 + 4);//LINE I
    set_difference(mynumbers1, mynumbers1+3, mynumbers2, mynumbers2+3,
v1.begin());//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
runtime error at LINE II
 

  
program outputs: 0, 3, 0, 0, 0, 0, 0,
 

  
program outputs: 2, 0, 0, 0, 0, 0, 0,
 

  
runtime error at LINE I
 

  
program outputs: 3, 0, 0, 0, 0, 0, 0
 

  
compilation error in LINE II
 
 
Question 25
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
    bool operator < (const int & _Right) const
    { return value < _Right; }
    operator int() const
    { return value;    }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {
    cout << i << ", ";
}
int main() {
    Pocket mynumbers1[]={ 3, 9, 0, 2};
    int mynumbers2[]={6, 1, 4, 2};
    vector<Pocket> v1(7,0);
    sort(mynumbers2, mynumbers2 + 4);
    sort(mynumbers1, mynumbers1 + 4);//LINE I
    set_symmetric_difference(mynumbers1, mynumbers1+3, mynumbers2, mynumbers2+3,
v1.begin());//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
runtime error at LINE II
 
  
program outputs: 0, 1, 3, 4, 0, 0, 0,
 

  
runtime error at LINE I
 

  
compilation error in LINE II
 

  
program outputs: 0, 3, 0, 0, 0, 0, 0,
 

  
program outputs: 3, 0, 0, 0, 0, 0, 0
 
 
PartialQuestion 26
0.5 / 1 pts
What will happen when you attempt to compile and run the following code? Choose all
that apply.

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
    bool operator < (const int & _Right) const
    { return value < _Right; }
    operator int() const
    { return value;    }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
int main() {
    Pocket mynumbers1[]={ 3, 9, 0, 2};
    int mynumbers2[]={6, 1, 4, 2};
    vector<Pocket> v1(7,0);
    sort(mynumbers2, mynumbers2 + 4);
    sort(mynumbers1, mynumbers1 + 4);
    set_symmetric_difference(mynumbers1, mynumbers1+3, mynumbers2, mynumbers2+3,
v1.begin());//LINE I
    cout<< *min_element(v1.begin(), v1.end()) << ", " ;//LINE II
    return 0;
}

  
program outputs: 0,
 

  
compilation error
 

  
runtime error at LINE II
 

  
program outputs: 3,
 

  
compilation error in LINE II
 

  
program outputs: 1,
 

  
runtime error at LINE I
 
 
Question 27
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
    bool operator < (const int & _Right) const
    { return value < _Right; }
    operator int() const
    { return value;    }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
int main() {
    Pocket mynumbers1[]={ 3, 9, 0, 2};
    int mynumbers2[]={6, 1, 4, 2};
    vector<Pocket> v1(7,0);
    sort(mynumbers2, mynumbers2 + 4);
    sort(mynumbers1, mynumbers1 + 4);
    set_symmetric_difference(mynumbers1, mynumbers1+3, mynumbers2, mynumbers2+3,
v1.begin());//LINE I
    cout<< max_element(v1.begin(), v1.end()) << ", " ;//LINE II
    return 0;
}

  
compilation error in LINE II
 

  
runtime error at LINE II
 

  
program outputs: 9,
 

  
program outputs: 0,
 

  
runtime error at LINE I
 

  
program outputs: 3,
 

  
program outputs: 4,
 
 
Question 28
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
void printer(string i) {
    cout << i << ", ";
}
int main() {
    string myvalues[]={"yyy","Yyy", "yYy","yyY","ZZZ","zZZ", "ZzZ", "ZZz"};
    vector<string> v1(myvalues, myvalues+8);
    sort(v1.begin(), v1.end()); //LINE I
    remove(v1.begin(), v1.end(), "yyy"); //LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
runtime error at LINE I
 

  
program outputs: yyy, Yyy, ZZZ, ZZz, ZzZ, yYy, yyY, zZZ, ,
 

  
program outputs: Yyy, ZZZ, ZZz, ZzZ, yYy, yyY, zZZ,
 

  
runtime error at LINE II
 

  
compilation error in LINE II
 

  
program outputs: Yyy, ZZZ, ZZz, ZzZ, yYy, yyY, zZZ, , - last element could be empty or
zZZ or yyy
 
 
Question 29
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
int main() {
    char s[]={"lazybrownfox"};
    char pattern1[]={"ybr"};
    char pattern2[]={"nfo"};
    sort(s, s+8); //LINE I
    sort(pattern1, pattern1+3); //LINE II
    sort(pattern2, pattern2+3);
    cout<<includes(s, s+7, pattern1, pattern1+3) <<", "
        <<includes(s, s+6, pattern2, pattern2+3);
    return 0;
}

  
program outputs: 1, 0
 

  
runtime error at LINE I
 

  
compilation error in LINE II
 

  
program outputs: 0, 0
 

  
program outputs: 1, 1
 

  
runtime error at LINE II
 

  
program outputs: 0, 1
 
 
Question 30
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <deque>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
bool Compare(char _Left, char _Right) { return tolower(_Left) < tolower(_Right);}
int main() {
    char s[]={"lazybrownfox"};
    char pattern1[]={"ybr"};
    char pattern2[]={"nfo"};
    sort(s, s+8, Compare);
    sort(pattern1, pattern1+3);
    sort(pattern2, pattern2+3);
    cout<<includes(s, s+7, pattern1, pattern1+3) <<", "
        <<pattern2;
    return 0;
}

  
program outputs: 1, 0,
 

  
program outputs: 1, fno,
 

  
runtime error at LINE I
 

  
compilation error in LINE II
 

  
program outputs: 1, nfo,
 

Score for this attempt: 19 out of 20


Submitted Dec 31 at 3:14pm
This attempt took 4 minutes.
 
Question 1
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers1[]={3, 9, 0, 2};
    int mynumbers2[]={6, 1, 4, 5};
    vector<int> v1(4);
    transform(mynumbers1, mynumbers1+4, mynumbers2, v1.rbegin(), plus<int>());//LINE
I
    for_each(v1.rbegin(), v1.rend(), printer);//LINE II
    return 0;
}

  
program outputs: 3, 9, 0, 2, 6, 1, 4, 5,
 

  
program outputs: 6, 9, 4, 5,
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 

  
program outputs: 4, 10, 1, 3, 7, 2, 5, 6 ,
 

  
program outputs: 9, 10, 4, 7,
 

  
compilation error in LINE I
 
 
Question 2
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    for_each(v1.begin(), v1.end(), bind2nd(plus<int>(), 1));//LINE I
    for_each(v1.rbegin(), v1.rend(), printer);//LINE II
    return 0;
}

  
runtime error at LINE II
 

  
runtime error at LINE I
 

  
program outputs: 5, 4, 1, 2, 0, 9, 3,
 

  
program outputs: 4, 10, 1, 3, 2, 5, 6,
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5,
 

  
compilation error in LINE I
 
 
Question 3
1 / 1 pts
What will happen when you attempt to compile and run the following code?
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    int counter = count_if(v1.begin(), v1.end(), bind1st(plus<int>(), 4));//LINE I
    v1.push_back(counter);//LINE II
    for_each(v1.rbegin(), v1.rend(), printer);
    return 0;
}

  
compilation error in LINE I
 

  
runtime error at LINE I
 

  
program outputs: 7, 5, 4, 1, 2, 0, 9, 3,
 

  
program outputs: 4, 10, 1, 3, 2, 5, 6,
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5,
 

  
program outputs: 0, 5, 4, 1, 2, 0, 9, 3,
 

  
runtime error at LINE II
 
 
Question 4
1 / 1 pts
What will happen when you attempt to compile and run the following code?
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    int counter = count_if(v1.begin(), v1.end(), bind1st(less_equal<int>(),
4));//LINE I
    v1.push_back(counter);//LINE II
    for_each(v1.rbegin(), v1.rend(), printer);
    return 0;
}

  
program outputs: 3, 5, 4, 1, 2, 0, 9, 3,
 

  
compilation error in LINE I
 

  
program outputs: 7, 5, 4, 1, 2, 0, 9, 3,
 

  
runtime error at LINE II
 

  
program outputs: 4, 5, 4, 1, 2, 0, 9, 3,
 

  
program outputs: 7, 3, 9, 0, 2, 1, 4, 5,
 

  
runtime error at LINE I
 
 
Question 5
1 / 1 pts
What will happen when you attempt to compile and run the following code?
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers1[] = {3, 9, 0, 2, 1, 4, 5};
    int mynumbers2[] = {9, 0, 2, 1, 4, 5, 3};
    vector<int> v1(mynumbers1, mynumbers1+7);
    vector<int> v2(mynumbers1, mynumbers1+7);
    vector<int> v3(mynumbers2, mynumbers2+7);//LINE I
    transform(v1.begin(), v1.end(), v2.rbegin(), v3.begin(), minus<int>());//LINE II
    for_each(v3.rbegin(), v3.rend(), printer);
    return 0;
}

  
runtime error at LINE II
 

  
runtime error at LINE I
 

  
program outputs: 6, -9, 2, -1, 3, 1, -2,
 

  
program outputs: 2, -5, 1, 0, -1, 5, -2,
 

  
program outputs: 2, 5, 1, 0, 1, 5, 2,
 

  
compilation error in LINE I
 
 
Question 6
1 / 1 pts
What will happen when you attempt to compile and run the following code?
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
struct Add : public binary_function<int, int, int> {//LINE I
    int operator()(const int & _Left, const int & _Right) const
    { return _Left+_Right;}
};
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    vector<int> v2(7);
    transform(v1.begin(), v1.end(), v2.begin(), bind1st(Add(), -1));//LINE II
    for_each(v2.rbegin(), v2.rend(), printer);
    return 0;
}

  
program outputs: 4, 10, 1, 3, 2, 5, 6,
 

  
program outputs: 4, 3, 0, 1, -1, 8, 2,
 

  
runtime error at LINE I
 

  
runtime error at LINE II
 

  
compilation error in LINE I
 

  
program outputs: 6, 5, 2, 3, 1, 10, 4,
 
 
Question 7
1 / 1 pts
What will happen when you attempt to compile and run the following code?
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
struct Add : public binary_function<int, int, int> {
    int operator()(int & _Left, const int & _Right) const//LINE I
    { return _Left+_Right;}
};
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    vector<int> v2(7);
    transform(v1.begin(), v1.end(), v2.begin(), bind1st(Add(), -1));//LINE II
    for_each(v2.rbegin(), v2.rend(), printer);
    return 0;
}

  
program outputs: 4, 3, 0, 1, -1, 8, 2,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
program outputs: 6, 5, 2, 3, 1, 10, 4,
 

  
runtime error at LINE II
 

  
program outputs: 4, 10, 1, 3, 2, 5, 6,
 
 
Question 8
1 / 1 pts
What will happen when you attempt to compile and run the following code?
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
struct Add : public binary_function<int, int, int> {
    int operator()(const int & _Left, const int & _Right) const//LINE I
    { return _Left+_Right;}
};
void printer(int i) {
    cout << i << ", ";
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    vector<int> v2(7);
    transform(v1.begin(), v1.end(), v2.begin(), bind1st(Add, -1));//LINE II
    for_each(v2.rbegin(), v2.rend(), printer);
    return 0;
}

  
compilation error in LINE I
 

  
runtime error at LINE II
 

  
program outputs: 4, 10, 1, 3, 2, 5, 6,
 

  
program outputs: 6, 5, 2, 3, 1, 10, 4,
 

  
program outputs: 4, 3, 0, 1, -1, 8, 2,
 

  
compilation error in LINE I
 
 
Question 9
1 / 1 pts
What will happen when you attempt to compile and run the following code?
#include <deque>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
struct MultiAdd : public binary_function<int, int, int> {
    int operator()(const int & _Left, const int & _Right) const
    { return 2*(_Left+_Right);}
};
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    deque<int> d1(mynumbers, mynumbers + 7);
    deque<int> d2(7);//LINE I
    transform(d1.begin(), d1.end(), d2.begin(), bind2nd(MultiAdd(), 1));//LINE II
    for_each(d2.begin(), d2.end(), printer);
    return 0;
}

  
runtime error at LINE II
 

  
program outputs: 5, 11, 2, 4, 3, 6, 7,
 

  
program outputs: 8, 20, 2, 6, 4, 10, 12,
 

  
program outputs: 12, 10, 4, 6, 2, 20, 8,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 
 
Question 10
1 / 1 pts
What will happen when you attempt to compile and run the following code?
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
struct Add {
    int operator()(const int & _Left, const int & _Right) const//LINE I
    { return _Left+_Right;}
};
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    vector<int> v2(7);
    transform(v1.begin(), v1.end(), v2.begin(), bind1st(ptr_fun (Add()), 1));//LINE
II
    for_each(v2.begin(), v2.end(), printer);
    return 0;
}

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
program outputs: 4, 10, 1, 3, 2, 5, 6,
 

  
program outputs: 6, 5, 2, 3, 1, 10, 4,
 

  
runtime error at LINE II
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5,
 
 
IncorrectQuestion 11
0 / 1 pts
What will happen when you attempt to compile and run the following code?
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int Mul(int & _Left)
{ return 2*_Left;}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    vector<int> v2(7);
    transform(v1.begin(), v1.end(), v2.begin(), ptr_fun(Mul));//LINE I
    vector<int>::iterator it = find_if(v2.begin(), v2.end(),
bind2nd(equal_to<int>(),7));//LINE II
    cout<<*it<<endl;//LINE III
    return 0;
}

  
program outputs: 3
 

  
runtime error at LINE II
 

  
runtime error at LINE III
 

  
program outputs: 6
 

  
program outputs: 0
 

  
compilation error in LINE I
 
 
Question 12
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int Mul(int & _Left)
{
    if (_Left<=3)
        return 2*_Left;
    else
        return 6;
}
int main() {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    vector<int> v2(7);
    transform(v1.begin(), v1.end(), v2.begin(), ptr_fun(Mul));//LINE I
    vector<int>::iterator it = find_if(v2.begin(), v2.end(),
bind2nd(equal_to<int>(),6));//LINE II
    cout<<*it<<endl;//LINE III
    return 0;
}

  
compilation error in LINE I
 

  
program outputs: 3
 

  
program outputs: 6
 

  
runtime error at LINE III
 

  
runtime error at LINE II
 

  
program outputs: 6 6
 

  
program outputs: 0
 
 
Question 13
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <functional>
#include <iostream>
#include <algorithm>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
    operator int() const
    { return value;    }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue(); //LINE I
    return stream;
}
void printer(Pocket i) {
    cout << i << ", ";
}
int main() {
    Pocket mynumbers1[] = {3, 9, 0, 2};
    Pocket mynumbers2[] = {2, 1, 4, 5};
    vector<Pocket> v1(5, 0);
    transform(mynumbers1, mynumbers1+4, mynumbers2, v1.rbegin(),
plus<Pocket>());//LINE II
    for_each(v1.rbegin(), v1.rend(), printer);
    return 0;
}

  
program outputs: 7, 4, 10, 5, 0
 

  
program outputs: 5, 10, 4, 7,
 

  
runtime error at LINE II
 

  
program outputs: 5, 10, 4, 7, 0
 

  
runtime error at LINE I
 

  
compilation error in LINE I
 
 
Question 14
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    operator int() const
    { return value;    }
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {//LINE I
    cout << i << ", ";
}
int main() {
    Pocket mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<Pocket> v1(mynumbers, mynumbers+7);
    transform(v1.begin(), v1.end(), v1.begin(), bind2nd(plus<Pocket>(), 1));//LINE II
    for_each(v1.rbegin(), v1.rend(), printer);
    return 0;
}

  
compilation error in LINE I
 
  
compilation error in LINE II
 

  
program outputs: 4, 10, 1, 3, 2, 5, 6,
 

  
runtime error at LINE II
 

  
program outputs: 6, 5, 2, 3, 1, 10, 4,
 

  
program outputs: 6, 5, 2, 3, 1, 10, 4, 0,
 
 
Question 15
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    operator int() const
    { return value;    }
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {//LINE I
    cout << i << ", ";
}
int main() {
    Pocket mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<Pocket> v1(mynumbers, mynumbers+7);
    for_each(v1.begin(), v1.end(), bind1st(plus<Pocket>(), 1));//LINE II
    for_each(v1.rbegin(), v1.rend(), printer);
    return 0;
}

  
program outputs: 6, 5, 2, 3, 1, 10, 4,
 

  
program outputs: 6, 5, 2, 3, 1, 10, 4, 0,
 

  
compilation error in LINE II
 

  
runtime error at LINE II
 

  
program outputs: 5, 4, 1, 2, 0, 9, 3,
 

  
compilation error in LINE I
 
 
Question 16
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    operator int() const
    { return value;    }
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {//LINE I
    cout << i << ", ";
}
int main() {
    Pocket mynumbers1[] = { 3, 9, 0, 2, 1, 4, 5 };
    Pocket mynumbers2[] = { 3, 8, 0, 1, 0, 2, 2 };
    vector<Pocket> v1(mynumbers1, mynumbers1+7);
    vector<Pocket> v2(mynumbers2, mynumbers2+7);
    vector<Pocket> v3(7, 0);
    transform(v1.begin(), v1.end(), v2.begin(), v3.begin(), minus<Pocket>());//LINE
II
    for_each(v1.rbegin(), v1.rend(), printer);
    return 0;
}

  
program outputs: 3, 2, 1, 1, 0, 1, 0,
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
program outputs: 5, 4, 1, 2, 0, 9, 3,
 

  
runtime error at LINE II
 

  
program outputs: 0, 1, 0, 1, 1, 2, 3,
 
 
Question 17
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    operator int() const
    { return value;    }
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {//LINE I
    cout << i << ", ";
}
int main() {
    Pocket mynumbers1[] = { 3, 9, 0, 2, 1, 4, 5 };
    Pocket mynumbers2[] = { 3, 8, 0, 1, 0, 2, 2 };
    vector<Pocket> v1(mynumbers1, mynumbers1+7);
    vector<Pocket> v2(mynumbers2, mynumbers2+7);
    vector<Pocket> v3(7, 0);
    transform(v1.begin(), v1.end(), v2.begin(), v3.begin(), minus<Pocket>());//LINE
II
    for_each(v3.rbegin(), v3.rend(), printer);
    return 0;
}

  
runtime error at LINE II
 

  
compilation error in LINE II
 

  
compilation error in LINE I
 

  
program outputs: 5, 4, 1, 2, 0, 9, 3,
 

  
program outputs: 3, 2, 1, 1, 0, 1, 0,
 

  
program outputs: 0, 1, 0, 1, 1, 2, 3,
 
 
Question 18
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    operator int() const
    { return value;    }
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {//LINE I
    cout << i << ", ";
}
struct Add : public binary_function<Pocket, Pocket, Pocket> {
    Pocket operator()(const Pocket &_Left, const Pocket &_Right) const
    { return _Left+_Right;   }
};
int main() {
    Pocket mynumbers1[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<Pocket> v1(mynumbers1, mynumbers1+7);
    vector<Pocket> v2(7, 0);
    transform(v1.begin(), v1.end(), v2.begin(), bind2nd(Add(),1));//LINE II
    for_each(v2.rbegin(), v2.rend(), printer);
    return 0;
}
  
compilation error in LINE II
 

  
runtime error at LINE II
 

  
compilation error in LINE I
 

  
program outputs: 6, 5, 2, 3, 1, 10, 4,
 

  
program outputs: 5, 4, 1, 2, 0, 9, 3,
 

  
program outputs: 6, 5, 2, 3, 1, 10, 4, 0,
 
 
Question 19
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    operator int() const
    { return value;    }
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {//LINE I
    cout << i << ", ";
}
template <typename T>
struct Add : public binary_function<T, T, T> {//LINE I
    T operator()(const T &_Left, const T &_Right) const
    { return _Left+_Right;   }
};
int main() {
    Pocket mynumbers1[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<Pocket> v1(mynumbers1, mynumbers1+7);
    vector<Pocket> v2(7, 0);
    transform(v1.begin(), v1.end(), v2.begin(), bind2nd(Add<Pocket>(),0));//LINE II
    for_each(v2.rbegin(), v2.rend(), printer);
    return 0;
}

  
program outputs: 5, 4, 1, 2, 0, 9, 3,
 

  
compilation error in LINE I
 

  
program outputs: 6, 5, 2, 3, 1, 10, 4,
 

  
compilation error in LINE II
 

  
program outputs: 6, 5, 2, 3, 1, 10, 4, 0,
 

  
runtime error at LINE II
 
 
Question 20
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    int getValue() const
    { return value; }  
    operator int() const
    { return value;    }
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(Pocket i) {//LINE I
    cout << i << ", ";
}
template <typename T>
struct Add : public binary_function<T, T, T> {//LINE I
    T operator()(const T &_Left, const T &_Right) const
    { return _Left+_Right;   }
};
int main() {
    Pocket mynumbers1[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<Pocket> v1(mynumbers1, mynumbers1+7);
    vector<Pocket> v2(7, 0);
    transform(v1.begin(), v1.end(), v2.begin(), bind1st(ptr_fun (Add<Pocket>()),
1));//LINE II
    for_each(v2.rbegin(), v2.rend(), printer);
    return 0;
}

  
program outputs: 6, 5, 2, 3, 1, 10, 4, 0,
 

  
compilation error in LINE II
 

  
program outputs: 5, 4, 1, 2, 0, 9, 3,
 

  
compilation error in LINE I
 
  
program outputs: 6, 5, 2, 3, 1, 10, 4,
 

Score for this attempt: 20.5 out of 26


Submitted Dec 31 at 3:25pm
This attempt took 7 minutes.
 
Question 1
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
int main()
{
    cout<<127<<", ";
    cout.setf(ios::hex);//LINE I
    cout<<127<<", ";
    cout.setf (ios::showbase );  //LINE II
    cout<<127<<", ";
    return 0;
}

  
program outputs: 127, 7f, 7f
 

  
runtime error at LINE II
 

  
program outputs: 127, 127, 127, (but it is an unpredictable result)
 

  
program outputs: 127, 0x7f, 0x7f
 

  
program outputs: 127, 7f, 0x7f
 

  
compilation error in LINE II
 
  
compilation error in LINE I
 
 
Question 2
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
int main()
{
    cout<<127<<", ";
    cout.setf(ios::hex);//LINE I
    cout<<127<<", ";
    cout.setf (ios::showbase, ios::basefield );  //LINE II
    cout<<127<<", ";
    return 0;
}

  
runtime error at LINE II
 

  
compilation error in LINE I
 

  
program outputs: 127, 7f, 7f
 

  
program outputs: 127, 127, 127, (but it is an unpredictable result)
 

  
program outputs: 127, 0x7f, 0x7f
 

  
program outputs: 127, 7f, 0x7f
 

  
compilation error in LINE II
 
 
Question 3
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
int main()
{
    cout<<127<<", ";
    cout.setf(ios::hex, ios::basefield);//LINE I
    cout<<127<<", ";
    cout.setf (ios::showbase);  //LINE II
    cout<<127<<", ";
    return 0;
}

  
runtime error at LINE II
 

  
program outputs: 127, 127, 127,
 

  
program outputs: 127, 7f, 7f
 

  
compilation error in LINE I
 

  
program outputs: 127, 7f, 0x7f
 

  
compilation error in LINE II
 

  
program outputs: 127, 0x7f, 0x7f
 
 
Question 4
1 / 1 pts
What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
    cout<<127<<", ";
    cout.setf(ios::hex, ios::basefield);
    cout.setf (ios::showbase);  //LINE I
    cout<<127<<", ";
    cout.unsetf(ios::showbase);  //LINE II
    cout<<127<<", ";
    return 0;
}

  
runtime error in LINE I
 

  
program outputs: 127, 127, 127,
 

  
program outputs: 127, 7f, 0x7f
 

  
program outputs: 127, 0x7f, 7f
 

  
program outputs: 127, 0x7f, 0x7f
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 
 
Question 5
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
int main()
{
cout<<127<<", ";
cout.setf(ios::oct, ios::basefield);
cout.setf (ios::showbase); //LINE I
cout<<127<<", ";
cout.unsetf(ios::showbase); //LINE II
cout<<127<<", ";
return 0;
}

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
program outputs: 127, 127, 127,
 

  
program outputs: 127, 0x177, 177
 

  
program outputs: 127, 0177, 0177
 

  
runtime error at LINE II
 

  
program outputs: 127, 0177, 177
 
 
Question 6
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
int main()
{
    cout<<127.45<<", ";
    cout.setf(ios::hex, ios::basefield);
    cout.setf (ios::showbase);  //LINE I
    cout<<127.45<<", ";
    cout.unsetf(ios::showbase);  //LINE II
    cout<<127.45<<", ";
    return 0;
}

  
program outputs: 127.45, 0x7f, 7f
 

  
runtime error at LINE I
 

  
program outputs: 127.45, 0x7f.2d, 0x7f.2d
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
program outputs: 127.45, 0x7f.2d, 7f.2d
 

  
program outputs: 127.45, 127.45, 127.45,
 
 
Question 7
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
int main()
{
    cout<<127.45<<", ";
    cout.setf(ios::hex, ios::basefield);
    cout.setf (ios::showbase);  //LINE I
    cout<<127.45<<", ";
    cout.setf(ios::noshowbase);  //LINE II
    cout<<127.45<<", ";
    return 0;
}

  
runtime error at LINE II
 

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
program outputs: 127.45, 127.45, 127.45,
 

  
program outputs: 127.45, 0x7f.2d, 7f.2d
 

  
program outputs: 127.45, 0x7f, 7f
 

  
program outputs: 127.45, 0x7f.2d, 0x7f.2d
 
 
Question 8
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
int main()
{
    cout<<127<<", ";
    cout.setf(ios::hex, ios::basefield);
    cout.setf (ios::showbase);  //LINE I
    cout<<127<<", ";
    cout.unsetf(ios::showbase);  
    cout<<std::showbase<<127<<", ";//LINE II
    return 0;
}

  
program outputs: 127, 0x7f, 07f,
 

  
program outputs: 127, 0x7f, 7f,
 

  
runtime error at LINE I
 

  
compilation error in LINE II
 

  
program outputs: 127, 0x7f, 0x7f,
 

  
program outputs: 127, 0x7f, 87f,
 

  
compilation error in LINE I
 
 
Question 9
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
int main()
{
    cout<<false<<", "; //LINE I
    cout<<boolalpha<<", ";//LINE II
    cout<<true<<", ";
    return 0;
}
  
program outputs: 0, 0, true,
 

  
program outputs: 1, 0, 0,
 

  
program outputs: 0, 0, 1,
 

  
runtime error at LINE II
 

  
compilation error in LINE I
 

  
program outputs: 0, , true,
 

  
compilation error in LINE II
 
 
Question 10
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
int main()
{
    double goodpi=3.1415;
    double badpi = 3.2;
    cout<<goodpi<<", ";
    cout<<badpi<<", ";
    cout.setf(ios_base::showpoint);//LINE I
    cout<<goodpi<<", "; //LINE II
    cout<<badpi<<", ";
    return 0;
}

  
compilation error in LINE II
 

  
program outputs: 3.1415, 3.2, 3.14, 3.20
 

  
runtime error at LINE II
 

  
compilation error in LINE I
 

  
program outputs: 3.1415, 3.2, 3.14150, 3.20000,
 

  
program outputs: 3, 3, 3.1415, 3.2
 

  
program outputs: 3, 3, 3.14, 3.20
 
 
Question 11
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iomanip>
#include <iostream>
using namespace std;
int main()
{
    double goodpi=3.1415;
    double badpi = 3.2;
    cout<<goodpi<<", ";
    cout<<badpi<<", ";
    cout<<setprecision(3);//LINE I
    cout<<goodpi<<", "; //LINE II
    cout<<badpi<<", ";
    return 0;
}

  
compilation error in LINE I
 
  
program outputs: 3.1415, 3.2, 3.14, 3.2,
 

  
program outputs: 3.1415, 3.2, 3.14, 3.20,
 

  
compilation error in LINE II
 

  
runtime error at LINE II
 

  
program outputs: 3.1415, 3.2, 3.1, 3.2,
 

  
program outputs: 3.1415, 3.2, 3.1415, 3.20,
 
 
Question 12
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iomanip>
#include <iostream>
using namespace std;
int main()
{
    double goodpi=3.1415;
    double badpi = 3.2;
    cout<<goodpi<<", ";
    cout<<badpi<<", ";
    cout<<setprecision();//LINE I
    cout<<goodpi<<", "; //LINE II
    cout<<badpi<<", ";
    return 0;
}

  
compilation error in LINE II
 

  
program outputs: 3.1415, 3.2, 3.14, 3.2,
 

  
program outputs: 3.1415, 3.2, 3.1415, 3.20,
 

  
compilation error in LINE I
 

  
program outputs: 3.1415, 3.2, 3.1, 3.2,
 

  
program outputs: 3.1415, 3.2, 3.14, 3.20,
 

  
runtime error at LINE II
 
 
Question 13
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iomanip>
#include <iostream>
using namespace std;
int main()
{
    double goodpi=3.1415;
    double badpi = 3.2;
    cout<<goodpi<<", ";
    cout<<fixed;
    cout<<badpi<<", ";
    cout<<setprecision(3);//LINE I
    cout<<goodpi<<", "; //LINE II
    cout.unsetf(ios::floatfield);
    cout<<badpi<<", ";
    return 0;
}

  
runtime error at LINE II
 

  
compilation error in LINE I
 

  
program outputs: 3.1415, 3.200000, 3.14, 3.200,
 

  
compilation error in LINE II
 

  
program outputs: 3.1415, 3.200000, 3.142, 3.20,
 

  
program outputs: 3.1415, 3.200000, 3.142, 3.200,
 

  
program outputs: 3.1415, 3.200000, 3.142, 3.2,
 
 
Question 14
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iomanip>
#include <iostream>
using namespace std;
int main()
{
    double goodpi=3.1415;
    double badpi = 3.2;
    cout<<goodpi<<", ";
    cout<<scientific;//LINE I
    cout<<setprecision(3);//LINE II
    cout<<goodpi<<", ";
    cout.unsetf(ios::floatfield);
    cout<<badpi<<", ";
    return 0;
}

  
compilation error in LINE II
 

  
program outputs: 3.1415, 3.142e+00, 3.20,
 

  
program outputs: 3.1415, 3.1415, 3.2,
 

  
compilation error in LINE I
 

  
program outputs: 3.1415, 3.142e+000, 3.200,
 

  
program outputs: 3.1415, 3.142e+00, 3.2,
 

  
runtime error at LINE II
 
 
Question 15
1 / 1 pts
What will happen when you attempt to compile and run the following code, assuming
you enter the following sequence: 9 8 7<enter> ?

#include <iostream>
using namespace std;
int main ()
{
    int c1, c2, c3;
    cin >> c1 >> c2 >> c3;
    cout << c3 << ", " << c1 << ", " << c2 << ", " << endl;
    return 0;
}

  
program outputs: 7, 9, 8,
 

  
program outputs: 8, 9, 7
 

  
program outputs: 8, 7, 9,
 
  
program outputs: 7, 8, 9,
 
 
IncorrectQuestion 16
0 / 1 pts
What will happen when you attempt to compile and run the following code, assuming
that you will enter the following sequence: 9 8 7<enter>?

#include <iostream>
#include <string>
using namespace std;
int main ()
{
    string s;
    cin >> s; //LINE I
    cout << s << ", " << s << ", " << endl; //LINE II
    return 0;
}

  
program outputs: 9,
 

  
program outputs: 9, 9,
 

  
compilation error in LINE II
 

  
compilation error in LINE I
 

  
program outputs: 9, 8,
 

  
runtime error at LINE II
 

  
program outputs: 8, 7,
 
 
IncorrectQuestion 17
0 / 1 pts
What will happen when you attempt to compile and run the following code, assuming
that you will enter the following sequence: 9 8 a<enter>??

#include <iostream>
#include <string>
using namespace std;
int main ()
{
    string s;
    getline(cin, s); //LINE I
    cout << s << ", " << s << ", " << endl; //LINE II
    return 0;
}

  
program outputs: 9, 9,
 

  
runtime error at LINE II
 

  
program outputs: 9,
 

  
compilation error in LINE II
 

  
program outputs: 9, 8,
 

  
compilation error in LINE I
 

  
program outputs: 9 8 a, 9 8 a,
 
 
Question 18
1 / 1 pts
What will happen when you attempt to compile and run the following code, assuming
that you will enter the following sequence: 7 8 9<enter>?

#include <iostream>
#include <string>
using namespace std;
int main ()
{
    string s;
    getline(s); //LINE I
    cout << s << ", " << s << ", " << endl; //LINE II
    return 0;
}

  
compilation error in LINE II
 

  
runtime error at LINE II
 

  
program outputs: 9 8 a, 9 8 a,
 

  
program outputs: 9,
 

  
program outputs:
 

  
compilation error in LINE I
 

  
program outputs: 9, 9,
 
 
Question 19
1 / 1 pts
What will happen when you attempt to compile and run the following code, assuming
that you will enter the following sequence: 9.9 8.8 7.7<enter>?
#include <iostream>
using namespace std;
int main ()
{
    double c1, c2, c3;
    cin >> c1 >> c2 >> c3;
    cout << c3 << ", " << c1 << ", " << c2 << ", " << endl;
    return 0;
}

  
program outputs: 7.7, 9.9, 8.8,
 

  
program outputs: 7, 9, 8,
 

  
program outputs: 7.7, 8.8, 9.9,
 

  
program outputs: 7, 8, 9
 
 
Question 20
1 / 1 pts
What will happen when you attempt to compile and run the following code, assuming
that you will enter the following sequence: true false 1<enter>?

#include <iostream>
using namespace std;
int main ()
{
    bool c1, c2, c3;
    cin >> boolalpha >> c1 >> c2 >> c3;
    cout << boolalpha << c3 << ", " << c1 << ", " << c2 << ", " << endl;//LINE I
    return 0;
}

  
program outputs: true, true, false (but the c3 value is undefined)
 

  
program outputs: true, false, true (but the c3 value is undefined)
 
  
program outputs: true, false, false (but the c3 value is undefined)
 

  
runtime error at LINE I
 

  
compilation error in LINE I
 

  
program outputs: true, 1, false (but the c3 value is undefined)
 
 
IncorrectQuestion 21
0 / 1 pts
What will happen when you attempt to compile and run the following code, assuming
that you will enter the following sequence: r e w qw q<enter>?

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
void printer(string i) {
    cout << i << ", ";
}
int main ()
{
    vector<string> v1;
    string s;
    do
    {
        cin >> s;
        v1.push_back(s);//LINE I
    }
    while (s != "q" && cin.good());//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
program outputs: r, e, w, q,
 

  
runtime error at LINE II
 

  
program outputs: r, e, w, w, q,
 

  
compilation error in LINE II
 

  
compilation error in LINE I
 

  
program outputs: r, e, w, w
 

  
program outputs: r, e, w, qw, q,
 
 
Question 22
1 / 1 pts
What will happen when you attempt to compile and run the following code, assuming
that you will enter the following sequence: 7 8 9<enter>?

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main ()
{
    vector<int> v1;
    int i;
    do
    {
        cin >> i;
        v1.push_back(i);//LINE I
    }
    while (i != 9 && !cin.bad());//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}
  
program outputs: 7, 8, 9,
 

  
program runs forever without output
 

  
program outputs: 7, 8, 9, 9,
 

  
compilation error in LINE I
 

  
program outputs: 7, 8,
 

  
runtime error at LINE II
 

  
compilation error in LINE II
 
 
IncorrectQuestion 23
0 / 1 pts
What will happen when you attempt to compile and run the following code, assuming
that you will enter the following sequence: 255 127<enter>?

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <sstream>
using namespace std;
void printer(int i) {
    cout << setw(4) << i << ", ";
}
int main ()
{
    string s;
    getline(cin, s);
    stringstream input(s);//LINE I
    vector<int> v1;
    int i;
    do
    {
        input >> hex >> i;
        v1.push_back(i);//LINE II
    }
    while (!input.fail());
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
compilation error in LINE II
 

  
runtime error at LINE II
 

  
program outputs: 255, 127, 127,
 

  
program runs forever without output
 

  
program outputs: 597, 295,
 

  
program outputs: ff, 7f, 7f,
 

  
program outputs: 597, 295, 295,
 

  
compilation error in LINE I
 

  
program outputs: 255, 127,
 
 
IncorrectQuestion 24
0 / 1 pts
What will happen when you attempt to compile and run the following code, assuming
that the file input.txt contains the following sequence: t r e?
Note: spaces are important.

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <fstream>
using namespace std;
void printer(char c) {
    cout << setw(2) << c << ", ";
}
int main ()
{
    ifstream inputfile("input.txt");
    vector<char> v1;
    char c;
    do
    {
        inputfile>>c;//LINE I
        v1.push_back(c);
    }
    while (inputfile.good());//LINE II
    inputfile.close();
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}

  
runtime error at LINE I
 

  
compilation error in LINE I
 

  
program outputs: t, r, e, e, (two spaces after commas)
 

  
program runs forever without output
 

  
program outputs:t, r, e, (one space after commas)
 

  
compilation error in LINE II
 

  
program outputs: t, r, e, (two spaces after commas)
 

  
program outputs:t, r, e, e, (one space after commas)
 
 
Question 25
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <fstream>
using namespace std;
void printer(int i) {
    cout << setw(2) << i << ", ";
}
int main ()
{
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    fstream outfile("output.txt", ios::trunc|ios::out);
    int i ;
    while (outfile.good());//LINE I
    {
        outfile>>i;//LINE II
        v1.push_back(i);
    }
    outfile.close();
    for_each(v1.begin(), v1.end(), printer);
    outfile.close();   outfile.open("output.txt");
    return 0;
}

  
runtime error at LINE II
 

  
no file will be created or opened
 

  
compilation error in LINE I
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5, 0, 6,
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5,
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5, 0,
 

  
program runs forever without output
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5, 6,
 
 
PartialQuestion 26
0.5 / 1 pts
What will happen when you attempt to compile and run the following code? Choose all
that apply.

#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    operator int() const
    {return getValue();}//LINE I
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(int i) {
    cout << i << ", ";
}
int main () {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<Pocket> v1(mynumbers, mynumbers + 7);
    fstream outfile("output.txt", ios::trunc|ios::out);
    for_each(v1.begin(), v1.end(), printer);
    outfile.close();
    outfile.open("output.txt");
    while( outfile.good())   //LINE II
    {
        int i;
        outfile>>i;
    }
    outfile.close();
    return 0;
}

  
program outputs: 3, 9, 0, 2, 1, 4, 5, 6,
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5,
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5, 0,
 

  
program runs forever without output
 

  
compilation error in LINE I
 

  
program outputs: 3, 9, 0, 2, 1, 4, 5, 6, 0,
 

  
file output.txt will be opened for writing
 

Score for this attempt: 21 out of 22


Submitted Dec 31 at 3:30pm
This attempt took 4 minutes.
 
Question 1
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
template<class T>
void f(T &a)//LINE I
{
    cout << 1 + a << endl;
}
int main()
{
    int a = 1;
    f(a);//LINE II
    return 0;
}

  
compilation error in LINE II
 

  
program outputs: 3
 

  
program outputs: 2
 

  
compilation error in LINE I
 

  
runtime error at LINE II
 

  
program outputs: 1
 
 
Question 2
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
template<class T>
void f(T &a)//LINE I
{
    cout << 1 + a << endl;
}
void f(double &a)//LINE II
{
    cout << 2 + a << endl;
}
int main()
{
    int a = 1.5;
    f(a);//LINE II
    return 0;
}

  
program outputs: 3.5
 

  
program outputs: 2
 

  
compilation error in LINE I
 

  
runtime error at LINE II
 

  
compilation error in LINE II
 

  
program outputs: 2.5
 
 
Question 3
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
template<class T>
void f(T &a)//LINE I
{
    cout << 1 + a << endl;
}
void f(double &a)//LINE II
{
    cout << 2 + a << endl;
}
int main()
{
    double a = 1.5;
    f(a);//LINE II
    return 0;
}

  
program outputs: 3.5
 

  
compilation error in LINE I
 

  
program outputs: 2
 

  
compilation error in LINE II
 

  
program outputs: 2.5
 

  
runtime error at LINE II
 
 
Question 4
1 / 1 pts
What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
template<class T>
void f(T &a)//LINE I
{
    cout << 1 + a << endl;
}
void f(double &a)
{
    cout << 2 + a << endl;
}
int main()
{
    double a = 1.5;
    f<float &>(a);//LINE II
    return 0;
}

  
runtime error at LINE II
 

  
compilation error in LINE II
 

  
compilation error in LINE I
 

  
program outputs: 2.5
 

  
program outputs: 2
 

  
program outputs: 3.5
 
 
Question 5
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
template<class A>
void f(A &a)//LINE I
{
    cout << 1 + a << endl;
}
void f(double &a)//LINE II
{
    cout << 2 + a << endl;
}
int main()
{
    float a = 1.5;
    f<float &>(a);//LINE II
    return 0;
}

  
program outputs: 3.5
 

  
program outputs: 2
 

  
compilation error in LINE II
 

  
runtime error at LINE II
 

  
compilation error in LINE I
 

  
program outputs: 2.5
 
 
Question 6
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
template <class T>
class Pocket {
    T    value;//LINE I
public:
    Pocket(T value):value(value) {}
};
int main()
{
    Pocket<double> a(7);
    cout << a.value << endl;//LINE II
    return 0;
}

  
program outputs: 0
 

  
program outputs: 7
 

  
compilation error in LINE I
 

  
runtime error at LINE II
 

  
compilation error in LINE II
 

  
program outputs: 7.0
 
 
Question 7
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
template <class T>
class Pocket {
public:
    T    value;//LINE I
    Pocket(T value):value(value) {}
};
int main()
{
    Pocket<double> a(7);
    cout << a.value << endl;//LINE II
    return 0;
}

  
compilation error in LINE II
 

  
program outputs: 7.0
 

  
runtime error at LINE II
 

  
compilation error in LINE I
 

  
program outputs: 7
 

  
program outputs: 0
 
 
Question 8
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
template <class T>
class Pocket {
public:
    T    value;
    Pocket(T value);
};
template<class T>
Pocket::Pocket(T value):value(value) {}//LINE I
int main()
{
    Pocket<double> a(7);//LINE II
    cout << a.value << endl;
    return 0;
}

  
program outputs: 7
 

  
runtime error at LINE II
 

  
compilation error in LINE II
 

  
program outputs: 7.0
 

  
program outputs: 0
 

  
compilation error in LINE I
 
 
Question 9
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
template <class T>
class Pocket {
public:
    T    value;
    Pocket(T value);
};
template<class T>
Pocket<T>::Pocket(T value):value(value) {}//LINE I
int main()
{
    Pocket<double> a(7);//LINE II
    cout << a.value << endl;
    return 0;
}
  
compilation error in LINE II
 

  
compilation error in LINE I
 

  
program outputs: 0
 

  
runtime error at LINE II
 

  
program outputs: 7
 

  
program outputs: 7.0000
 
 
Question 10
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
template <typedef T>//LINE I
class Pocket {
public:
    T    value;
    Pocket(T value);
};
template<class T>
Pocket<T>::Pocket(T value):value(value) {}//LINE II
int main()
{
    Pocket<double> a(7);
    cout << a.value << endl;
    return 0;
}

  
runtime error at LINE II
 
  
compilation error in LINE II
 

  
program outputs: 0
 

  
program outputs: 7.0000
 

  
program outputs: 7
 

  
compilation error, the reason is in LINE I
 
 
Question 11
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
template <typename T>//LINE I
class Pocket {
public:
    T    value;
    Pocket(T value);
};
template<class T>
Pocket<T>::Pocket(T value):value(value) {}//LINE II
int main()
{
    Pocket<double> a(7);
    cout << a.value << endl;
    return 0;
}

  
program outputs:7.0000
 

  
program outputs: 7
 
  
runtime error at LINE II
 

  
program outputs: 0
 

  
compilation error in LINE II
 

  
compilation error, the reason is in LINE I
 
 
Question 12
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
class NothingSpecial {};
template <typename T>
class Pocket {
    T    value;//LINE I
public:
    Pocket() {}
    Pocket(T value);
    T getValue() { return value; }
    void add(T _Right) { value += _Right; }
};
template<class T>
Pocket<T>::Pocket(T value):value(value) {}
int main()
{
    Pocket<double> a(7);
    Pocket<NothingSpecial> n;//LINE II
    a.add(3) ;
    cout << a.getValue() << ", ";
    a.add(3) ;
    cout << a.getValue();
    return 0;
}

  
compilation error in LINE I
 
  
program outputs: 10, 10
 

  
compilation error in LINE II
 

  
runtime error at LINE II
 

  
program outputs: 10, 13
 

  
program outputs: 7, 7
 
 
Question 13
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
class SomethingSpecial {};
template <typename T>
class Pocket {
    T    value;
public:
    Pocket() {}
    Pocket(T value);
    T getValue() { return value; }
    void add(T _Right) { value += _Right; }
};
template<class T>
Pocket<T>::Pocket(T value):value(value) {}
int main()
{
    Pocket<double> a(7);//LINE I
    Pocket<SomethingSpecial> n;
    n.add(SomethingSpecial()) ;//LINE II
    cout << a.getValue() << ", ";
    a.add(3) ;
    cout << a.getValue();
    return 0;
}
  
program outputs: 7, 10
 

  
runtime error at LINE II
 

  
program outputs: 10, 13
 

  
compilation error, the reason is in LINE II
 

  
compilation error, the reason is in LINE I
 

  
program outputs: 7, 7
 
 
Question 14
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
class SomethingSpecial {
public:
    double value;
    SomethingSpecial():value(0){}
    SomethingSpecial(double value): value(value){}
    SomethingSpecial operator+=(SomethingSpecial & _Right) {
        SomethingSpecial result;
        result.value = value + _Right.value;
        return result;
    }
};
template <typename T>
class Pocket {
    T    value;
public:
    Pocket() {}
    Pocket(T value);
    T getValue() { return value; }
    void add(T _Right) { value += _Right; }
};
template<class T>
Pocket<T>::Pocket(T value):value(value) {}
int main()
{
    Pocket<double> a(7);//LINE I
    Pocket<SomethingSpecial> n;
    n.add(SomethingSpecial()) ;//LINE II
    cout << a.getValue() << ", ";
    a.add(3) ;
    cout << a.getValue();
    return 0;
}

  
program outputs: 10, 13
 

  
runtime error at LINE II
 

  
program outputs: 7, 10
 

  
compilation error, the reason is in LINE I
 

  
compilation error, the reason is in LINE II
 

  
program outputs: 7, 7
 
 
IncorrectQuestion 15
0 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <string>
using namespace std;
template <class T>
class Pocket {
    T    _v;
public:
    Pocket() {}
    Pocket(T v): _v(v){}
    T getV() { return _v; }
    void add(T & a) { _v+=a; }
};
int main()
{
    Pocket<string>    a("Hello");
    string s(" world!");
    a.add(s);
    cout << a.getV() <<endl;
    return 0;
}

  
program will not compile
 

  
program will display: Hello
 

  
program will run without any output
 

  
program will display: Hello world!
 
 
Question 16
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <string>
using namespace std;
template <typename T>
class Pocket {
    T    value;
public:
    Pocket() {}
    Pocket(T value);
    T getValue() { return value; }
    void add(T _Right) { value += _Right; }
};
template<class T>
Pocket<T>::Pocket(T value):value(value) {}
int main()
{
    Pocket<string> a("Hi");
    string n("Maker");
    a.add(n) ;//LINE I
    cout << a.getValue() << ", ";
    a.add(3) ;//LINE II
    cout << a.getValue();
    return 0;
}

  
runtime error at LINE II
 

  
compilation error in LINE II
 

  
program outputs: HiMaker, HiMaker
 

  
program outputs: HiMaker,
 

  
compilation error in LINE I
 

  
program outputs: Hi, Maker
 
 
Question 17
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <string>
using namespace std;
template <typename T>
class Pocket {
    T    value;
public:
    Pocket() {}
    Pocket(T value);
    T getValue() { return value; }
    void add(T _Right) { value += _Right; }
};
template<class T>
Pocket<T>::Pocket(T value):value(value) {}
int main()
{
    Pocket<string> a("Hi");
    string n("Maker");
    a.add(n) ;//LINE I
    cout << a.getValue() << ", ";//LINE II
    cout << a.getValue();
    return 0;
}

  
program outputs: Hi, Maker
 

  
program outputs: HiMaker,
 

  
runtime error at LINE II
 

  
program outputs: HiMaker, HiMaker
 

  
compilation error in LINE II
 

  
compilation error in LINE I
 
 
Question 18
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <string>
using namespace std;
template <typename T>
class Pocket {
    T    value;
public:
    Pocket() {}
    Pocket(T value);
    T getValue() { return value; }
    void add(T _Right) { value += _Right; }
    void add(string & _Right){value.insert(0, _Right);}
};
template<class T>
Pocket<T>::Pocket(T value):value(value) {}
int main()
{
    Pocket<string> a("Hi");
    string n("Tech");
    a.add(n) ;//LINE I
    cout << a.getValue() << ", ";//LINE II
    cout << a.getValue();
    return 0;
}

  
compilation error in LINE I
 

  
program outputs: HiTech, HiTech
 

  
program outputs: HiTech,
 

  
program outputs: Hi, Tech
 

  
compilation error in LINE II
 

  
runtime error at LINE I
 
 
Question 19
1 / 1 pts
What will happen when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
template <typename T>
class Pocket {
    T    value;
public:
    Pocket() {}
    Pocket(T value);
    T getValue() { return value; }
    void add(T _Right) { value += _Right; }
    friend ostream & operator<<(ostream & _os, const Pocket<T> & value) {
        _os<<value.value;    
        return _os;
    }
};
template<class T>
Pocket<T>::Pocket(T value):value(value) {}
int main()
{
    Pocket<string> a("Hi");
    string n("Tech");
    a.add(n) ;//LINE I
    cout << a << ", ";//LINE II
    cout << a;
    return 0;
}

  
compilation error in LINE I
 

  
compilation error in LINE II
 

  
program outputs: HiTech, HiTech
 

  
program outputs: Hi, Tech
 

  
runtime error at LINE II
 

  
program outputs: HiTech,
 
 
Question 20
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <string>
using namespace std;
template <class Ty>
class Pocket {
    Ty    value;
public:
    Pocket() {}
    Pocket(Ty value);
    Ty getValue() { return value; }
    void add(Ty _Right) { value += _Right; }
    template <class Tx>
        Tx get(Tx _Right) {
            return (Tx)(value) + _Right;//LINE I
        }
    friend ostream & operator<<(ostream & _os, const Pocket<Ty> & value) {
        _os<<value.value;    
        return _os;
    }
};
template<class T>
Pocket<T>::Pocket(T value):value(value) {}
int main()
{
    Pocket<string> a("Hi");
    string n("Tech");
    a.add(n) ;//LINE II
    cout << a << ", ";
    cout << a.get<double>(1);
    return 0;
}

  
program outputs: Hi, Tech
 

  
runtime error at LINE II
 

  
compilation error in LINE I
 
  
program outputs: HiTech,
 

  
program outputs: HiTech, HiTech
 

  
compilation error in LINE II
 
 
Question 21
1 / 1 pts
What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <string>
using namespace std;
template <class Ty>
class Pocket {
    Ty    value;
public:
    Pocket() {}
    Pocket(Ty value);
    Ty getValue() { return value; }
    void add(Ty _Right) { value += _Right; }
    template <class Tx>
        Tx get(Tx _Right) {
            return (Tx)(value) + _Right;//LINE I
        }
    friend ostream & operator<<(ostream & _os, const Pocket<Ty> & value) {
        _os<<value.value;    
        return _os;
    }
};
template<class T>
Pocket<T>::Pocket(T value):value(value) {}
int main()
{
    Pocket<int> a(7);
    cout << a << ", ";
    cout << a.get<double>(2);
    return 0;
}

  
compilation error in LINE I
 
  
program outputs: 7, 2
 

  
runtime error at LINE II
 

  
program outputs: 7,
 

  
program outputs: 7, 9
 

  
compilation error in LINE II
 
 
Question 22
1 / 1 pts
Which construction/keyword can be used to define the template type parameters?
Choose all the correct answers.

template<static T>
Pocket<T>::Pocket(T v):_v(v) {}
template<typedef T>
Pocket<T>::Pocket(T v):_v(v) {}
template<typename T>
Pocket<T>::Pocket(T v):_v(v) {}
template<class T>
Pocket<T>::Pocket(T v):_v(v) {}
template<volatile T>
Pocket<T>::Pocket(T v):_v(v) {}

  
with the static keyword
 

  
with the class keyword
 

  
with the typename keyword
 
  
with the volatile keyword
 

  
with the typedef keyword
 

  
none of the above
 

You might also like