What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include
using namespace std;
int main () {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
vector
vector
cout<< it?v.begin()<<endl;
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
void g(int a)
{
cout<<a?1<<endl;
}
template
void g(A a)
{
cout<<a+1<<endl;
}
int main()
{
int a = 1;
g(a);
return 0;
}
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
cout.setf(ios::hex, ios::basefield);
cout<<100<<" ";
cout.flags(ios::showbase);
cout<<100<<" ";
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include
using namespace std;
void myfunction(pair
cout << " " << i.first;
}
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
map
for(int i=0; i < 10; i++) {
m[i]=t[i];
}
for_each(m.begin(), m.end(), myfunction);
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
cout<<100<<" ";
cout.setf(ios::hex);
cout<<100<<" ";
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include
#include
#include <iostream>
#include <algorithm>
using namespace std;
template
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
struct Sequence {
int start;
Sequence(int start):start(start){}
int operator()() { return start++; } };
int main() {
vector
generate_n(v1.begin(), 10, Sequence(1));
random_shuffle(v1.rbegin(), v1.rend());
sort(v1.begin(), v1.end(), great
for_each(v1.begin(), v1.end(), Out
return 0;
}
Program outputs:
What happens 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
multiset
s1.insert(v.begin(),v.end());
pair
range = s1.equal_range(6);
while (range.first != range.second) {
cout<<*range.first<<" "; range.first++;
}
return 0;
}
Which changes, introduced independently, will allow the code to compile and display “one” “eight” “nine” “ten”? Choose all that apply
#include <iostream>
#include
#include <string>
using namespace std;
class A {
int a;
public:
A(int a):a(a){}
int getA() const { return a;}
/* Insert Code Here 1 */
};
/* Insert Code Here 2 */
int main(){
int t[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 10 };
string s[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight","ten"};
map m;/* Replace Code Here 3 */
for(int i=0; i<10; i++) {
m.insert(pair(A(t[i]),s[i]));
}
m.erase(m.lower_bound(2),m.upper_bound(7));
map::iterator i=m.begin(); /* Replace Code Here 4 */
for( ;i!= m.end(); i++) {
cout<<i?>second<<" ";
}
cout<<endl;
return 0;
}
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include
using namespace std;
int main () {
int t[] = {1,2,3,4,5,1,2,3,5,4};
vector
vector
int m1[] = {1, 3, 2};
it = find_end (v.begin(), v.end(), m1, m1+3);
if (it != v.end())
cout << "Found at position: " << it?v.begin() << endl;
return 0;
}
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<<" "; } };
struct Add : public binary_function
int operator() (const int & a, const int & b) const {
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(), bind1st(Add(), 1));
for_each(v2.rbegin(), v2.rend(), Out
return 0;
}
Program outputs:
PDF + Testing Engine
|
---|
$66 |
Testing Engine
|
---|
$50 |
PDF (Q&A)
|
---|
$42 |
C++ Institute Free Exams |
---|
![]() |