Question: 1
What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
#include
using namespace std;
int main()
{
deque mydeck;list mylist; vector myvector;
queue first; queue second(mydeck);
queue third(second); queue > fourth(mylist);
fourth.push(10);fourth.push(11);fourth.push(12);
queue > fifth(myvector);
fifth.push(10);fifth.push(11);fifth.push(12); // Line I
while(!fifth.empty())
{
cout<fifth.pop(); // Line III
}
while (!fourth.empty())
{
cout << fourth.front() << " ";
fourth.pop(); // Line IV
}
return 0;
}
Question: 2
Which are NOT valid instantiations of priority_queue object:
#include
#include
#include
#include
#include
using namespace std;
int main()
{
deque mydeck;list mylist; vector myvector;
priority_queue first;//line I
priority_queue > second;//line II
priority_queue third(first);//line III
priority_queue > fourth(third);//line IV
priority_queue > fifth(myvector.begin(), myvector.end());//line V
return 0;
}
Question: 3
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
template void print(T start, T end) {
while (start != end) {
std::cout << *start << " "; start++;
}
}
int main(){
vectorv;
multiset s;
for(int i=10; i>0; i??) {
v.push_back(i); s.push_back(i);
}
print(v.begin(), v.end()); print(s.begin(), s.end());cout<return 0;
}
Question: 4
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
int main() {
int t[] = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
string s[] = { "one", "one", "two", "two", "three","three", "four", "four", "five", "five"};
map m;
for (int i = 0; i < 10; i++) {
m.push_back(pair(t[i], s[i]));
}
for (map::iterator i = m.begin(); i != m.end(); i++) {
cout << i?>first << " ";
}
return 0;
}
Question: 5
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
int main(){
int second[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 10 };
string first[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight"," ten"};
map m;
for(int i=0; i<10; i++) {
m.insert(pair(second[i],first[i]));
}
if (m[11] == "eleven") {
cout<<"eleven ";
}
for(map::iterator i=m.begin();i!= m.end(); i++) {
cout<second<<" ";
}
cout<return 0;
}