Professional Documents
Culture Documents
Windows 7 It Essential 1 - 1
Windows 7 It Essential 1 - 1
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;
int main ()
{
int first[] = {10, 40, 90};
int second[] = {1, 2, 3};
int results[5];
transform ( first, first + 5, second, results, divides<int>());
for (int i = 0; i < 3; i++)
cout << results[i] << " ";
return 0;
}
a) 10 20
b) 20 30
c) 10 20 30
d) All of the mentioned
View Answer
5. What is the output of this program?
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;
int main ()
{
int numbers[] = {3, -4, -5};
transform ( numbers, numbers + 5, numbers, negate<int>() );
for (int i = 0; i < 3; i++)
cout << numbers[i] << " ";
}
a) -3
b) 3 4 5
c) 3 -4 5
d) -3 4 5
View Answer
6. What is the output of this program?
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
#include <iostream>
#include <functional>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main ()
{
vector <string*> numbers;
numbers.push_back ( new string ("one") );
numbers.push_back ( new string ("two") );
numbers.push_back ( new string ("three") );
vector <int> lengths ( numbers.size() );
transform (numbers.begin(), numbers.end(), lengths.begin(),
mem_fun(&string :: length));
16.
17.
18.
19.
20.
21.
a) 335
b) 225
c) 334
d) 224
View Answer
7. What is the output of this program?
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;
int main ()
{
int numbers[] = {1, 2, 3};
int remainders[5];
transform ( numbers, numbers + 5, remainders,
bind2nd(modulus<int>(), 2) );
for (int i = 0; i < 5; i++)
cout << (remainders[i] == 1 ? "odd" : "even") << "\n";
return 0;
}
a) odd
even
b) even
c) odd
odd
d) Runtime error
View Answer
8. What is the output of this program?
1.
2.
3.
4.
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;
5.
6.
7.
8.
9.
10.
11.
12.
int main ()
{
int numbers[] = {10, -20, -30, 40, -50};
int cx;
cx = count_if ( numbers, numbers + 5, bind2nd(less<int>(), 0) );
cout << cx;
return 0;
}
a) 1
b) 2
c) 3
d) 4
View Answer
9. Which are instances of a class with member function operator() when it is
defined?
a) function objects
b) member
c) methods
d) none of the mentioned
View Answer
10. How many parameters does a operator() in a function object shoud take?
a) 1
b) 2
c) 3
d) 4
View Answer