Question 1 of 25
Hints left: 3
Q1
What will be the output of the following C++ code? #include <iostream> #include <vector> #include <forward_list> using namespace std; int main() { forward_list<int> fl1 = {1,2,3,4,5}; for (int&c : fl1) cout << c << " "; cout<<endl; fl1.remove_if([](int x){ return x > 3;}); for (int&c : fl1) cout << c << " "; cout<<endl; return 0; }
Q2
What is meant by pure virtual function?
Q3
What will be the output of the following C++ code? #include <iostream> #include <vector> using namespace std; int main () { vector<int> first; first.assign (7,100); vector<int>::iterator it; it=first.begin()+1; int myints[] = {1776,7,4}; cout << int (first.size()) << '\n'; return 0; }
Q4
What is the main feature of locale in C++?
Q5
What will be the output of the following C++ code? #include <iostream> using namespace std; class poly { protected: int width, height; public: void set_values(int a, int b) { width = a; height = b; } }; class Coutput { public: void output(int i); }; void Coutput::output(int i) { cout << i; } class rect:public poly, public Coutput { public: int area() { return(width * height); } }; class tri:public poly, public Coutput { public: int area() { return(width * height / 2); } }; int main() { rect rect; tri trgl; rect.set_values(3, 4); trgl.set_values(4, 5); rect.output(rect.area()); trgl.output(trgl.area()); return 0; }
Q6
What will be the output of the following C++ code? #include <iostream> #include <algorithm> #include <vector> using namespace std; int main () { vector<int> myvector; for (int i = 1; i < 5; ++i) myvector.push_back(i); rotate(myvector.begin(), myvector.begin() + 3, myvector.end( )); for (vector<int> :: iterator it = myvector.begin(); it != myvector.end(); ++it) cout << ' ' << *it; return 0; }
Q7
What will be the output of the following C++ code? #include <string> #include <iostream> using namespace std; void string_permutation( string& orig, string& perm ) { if (orig.empty()) { cout<<perm<<endl; return; } for (int i = 0; i < orig.size(); ++i) { string orig2 = orig; orig2.erase(i, 1); string perm2 = perm; perm2 += orig.at(i); string_permutation(orig2, perm2); } } int main() { string orig = "ter"; string perm; string_permutation(orig, perm); return 0; }
Q8
Elements in STL heap are removed in . . . . . . . .
Q9
What type of class template is list?
Q10
What will be the output of the following C++ code? #include <iostream> #include <bitset> using namespace std; int main() { bitset<8> b1(95); bitset<8> b2 = b1 << 3; cout<<b2; }
Q11
How many types of sequence operations are provided by the C++ algorithm STL?
Q12
What are command line arguments?
Q13
Which is used to get the input during runtime?
Q14
What function will be called when we have an uncaught exception?
Q15
What will be the output of the following C++ code? #include <iostream> #include <Valarray> using namespace std; int main() { Valarray<int> varr = { 1, 2, 3, 4, 5 }; for (int &x: varr) cout << x << " "; cout<<endl; varr = varr.shift(2); for (int &x: varr) cout << x << " "; return 0; }
Q16
What will be the output of the following C++ code? #include <iostream> #include <valarray> using namespace std; int main() { valarray<int> varr = { 10, 2, 20, 1, 30 }; cout<<"Sum of array: "<<varr.sum(); return 0; }
Q17
What will be the output of the following C++ code? #include <iostream> using namespace std; class Base { public: Base ( ) { cout << "1" << endl; } ~Base ( ) { cout << "2" << endl; } }; class Derived : public Base { public: Derived ( ) { cout << "3" << endl; } ~Derived ( ) { cout << "4" << endl; } }; int main( ) { Derived x; }
Q18
What will be the output of the following C++ code? #include <iostream> #include <complex> using namespace std; int main() { complex <double> cn(3.0, 5.0); cout<<"Complex number is: "<<real(cn)<<" + "<<imag(cn)<<"i"<<endl; return 0; }
Q19
Which of the following header file is needed to use vectors in your program?
Q20
What kind of iteration does forward_list provide in C++?
Q21
Pick out the correct statement about vector.
Q22
What will be the output of the following C++ code? #include <iostream> #include <functional> #include <numeric> using namespace std; int myfunction (int x, int y) { return x + 2 * y; } struct myclass { int operator()(int x, int y) { return x + 3 * y; } } myobject; int main () { int init = 100; int numbers[] = {10, 20, 30}; cout << accumulate(numbers, numbers + 3, init); cout << endl; }
Q23
How do define the user-defined exceptions?
Q24
What will be the output of the following C++ code? #include <iostream> #include <memory> #include <string> using namespace std; int main () { string numbers[] = {"steve", "jobs"}; pair <string*, ptrdiff_t> result = get_temporary_buffer<string>(2); if (result.second>0) { uninitialized_copy ( numbers, numbers + result.second, result.first ); for (int i = 0; i < result.second; i++) cout << result.first[i] << " "; return_temporary_buffer(result.first); } return 0; }
Q25
Which of the following is correct about Input Iterators?