What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
#include
using namespace std;
int main()
{
deque
queue
queue
fourth.push(10);fourth.push(11);fourth.push(12);
queue
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; }
Answer : D
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
class A
{
int a;
public:
A():a(0){} A(int a){ this?>a = a;}
void setA(int a) {this?>a = a;}
int getA() {return a;}
};
ostream &operator<<(ostream & cout, A & a)
{
cout<< a.getA();
return cout;
}
int main ()
{
vectorv(5, new A());
v.push_back(new A(1));
vector::iterator it;
for(it = v.begin(); it != v.end(); it++)
{
cout<<*it<<" ";
}
cout< return 0; }
Answer : E
What happens when you attempt to compile and run the following code?
#include
#include
#include
#include
using namespace std;
class B { int val;
public:
B(int v):val(v){} B(){}
int getV() const {return val;} bool operator > (const B & v) const { return val>v.val;} };
ostream & operator <<(ostream & out, const B & v) { out< template ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out< int main() { int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3}; deque d1(t, t+10); sort(d1.begin(), d1.end(), greater()); deque::iterator it = lower_bound(d1.begin(), d1.end(), 4,greater()); for_each(it, d1.end(), Out(cout));cout< return 0; } Program outputs:
Answer : A
What happens when you attempt to compile and run the following code?
#include
#include
int main ()
{
std::vector
for(int i = 0; i<10; i++) {v1.push_back(i); }
std::vector
std::vector
for( ; it != v2.end(); it++) {std::cout<<*it++<<" "; }std::cout< return 0; }
Answer : D
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
for (int i = 0; i < 10; i++) {
m.insert(pair
}
if (m.count(3) == 2) {
m.erase(3);
}
for (map
cout << i?>first << " ";
}
return 0;
}
Answer : A
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
template
void print(T start, T end) {
while (start != end) {
std::cout << *start << " "; start++;
}
}
int main()
{
int t1[] ={ 1, 2, 3, 4, 5};
list
l1.remove(2);
print(l1.begin(), l1.end()); cout< return 0; }
Answer : C
What happens when you attempt to compile and run the following code? Choose all that apply.
#include
#include
#include
using namespace std;
class A
{
int a;
public:
A(int a) {this?>a = a; c++;}
A(const A & a) {this?>a = a.a; c++;}
~A() { c??;}
static int c;
};
int A::c(0);
int main ()
{
A* t[] = {new A(1), new A(2), new A(3),new A(4), new A(5)};
vectorv1(t, t+10);
dequed1(v1.begin(), v1.end());
d1.clear();
v1.clear();
cout< return 0; }
Answer : B, D