What happens when you attempt to compile and run the following code?
#include
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
template
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
int Add(int a, int b) {
return a+b;
}
int main() {
int t[]={1,2,3,4,5,6,7,8,9,10};
vector
vector
transform(v1.begin(), v1.end(), v2.begin(), bind2nd(ptr_fun (Add),1));
vector
cout<<*it<<endl;
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include
using namespace std;
struct Compare {
bool operator ()(int a) {
if (a >5) return true;
return false;
}
};
int main () {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
vector
int number = count(v.begin(), v.end(), Compare());
cout<< number<<endl;
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include
#include
using namespace std;
void myfunction(int i) {
cout << " " << i;
}
bool classifier(int v) {
return v%2==0;
}
int main() {
int t[] = { 1, 5, 2, 5, 2, 4, 4, 3, 3, 1 };
vector
set
replace(v1.begin(), v1.end(),classifier, 10);
for_each(v1.begin(), v1.end(), myfunction);
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include <iostream>
#include
#include
using namespace std;
template
while (start != end) {
std::cout << *start << " "; start++;
}
}
int main(){
vector
multiset
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<<endl;
return 0;
}
What happens when you attempt to compile and run the following code?
#include
#include <iostream>
int main ()
{
std::vector
for(int i = 10; i>0; i??)
{
v1.push_back(i);
}
std::vector
int sum = 0;
while(it != v1.end())
{
sum+=it++;
}
std::cout<<*v1.erase(v1.begin(),v1.end()?3)<<" "< return 0; }
What happens when you attempt to compile and run the following code?
#include
#include
#include <iostream>
#include <string>
using namespace std;
template<typename T>
void print(T start, T end)
{
while (start != end)
cout<<*start++;
}
int main ()
{
string t[] = {"one", "two" ,"three" ,"four", "five"};
vector<string>v1(t, t+5);
deque<string>d1(v1.rbegin(), v1.rend());
d1.push_back("zero");
print(d1[0].rbegin(),d1[0].rend());
return 0;
}
What will happen when you attempt to compile and run the following code?
#include <iostream>
#include
#include
using namespace std;
int main(){
int t[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
vector
set
s1.insert(v.begin(),v.end());
pair
range = s1.equal_range(6);
cout<<*range.first<<" "<<*range.second<<endl;
return 0;
}
The output will be:
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include
using namespace std;
struct Even {
bool operator ()(int a) {
return (a % 2)==0?true:false;
}
};
int main () {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
set
int number = count_if(s.begin(), s.end(), Even());
cout<< number<<endl;
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
#include <iostream>
using namespace std;
int main ()
{
int t[] = {1, 2 ,3 ,4 ,5, 6 , 7, 8 , 9, 10};
vector
deque
d1.empty();
v1.empty();
if (v1.isempty())
{
cout<<"I am empty ";
}
else
{
cout<<"I am not empty ";
}
cout<<v1.size()<<" "< return 0; }
What happens when you attempt to compile and run the following code?
#include <iostream>
#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"};
multimap
for (int i = 0; i < 10; i++) {
m.insert(pair
}
if (m.count(3) == 2) {
m.erase(3);
}
for (multimap
cout << i?>first << " ";
}
return 0;
}
PDF + Testing Engine
|
---|
$66 |
Testing Engine
|
---|
$50 |
PDF (Q&A)
|
---|
$42 |
C++ Institute Free Exams |
---|
![]() |