Question: 1
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main()
{
cout<return 0;
}
Program outputs:
Question: 2
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
templatestruct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator()(const T & val ) { out<};
struct Sequence {
int start;
Sequence(int start):start(start){}
int operator()() { return start++; }
};
struct Odd { bool operator()(int v) { return v%2==0; } };
int main() {
vector v1(10);
vector v2(10);
generate(v1.begin(), v1.end(), Sequence(1));
stable_partition(v1.begin(),v1.end(), Odd());
for_each(v1.begin(), v1.end(), Out(cout) );cout<return 0;
}
Program outputs:
Question: 3
What happens when you attempt to compile and run the following code?
#include
#include
#include
using namespace std;
templatestruct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator()(const T & val ) { out<};
struct Sequence {
int start;
Sequence(int start):start(start){}
int operator()() { return start++; }
};
struct Odd { bool operator()(int v) { return v%2==0; } };
int main() {
vector v1(10);
vector v2(10);
generate(v1.begin(), v1.end(), Sequence(1));
stable_partition(v1.begin(),v1.end(), Odd());
for_each(v1.begin(), v1.end(), Out(cout) );cout<return 0;
}
Program outputs:
Question: 4
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;
}
Question: 5
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;
}