What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main () {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
vector<int> v (t,t+15);
int number = count(v.begin(), v.end(), 2);
cout<< number<<endl;
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <deque>
#include <list>
#include <queue>
#include <vector>
using namespace std;
int main()
{
deque<int> mydeck;list<int> mylist; vector<int> myvector;
queue<int> first; queue<int> second(mydeck);
queue<int> third(second); queue<int, list<int> > fourth(mylist);
fourth.push(10);fourth.push(11);fourth.push(12);
queue<int, vector<int> > fifth(myvector);
fifth.push(10);fifth.push(11);fifth.push(12); // Line I
while(!fifth.empty())
{
cout<<fifth.front()<<" "; // Line II
fifth.pop(); // Line III
}
while (!fourth.empty())
{
cout << fourth.front() << " ";
fourth.pop(); // Line IV
}
return 0;
}
What happens 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; }
operator int() const {return a;}
};
int main () {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
set<A> s (t,t+15);
cout<<equal(s.begin(), s.end(), t)<<endl;
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main () {
int t[] = {1,2,3,4,5,1,2,3,4,5};
vector<int> v (t,t+10);
vector<int>::iterator it;
int m1[] = {1, 3, 2};
it = find_first_of (v.begin(), v.end(), m1, m1+3);
cout << "First found at position: " << it?v.begin() << endl;
return 0;
}
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
template<int>
void g(int a)
{
cout<<a?1<<endl;
}
template<class A>
void g(A a)
{
cout<<a+1<<endl;
}
int main()
{
int a = 1;
g(a);
return 0;
}