Question 1 of 25
Hints left: 3
Q1
What is the use of log() function in a complex?
Q2
What will be the output of the following C++ code? #include <stdexcept> #include <limits> #include <iostream> using namespace std; void func(int c) { if (c < numeric_limits<char> :: max()) throw invalid_argument("MyFunc argument too large."); else { cout<<"Executed"; } } int main() { try { func(256); } catch(invalid_argument& e) { cerr << e.what() << endl; return -1; } return 0; }
Q3
What is meant by polymorphism?
Q4
setprecision requires which of the following header file?
Q5
What will be the output of the following C++ code? #include <iostream> #include <new> using namespace std; int main () { int i, n; int * p; i = 2; p= new (nothrow) int[i]; if (p == 0) cout << "Error: memory could not be allocated"; else { for (n=0; n<i; n++) { p[n] = 5; } for (n = 0; n < i; n++) cout << p[n]; delete[] p; } return 0; }
Q6
What is the correct syntax of defining function template/template functions?
Q7
Which of the following is correct syntax of making heap from a vector v?
Q8
Pick out the incorrect method in non-modifying sequence algorithm?
Q9
What do container adapter provide to interface?
Q10
What will be the output of the following C++ code? #include <vector> #include <algorithm> #include <iostream> #include <iterator> using namespace std; int square(int i) { return i * i; } int main() { vector<int> V, V2; V.push_back(0); V.push_back(1); V.push_back(2); transform(V.begin(), V.end(), back_inserter(V2), square); copy(V2.begin(), V2.end(), ostream_iterator<int>(cout, " ")); cout << endl; }
Q11
What will be the output of the following C++ code? #include <iostream> #include <vector> #include <algorithm> using namespace std; int main(int argc, char const *argv[]) { vector <int> v = {1,5,23,90,15,35}; make_heap(v.begin(),v.end()); cout<<v.front(); }
Q12
What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { double a = 10, b = 5, res; char Operator = '/'; try { if (b == 0) throw "Division by zero not allowed"; res = a / b; cout << a << " / " << b << " = " << res; } catch(const char* Str) { cout << "\n Bad Operator: " << Str; } return 0; }
Q13
What will be the output of the following C++ code? #include <iostream> using namespace std; long factorial (long a) { if (a > 1) return (a * factorial (a + 1)); else return (1); } int main () { long num = 3; cout << num << "! = " << factorial ( num ); return 0; }
Q14
What is mandatory for designing a new container?
Q15
What will be the output of the following C++ code? #include <iostream> using namespace std; class BaseClass { int x; public: void setx(int n) { x = n; } void showx() { cout << x ; } }; class DerivedClass : private BaseClass { int y; public: void setxy(int n, int m) { setx(n); y = m; } void showxy() { showx(); cout << y << '\n'; } }; int main() { DerivedClass ob; ob.setxy(10, 20); ob.showxy(); return 0; }
Q16
What will be the output of the following C++ code? #include <iostream> #include <vector> using namespace std; int main () { vector<int> myvector (5); int* p = myvector.data(); *p = 10; ++p; *p = 20; p[2] = 100; for (unsigned i = 0; i < myvector.size(); ++i) cout << ' ' << myvector[i]; return 0; }
Q17
What is the use of is_array() function in C++?
Q18
What will be the output of the following C++ code? #include <iostream> using namespace std; double division(int a, int b) { if (b == 0) { throw "Division by zero condition!"; } return (a / b); } int main () { int x = 50; int y = 0; double z = 0; try { z = division(x, y); cout << z << endl; } catch (const msg) { cerr << msg << endl; } return 0; }
Q19
How many streams are automatically created when executing a program?
Q20
Which of the following function is used to get the actual number of elements stored in vector?
Q21
Given the below class, what is the correct syntax of declaring a functor that adds 10 to each of the passed argument? class Add { int x; public: Add(int x){ this->x = x; } int operator()(int a){ return x+a; } };
Q22
What are functors in C++?
Q23
What will be the output of the following C++ code? #include <iostream> #include <vector> using namespace std; int main () { vector<int> myvector (3); for (unsigned i = 0; i < myvector.size(); i++) myvector.at(i) = i; for (unsigned i = 0; i < myvector.size(); i++) cout << ' ' << myvector.at(i); return 0; }
Q24
What is the correct syntax of constructing any using assignment operator?
Q25
What is random_device?