C++ Cert Exam 1

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Which operator works only with integer variables? a) increment b) decrement c) both a & b d) None of the mentioned

Answer:c Explanation:None.

Constructors are used to a) initalize the objects b) construct the data members c) both a & b d) none of the mentioned

Answer:a Explanation:Once the object is declared means, the constructor are also declared by default.

Which of the following keyword is used to declare the header file? a) include b) exclude c) string d) namespace

Answer:a Explanation:The include keyword is used to include all the required things to execute the given code in the program.

Which is used to define the member of a class externally? a) : b) :: c) # d) none of the mentioned

Answer:b Explanation:None.

Which keyword is used to declare the friend function? a) firend b) friend c) classfriend d) myfriend

Answer:b Explanation:None.

Which of the header file must be included to use stringstream? a) <iostream> b) <string> c) <sstring> d) <sstream>

Answer:b Explanation:None.

Which operator is having the highest precedence in c++? a) array subscript b) Scope resolution operator c) static_cast d) dynamic_cast

Answer:b Explanation:None.

setprecision requires which of the following header file? a) stdlib.h b) iomanip.h c) console.h d) conio.h

Answer:b Explanation:The iomanip header file is used to correct the precision of the values.

What is the output of this program? #include <stdio.h> using namespace std; int main() { int x = 5, y = 5; cout << ++x << --y << endl; return 0; } a) 55 b) 64 c) 46 d) 45

Answer:b Explanation:The values will be preincemented and predecremented, So it will print as 64. Output: 64

How many types are there in increment/decrement operator? a) 1 b) 2 c) 3 d) 4

Answer:b Explanation:There are two types of increment/decrement. They are postfix and prefix.

How many types of models are available to create the user-defined data type? a) 1 b) 2 c) 3 d) 4

Answer:b Explanation:There are two types of models. They are references to built-in types and multipart types.

How types are there in user defined conversion? a) 1 b) 2 c) 3 d) 4

Answer:b Explanation:There are two types of user-defined conversions.They are conversion by constructor, Conversion functions.

Which special character is used to mark the end of class? a) ; b) : c) # d) $

Answer: a Explanation:None.

What does your class can hold? a) data b) functions c) both a & b d) none of the mentioned

Answer:C Explanation:The classes in c++ are used to manipulate both data and functions.

Pick out the correct statement a) Preincrement is faster than postincrement. b) postincrement is faster than preincrement. c) Both a & b d) None of the mentioned

Answer:a Explanation:Because preincrement take one byte instruction & post increment takes two byte instruction.

Identify the correct statement. a) typedef does not create different types.It only creates synonyms of existing types. b) typedef create different types. c) both a & b d) none of the mentioned

Answer:a Explanation:By using typedef, we can create a type of pre-existing type only not our own type of data.

Which rule will not affect the friend function? a) private and protected members of a class cannot be accessed from outside b) private and protected member can be accessed anywhere c) both a & b d) None of the mentioned

Answer:a Explanation:Friend is used to access private and protected members of a class from outside the same class.

Where does the object is created? a) class b) constructor c) destructor d) attributes

Answer:a Explanation:In class only all the listed items except class will be declared.

What is the syntax of friend function? a) friend class1 Class2; b) friend class; c) friend class d) None of the mentioned

Answer:a Explanation:In option a, the class2 is the friend of class1 and it can access all the private and protected members of class1.

What is the output of this program? #include <iostream> using namespace std; class myclass { public: int i; myclass *operator->() {return this;} }; int main() { myclass ob; ob->i = 10; cout << ob.i << " " << ob->i; return 0; } a) 10 10 b) 11 11 c) error d) runtime error

Answer:a Explanation:In this program, -> operator is used to describe the member of the class and so we are getting this output. Output: $ g++ char4.cpp $ a.out 10 10

What is the output of this program? #include <iostream> using namespace std; class base { int val1, val2; public: int get() { val1 = 100; val2 = 300; } friend float mean(base ob); }; float mean(base ob) { return float(ob.val1 + ob.val2) / 2; } int main() { base obj; obj.get(); cout << mean(obj); return 0; } a) 200 b) 150 c) 100 d) 300

Answer:a Explanation:In this program, We are finding the mean value by declaring the function mean as a friend of class base. Output: $ g++ friend3.cpp $ a.out 200

What is the output of this program? #include <iostream> using namespace std; int main () { int a; int * ptr_b; int ** ptr_c; a = 1; ptr_b = &a; ptr_c = &ptr_b; cout << a << "\n"; cout << *ptr_b << "\n"; cout << *ptr_c << "\n"; cout << **ptr_c << "\n"; return 0; } a) 1 1 0xbffc9924 1 b) 1 1 1 0xbffc9924 c) 1 0xbffc9924 1 1 d) none of the mentioned

Answer:a Explanation:In this program, We are printing the values and memory address by using the pointer and derefernce operator. Output: $ g++ def2.cpp $ a.out 1 1 0xbffc9924 1

What is the output of this program? #include <iostream> using namespace std; int main() { double arr[] = {5.0, 6.0, 7.0, 8.0}; double *p = (arr+2); cout << *p << endl; cout << arr << endl; cout << *(arr+3) << endl; cout << *(arr) << endl; cout << *arr+9 << endl; return 0; } a) 7 0xbf99fc98 8 5 14 b) 7 8 0xbf99fc98 5 14 c) 0xbf99fc98 d) none of the mentioned

Answer:a Explanation:In this program, We are printing the values that are pointed by pointer and also the dereference oerator. Output: $ g++ def5.cpp $ a.out 7 0xbf99fc98 8 5 14

What is the output of this program? #include <iostream> using namespace std; const int SIZE = 10; class safe { private: int arr[SIZE]; public: safe() { register int i; for (i = 0; i < SIZE; i++) { arr[i] = i; } } int &operator[](int i) { if (i > SIZE) { cout << "Index out of bounds" <<endl; return arr[0]; } return arr[i]; } }; int main() { safe A; cout << A[5]; cout << A[12]; return 0; } a) 5Index out of bounds 0 b) 40 c) 50 d) 51

Answer:a Explanation:In this program, We are returning the elements in the specified array location and if it is out of bound means it will return the first element. Output: $ g++ sub.cpp $ a.out 5Index out of bounds 0

What is the output of this program? #include #include using namespace std; class Complex { private: float real; float imag; public: Complex():real(0), imag(0){} Complex operator ()(float re, float im) { real += re; imag += im; return *this; } Complex operator() (float re) { real += re; return *this; } void display() { cout << "(" << real << "," << imag << ")" << endl; } }; int main() { Complex c1, c2; c2 = c1(3.2, 5.3); c1(6.5, 2.7); c2(1.9); cout << "c2=";c1.display(); cout << "c2=";c2.display(); return 0; } a) c2=(9.7,8) c2=(5.1,5.3) b) c2=(9,8) c2=(5,5) c) c2=(4.7,8) c2=(2.1,5.3) d) none of the mentioned

Answer:a Explanation:In this program, We are returning the real and imaginary part of the complex number by using function call operator. Output: $ g++ call3.cpp $ a.out c2=(9.7,8) c2=(5.1,5.3)

What is the output of this program? #include <iostream> using namespace std; int main () { int a, b; a = 10; b = 4; a = b; b = 7; cout << "a:"; cout << a; cout << " b:"; cout << b; return 0; } a) a:4 b:7 b) a:10 b:4 c) a:4 b:10 d) None of the mentioned

Answer:a Explanation:In this program, we are reassigning the values of a and b because of this we got the output as a:4 b:7 Output: $ g++ ess.cpp $ a.out a:4 b:7

What is the output of this program? #include using namespace std; class three_d { int x, y, z; public: three_d() { x = y = z = 0; } three_d(int i, int j, int k) { x = i; y = j; z = k; } three_d operator()(three_d obj); three_d operator()(int a, int b, int c); friend ostream &operator<<(ostream &strm, three_d op); }; three_d three_d::operator()(three_d obj) { three_d temp; temp.x = (x + obj.x) / 2; temp.y = (y + obj.y) / 2; temp.z = (z + obj.z) / 2; return temp; } three_d three_d::operator()(int a, int b, int c) { three_d temp; temp.x = x + a; temp.y = y + b; temp.z = z + c; return temp; } ostream &operator<<(ostream &strm, three_d op) { strm << op.x << ", " << op.y << ", " << op.z << endl; return strm; } int main() { three_d objA(1, 2, 3), objB(10, 10, 10), objC; objC = objA(objB(100, 200, 300)); cout << objC; return 0; } a) 55, 106, 156 b) 55, 106 c) 55, 106, 159 d) none of the mentioned

Answer:a Explanation:In this program, We are using the function call operator to calculate the value of objc. Output: $ g++ call2.cpp $ a.out 55, 106, 156

What is the output of this program? #include <iostream> #include <string> using namespace std; class test { public: operator string () { return "Converted"; } }; int main() { test t; string s = t; cout << s << endl; return 0; } a) converted b) error c) run time error d) None of the mentioned

Answer:a Explanation:In this program, We casted the string to the object of the class. Output: converted

What is the output of this program? #include <stdio.h> using namespace std; int main() { int x = 5, y = 5, z; x = ++x; y = --y; z = x++ + y--; cout << z; return 0; } a) 10 b) 11 c) 9 d) 12

Answer:a Explanation:In this program, the increment and decrement of evaluation of z will not be accounted because they are post. Output: $ g++ incre3.cpp $ a.out 10

What is the output of this program? #include <iostream> using namespace std; int main() { int a = 20; int b = 10; int c = 15; int d = 5; int e; e = a + b * c / d; cout << e << endl ; return 0; } a) 50 b) 60 c) 70 d) 90

Answer:a Explanation:In this program, the value e is evaluated by precedence ad we got the output as 50. Output: $ g++ ess4.cpp $ a.out 50

What is the output of this program? #include <iostream> #include <cmath> using namespace std; class Complex { private: double real; double imag; public: Complex(double r = 0.0, double i = 0.0) : real(r), imag(i) {} double mag() { return getMag(); } operator double () { return getMag(); } private: double getMag() { return sqrt(real * real + imag * imag); } }; int main() { Complex com(3.0, 4.0); cout << com.mag(); cout << com; return 0 } a) 5 5 b) 4 5 c) 6 6 d) None of the mentioned

Answer:a Explanation:In this program, we are calculating the magnitude value by two ways. Output: $ g++ con3.cpp $ a.out 55

What is the output of this program? #include <iostream> using namespace std; int main() { int x; int *p; x = 5; p = &x; cout << *p; return 0; } a) 5 b) 10 c) memory address d) none of the mentioned

Answer:a Explanation:In this program, we are copying the memory location of x into p and then printing the value in the address. Output: 5

What is the output of this program? #include <iostream> using namespace std; int main() { int i; enum month { JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,DEC }; for (i = JAN; i <= DEC; i++) cout << i; return 0; } a) 012345678910 b) 0123456789 c) 01234567891011 d) none of the mentioned

Answer:a Explanation:In this program, we are defined the data types as enumerator and printing its value in a order. Output: $ g++ user1.cpp $ a.out 012345678910

What is the output of this program? #include <iostream> #include <stdarg.h> using namespace std; float avg( int Count, ... ) { va_list Numbers; va_start(Numbers, Count); int Sum = 0; for (int i = 0; i < Count; ++i) Sum += va_arg(Numbers, int); va_end(Numbers); return (Sum/Count); } int main() { float Average = avg(10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9); cout << Average; return 0; } a) 4 b) 5 c) 6 d) compile time error

Answer:a Explanation:In this program, we are finding the average of first 10 numbers using stdarg header file Output: 4

What is the output of this program? #include <iostream> #include <complex> using namespace std; int main() { complex<double> c1(4.0, 16.0), c2; c2 = pow(c1, 2.0); cout << c2; return 0; } a) (-240, 128) b) (240, 128) c) (240, 120) d) None of the mentioned

Answer:a Explanation:In this program, we are finding the square of the complex number. Output: $ g++ comp.cpp $ a.out (-240,128)

What is the output of this program? #include <iostream> #include <complex> using namespace std; int main() { complex<double> c1(4.0, 16.0), c2; c2 = pow(c1, 2.0); cout << c2; return 0; } a) (-240, 128) b) (240, 128) c) (240, 120) d) None of the mentioned View Answer Answer:a Explanation:In this program, we are finding the square of the complex number. Output: $ g++ comp.cpp $ a.out (-240,128)

Answer:a Explanation:In this program, we are finding the square of the complex number. Output: $ g++ comp.cpp $ a.out (-240,128)

What is the output of this program? #include <iostream> using namespace std; class CDummy { public: int isitme (CDummy& param); }; int CDummy::isitme (CDummy& param) { if (&param == this) return true; else return false; } int main () { CDummy a; CDummy *b = &a; if (b->isitme(a)) { cout << "execute"; } else { cout<<"not execute"; } return 0; } a) execute b) not execute c) none of the mentioned d) both a & b

Answer:a Explanation:In this program, we are just pointing the pointer to a object and printing execute if it is correctly pointed. Output: execute

What is the output of this program? #include <iostream> using namespace std; int main() { typedef int num; num a = 10, b = 15; num c = a + b + a - b; cout << c; return 0; } a) 20 b) 15 c) 30 d) 25

Answer:a Explanation:In this program, we are manipulating the numbers and printing the result using user-defined data types. Output: $ g++ user.cpp $ a.out 20

What is the output of this program? #include <iostream> using namespace std; class sample { private: int* i; int j; public: sample (int j); ~sample (); int& operator [] (int n); }; int& sample::operator [] (int n) { return i[n]; } sample::sample (int j) { i = new int [j]; j = j; } sample::~sample () { delete [] i; } int main () { sample m (5); m [0] = 25; m [1] = 20; m [2] = 15; m [3] = 10; m [4] = 5; for (int n = 0; n < 5; ++ n) cout << m [n]; return 0; } a) 252015105 b) 510152025 c) 51015 d) None of the mentioned

Answer:a Explanation:In this program, we are printing the array in the reverse order by using subscript operator. Output: $ g++ sub4.cpp $ a.out 252015105

What is the output of this program? #include <iostream> using namespace std; const int limit = 4; class safearray { private: int arr[limit]; public: int& operator [](int n) { if (n == limit - 1) { int temp; for (int i = 0; i < limit; i++) { if (arr[n + 1] > arr[n]) { temp = arr[n]; arr[n] = arr[n + 1]; arr[n + 1] = temp; } } } return arr[n]; } }; int main() { safearray sa1; for(int j = 0; j < limit; j++) sa1[j] = j*10; for(int j = 0; j < limit; j++) { int temp = sa1[j]; cout << "Element " << j << " is " << temp; } return 0; } a) 0102030 b) 1020300 c) 3020100 d) error

Answer:a Explanation:In this program, we are returning the array element by the multiple of 10. Output: $ g++ sub2.cpp $ a.out 0102030

What is the output of this program? #include <iostream> using namespace std; int main() { double a = 21.09399; float b = 10.20; int c ; c = (int) a; cout << c ; c = (int) b; cout << c ; return 0; } a) 2110 b) 1210 c) 21 d) None of the mentioned

Answer:a Explanation:In this program, we casted the data type to integer. Output: 2110

What is the output of this program? #include <iostream> using namespace std; class Box { double length; double breadth; double height; public: double getVolume(void) { return length * breadth * height; } void setLength( double len ) { length = len; } void setBreadth( double bre ) { breadth = bre; } void setHeight( double hei ) { height = hei; } Box operator+(const Box& b) { Box box; box.length = this->length + b.length; box.breadth = this->breadth + b.breadth; box.height = this->height + b.height; return box; } }; int main( ) { Box Box1; Box Box2; Box Box3; double volume = 0.0; Box1.setLength(6.0); Box1.setBreadth(7.0); Box1.setHeight(5.0); Box2.setLength(12.0); Box2.setBreadth(13.0); Box2.setHeight(10.0); volume = Box1.getVolume(); cout << "Volume of Box1 : " << volume <<endl; volume = Box2.getVolume(); cout << "Volume of Box2 : " << volume <<endl; Box3 = Box1 + Box2; volume = Box3.getVolume(); cout << "Volume of Box3 : " << volume <<endl; return 0; } a) Volume of Box1 : 210 Volume of Box2 : 1560 Volume of Box3 : 5400 b) Volume of Box1 : 200 Volume of Box2 : 1560 Volume of Box3 : 5400 c) Volume of Box1 : 210 Volume of Box2 : 1550 Volume of Box3 : 5400 d) None of the mentioned

Answer:a Explanation:In this program, we finding the box3 area by adding box1 and box2. Output: $ g++ oper1.cpp $ a.out Volume of Box1 : 210 Volume of Box2 : 1560 Volume of Box3 : 5400

What will be the output of these two programs? 1. #ifndef Exercise_H #define Exercise_H int num = 842; #endif 2. #include <iostream> #include "exe.h" using namespace std; int main(int argc, char * argv[] ) { cout << number++; return 0; } a) 842 b) 843 c) compile time error d) none of the mentioned

Answer:a Explanation:In this program, we have created a header file and linked that into the source program and we are post incrementing that because of that it is printed as 842. Output: $ g++ link.cpp $ a.out 842

Why we use the "dynamic_cast" type conversion? a) result of the type conversion is a valid b) to be used in low memory c) result of the type conversion is a invalid d) None of the mentioned

Answer:a Explanation:It is used to check that operators and operands are compatible after conversion.

Pick out the correct syntax of operator conversion. a) operator float()const b) operator float() c) operator const d) None of the mentioned .

Answer:a Explanation:None

10. When struct is used instead of the keyword class means, what will happen in the program? a) access is public by default b) access is private by default c) access is protected by default d) none of the mentioned

Answer:a Explanation:None.

How many parameters does a conversion operator may take? a) 0 b) 1 c) 2 d) as many as possible

Answer:a Explanation:None.

Pick out the correct option. a) References automatically dereference without needing an extra character. b) References automatically dereference with an extra character. c) Reference will not dereference d) none of the mentioned

Answer:a Explanation:None.

Pick out the correct statement. a) Increment operator ++ adds 1 to its operand b) Increment operator ++ adds 2 to its operand c) Decrement operator ++ subtracts 1 to its operand d) None of the mentioned

Answer:a Explanation:None.

Pick out the correct statement. a) The NULL pointer dereference occurs where a pointer that is expected to be a valid address but instead is equal to NULL. b) The NULL pointer dereference occurs where a pointer that is expected to be a valid address but instead is equal to memory address. c) both a & b d) none of the mentioned

Answer:a Explanation:None.

Pick out the correct statement. a) subscript operator has a higher precedence than the assignment operator. b) subscript operator has a lower precedence than the assignment operator. c) subscript operator is used with string elements. d) None of the mentioned

Answer:a Explanation:None.

Pick out the correct statement. a) virtual functions does not give the ability to write a templated function. b) virtual functions does not give the ability to rewrite a templated function. c) virtual functions does give the ability to write a templated function. d) none of the mentioned

Answer:a Explanation:None.

To use internal linkage we have to use which keyword? a) static b) extern c) static or extern d) none of the mentioned

Answer:a Explanation:None.

What is the syntax of user-defined data types? a) typedef_existing data type_new name b) typedef_new name_existing data type c) def_existing data type_new name d) none of the mentioned

Answer:a Explanation:None.

What is the use of functor? a) It makes the object "callable" like a function. b) It makes the class "callable" like a function. c) It makes the attribute "callable" like a function. d) none of the mentioned

Answer:a Explanation:None.

Which is used to tell the computer that where a pointer is pointing to? a) dereference b) reference c) heap operations d) none of the mentioned

Answer:a Explanation:None.

Which of the following is a valid class declaration? a) class A { int x; }; b) class B { } c) public class A { } d) object A { int x; };

Answer:a Explanation:None.

Which of the following operators can't be overloaded? a) :: b) + c) - d) []

Answer:a Explanation:None.

Which header file is used to declare the complex number? a) complexnum b) complex c) complexnumber d) None of the mentioned

Answer:b Explanation:None.

Identify the incorrect statement. a) iostream is a standard header and iostream.h is a non-standard header. b) iostream is a non-standard header and iostream.h is a non-standard header. c) iostream is a standard header and iostream.h is a standard header. d) none of the mentioned

Answer:a Explanation:The iostream.h is used in the older versions of c++ and iostream is evolved from it in the std namespace

Where does keyword 'friend' should be placed? a) function declaration b) function definition c) main function d) None of the mentioned

Answer:a Explanation:The keyword friend is placed only in the function declaration of the friend function and not in the function definition because it is used toaccess the member of a class.

0. What do we need to use when we have multiple subscripts? a) operator() b) operator[] c) operator d) None of the mentioned

Answer:a Explanation:The reason is that operator[] always takes exactly one parameter, but operator() can take any number of parameters.

How many arguments will the subscript operator will take for overloading? a) 1 b) 2 c) 0 d) as many as possible

Answer:a Explanation:The subscript operator overload takes only one argument, but it can be of any type.

What is the output of this program? #include <iostream> #include <complex> using namespace std; int main() { complex<double> c1(4.0,3.0); cout << "c1: " << c1; complex<float> c2(polar(5.0,0.75)); cout << c1 + complex<double>(c2.real(),c2.imag()); return 0; } a) c1: (4,3)(7.65844,6.40819) b) c1: (4,3)(7,6) c) both a & b d) None of the mentioned

Answer:a Explanation:We are adding the two complex numbers and printing the result. Output: $ g++ comp3.cpp $ a.out c1: (4,3)(7.65844,6.40819)

What is the output of the program? #include <iostream> using namespace std; class Rect { int x, y; public: void set_values (int,int); int area () { return (x * y); } }; void Rect::set_values (int a, int b) { x = a; y = b; } int main () { Rect recta, rectb; recta.set_values (5, 6); rectb.set_values (7, 6); cout << "recta area: " << recta.area(); cout << "rectb area: " << rectb.area(); return 0; } a) recta area: 30 rectb area: 42 b) recta area: 20 rectb area: 34 c) recta area: 30 rectb area: 21 d) none of the mentioned

Answer:a Explanation:We are calculating the area of rectangle by two objects.

What is the output of this program? #include using namespace std; class Distance { private: int feet; int inches; public: Distance() { feet = 0; inches = 0; } Distance(int f, int i) { feet = f; inches = i; } Distance operator()(int a, int b, int c) { Distance D; D.feet = a + c + 10; D.inches = b + c + 100 ; return D } void displayDistance() { cout << feet << inches << endl; } }; int main() { Distance D1(11, 10), D2; cout << "First Distance : "; D1.displayDistance(); D2 = D1(10, 10, 10); cout << "Second Distance :"; D2.displayDistance(); return 0; } a) First Distance : 1110 Second Distance :30120 b) First Distance : 110 Second Distance :3020 c) First Distance : 1115 Second Distance :30125 d) none of the mentioned

Answer:a Explanation:We are calculating the foot and inches by using the function call operator. Output: $ g++ call.cpp $ a.out First Distance : 1110 Second Distance :30120

What is the output of this program? #include <iostream> using namespace std; class number { int i; public: int geti(); void puti(int j); }; int number::geti() { return i; } void number::puti(int j) { i = j; } int main() { number s; s.puti(10); cout << s.geti( ); return 0; } a) 10 b) 11 c) 20 d) 22

Answer:a Explanation:We are getting the number and copying it to j and printing it. Output: $ g++ obj2.cpp $ a.out 10

What is the output of this program? #include <iostream> #include <complex> using namespace std; int main() { complex<int> i(2, 3); i = i * 6 / 3; cout << i; return 0; } a) (4, 6) b) (2, 3) c) (6, 12) d) None of the mentioned

Answer:a Explanation:We are multiplying the complex number by 2. Output: $ g++ comp2.cpp $ a.out (4,6)

. What is the output of this program? #include <iostream> using namespace std; class Integer { int i; public: Integer(int ii) : i(ii) {} const Integer operator+(const Integer& rv) const { cout << "operator+" << endl; return Integer(i + rv.i); } Integer& operator+=(const Integer& rv) { cout << "operator+=" << endl; i += rv.i; return *this; } }; int main() { int i = 1, j = 2, k = 3; k += i + j; Integer ii(1), jj(2), kk(3); kk += ii + jj; } a) operator+ operator+= b) operator+= operator+ c) operator+ operator+ d) None of the mentioned

Answer:a Explanation:We are using two operator functions and executing them and result is printed according to the order. Output: $ g++ oper2.cpp $ a.out operator+ operator+=

How to declare operator function? a) operator operator sign b) operator c) operator sign d) None of the mentioned

Answer:a Explanation:We have to declare the operator function by using operator, operator sign. Example "operator +" where operator is a keyword and + is the symbol need to be overloaded.

What is the output of this program? #include <iostream> #include <complex> using namespace std; int main () { complex<double> mycomplex (20.0, 2.0); cout << imag(mycomplex) << endl; return 0; } a) 2 b) 20 c) 40 d) None of the mentioned

Answer:a Explanation:imag part will return the imaginery part of the complex number. Output: 2

What is the output of this program? #include <stdio.h> using namespace std; int main() { int a = 21; int c ; c = a++; cout << c; return 0; } a) 21 b) 22 c) 23 d) 20

Answer:a Explanation:value of 'a' will be stored in c and then only it will be incremented. Output: 21

What is the output of this program? #include <iostream> using namespace std; int main() { int a = 0; int b = 10; if ( a && b ) { cout << "true"<< endl ; } else { cout << "false"<< endl ; } return 0; } a) true b) false c) error d) None of the mentioned

Answer:b Explanation:&& is called as Logical AND operator, if there is no zero in the operand means, it will be true otherwise false. Output: $ g++ ess2.cpp $ a.out false

How many types of representation are in string? a) 1 b) 2 c) 3 d) 4

Answer:b Explanation:C++ provides following two types of string representations. They are C-style character string and string class type with Standard C++.

What do we need to do to pointer for overloading the subscript operator? a) reference pointer b) dereference pointer c) store it in heap d) None of the mentioned

Answer:b Explanation:If you have a pointer to an object of some class type that overloads the subscript operator, you have to dereference that pointer in order to free the memory.

What is the output of the following program? #include <iostream> using namespace std; class Box { public : double length; double breadth; double height; }; int main( ) { Box Box1; double volume; Box1.height = 5; Box1.length = 6; Box1.breadth = 7.1; volume = Box1.height * Box1.length * Box1.breadth; cout << "Volume of Box1 : " << volume <<endl; return 0; } a) 210 b) 213 c) 215 d) 217

Answer:b Explanation:In the above program, we are calculating the area of the cube by using the cube formula Output: $ g++ obj1.cpp $ a.out 213

Which one is used to refer to program elements in any translation units? a) internal linkage b) external linkage c) no linkage d) none of the mentioned

Answer:b Explanation:In the external linkage, it is used to refer to identifiers in various programs.

Which of the following header files is required for creating and reading data files? a) ofstream.h b) fstream.h c) ifstream.h d) console.h

Answer:b Explanation:In this fstream.h header file is used for accessing the files only.

What is the output of this program? #include <iostream> using namespace std; class numbers { private: int m_nValues[10]; public: int& operator[] (const int nValue); }; int& numbers::operator[](const int nValue) { return m_nValues[nValue]; } int main() { numbers N; N[5] = 4; cout << N[5]; return 0; } a) 5 b) 4 c) 3 d) 6

Answer:b Explanation:In this program, We are getting the values and returning it by overloading the subscript operator. Output: $ g++ sub1.cpp $ a.out 4

What is the output of this program? #include <iostream> #include <string> using namespace std; int main () { string str ("steve jobs is legend"); string::iterator it; str.erase (str.begin()+ 5, str.end()-7); cout << str << endl; return 0; } a) jobs is b) steve legend c) steve d) none of the mentioned

Answer:b Explanation:In this program, We are leaving the first 5 characters and last 7 characters and we are erasing the remaining the characters. Output: $ g++ stri3.cpp $ a.out steve legend

What is the output of this program? #include using namespace std; int operate (int a, int b) { return (a * b); } float operate (float a, float b) { return (a / b); } int main () { int x = 5, y = 2; float n = 5.0, m = 2.0; cout << operate (x, y); cout << operate (n, m); return 0; } a) 119 b) 102.5 c) 123.4 d) none of the mentioned

Answer:b Explanation:In this program, We are overloading the function and getting the output as 10 and 2.5 by division and multiplication. Output: 102.5

What is the output of this program? #include <iostream> #include <complex> using namespace std; int main() { complex<double> c1(4.0, 3.0); complex<float> c2(polar(5.0, 0.75)); cout << (c1 += sqrt(c1)) << endl; return 0; } a) (4.0, 3.0) b) (6.12132, 3.70711) c) (5.0, 0.75) d) None of the mentioned

Answer:b Explanation:In this program, we are adding both complex number and finding the square root of it. Output: $ g++ comp4.cpp $ a.out (6.12132,3.70711)

What is the output of this program? #include <iostream> using namespace std; class sample { public: sample(int i) : m_i(i) { } public: int operator()(int i = 0) const { return m_i + i; } operator int () const { return m_i; } private: int m_i; friend int g(const sample&); }; int f(char c) { return c; } int main() { sample f(2); cout << f(2); return 0; } a) 3 b) 4 c) 5 d) None of the mentioned

Answer:b Explanation:In this program, we are adding its value with it itself, So only we got the output as 4. Output: 4

What is the output of this program? #include <iostream> using namespace std; class sample { public: int x, y; sample() {}; sample(int, int); sample operator + (sample); }; sample::sample (int a, int b) { x = a; y = b; } sample sample::operator+ (sample param) { sample temp; temp.x = x + param.x; temp.y = y + param.y; return (temp); } int main () { sample a (4,1); sample b (3,2); sample c; c = a + b; cout << c.x << "," << c.y; return 0; } a) 5, 5 b) 7, 3 c) 3, 7 d) None of the mentioned

Answer:b Explanation:In this program, we are adding the first number of a with first number of b by using opertor function and also we are adding second number by this method also. Output: $ g++ oper.cpp $ a.out 7, 3

What is the output of this program? #include <iostream> using namespace std; class rect { int x, y; public: void val (int, int); int area () { return (x * y); } }; void rect::val (int a, int b) { x = a; y = b; } int main () { rect rect; rect.val (3, 4); cout << "rect area: " << rect.area(); return 0; } a) rect area:12 b) rect area: 12 c) rect area:24 d) none of the mentioned

Answer:b Explanation:In this program, we are calculating the area of rectangle based on given values. Output: rect area: 12

What does the dereference operator will return? a) rvalue equivalent to the value at the pointer address. b) lvalue equivalent to the value at the pointer address. c) it will return nothing d) none of the mentioned

Answer:b Explanation:It operates on a pointer variable, and returns an l-value equivalent to the value at the pointer address.

In which form does the function call operator can be overloaded? a) static member function b) non-static member function c) dynamis_cast d) static_cast

Answer:b Explanation:None.

Pick the other name of operator function. a) function overloading b) operator overloading c) member overloading d) None of the mentioned

Answer:b Explanation:None.

The fields in the class in c++ program are by default a) protected b) private c) public d) none of the mentioned

Answer:b Explanation:None.

What is the associativity of add(+); a) right to left b) left to right c) both of these d) None of the mentioned

Answer:b Explanation:None.

What is the defualt type oof linkage that are available for identifires? a) internal b) external c) no linkage d) none of the mentioned

Answer:b Explanation:None.

What is the use of function call operator? a) overloading the methods b) overloading the objects c) overloading the parameters d) none of the mentioned

Answer:b Explanation:None.

What is the user-defined header file extension in c++? a) cpp b) h c) hf d) none of the mentioned

Answer:b Explanation:None.

Which concepts does the preincrement uses? a) call by value b) call by reference c) queue d) None of the mentioned

Answer:b Explanation:None.

What is the scope of typedef defined data types? a) inside that block only b) whole program c) outside the program d) none of the mentioned

Answer:b Explanation:We are defining the user-defined data type to be availed only inside that program, if we want to use anywhere means we have to define those types in the header file.

What is the output of this program? #include <iostream> #include <complex> using namespace std; int main() { complex<double> c_double(2, 3); complex<int> c_int(4, 5); c_double *= 2; c_double = c_int; cout << c_double; return 0; } a) (2, 3) b) (4, 5) c) (8, 15) d) None of the mentioned

Answer:b Explanation:We are just copying the value of c_int into c_double, So it's printing as (4,5). Output: $ g++ comp1.cpp $ a.out (4,5)

What is the output of this program? #include <iostream> using namespace std; int main () { int a, b, c; a = 2; b = 7; c = (a > b) ? a : b; cout << c; return 0; } a) 2 b) 7 c) 9 d) 14

Answer:b Explanation:We are using the ternary operator to evaluate this expression. It will return first option, if first condition is true otherwise it will return second Output: $ g++ ess1.cpp $ a.out 7

How to declare the complex number? a) (3,4) b) complex(3,4) c) (3,4i) d) None of the mentioned

Answer:b Explanation:We can declare the complex number by using complex(3,4) where 3 is a real number and 4 is imaginary part.

To use external linkage we have to use which keyword? a) static b) extern c) const d) none of the mentioned

Answer:b Explanation:extern keyword is used to represent identifiers from other programs.

What is the name of | operator? a) sizeof b) or c) and d) modulus

Answer:b Explanation:| operator is used to find the 'or' of given values.

What is the output of this program? #include <iostream> using namespace std; class sample { int width, height; public: void set_values (int, int); int area () {return (width * height);} friend sample duplicate (sample); }; void sample::set_values (int a, int b) { width = a; height = b; } sample duplicate (sample rectparam) { sample rectres; rectres.width = rectparam.width * 2; rectres.height = rectparam.height * 2; return (rectres); } int main () { sample rect, rectb; rect.set_values (2, 3); rectb = duplicate (rect); cout << rectb.area(); return 0; } a) 20 b) 16 c) 24 d) None of the mentioned

Answer:c Explanation:In this program, we are using the friend function for duplicate function and calculating the area of the rectangle. Output: 24

What is the output of this program? #include <iostream> #include <string> using namespace std; int main () { string str ("microsoft"); string::reverse_iterator r; for (r = str.rbegin() ; r < str.rend(); r++ ) cout << *r; return 0; } a) microsoft b) micro c) tfosorcim d) tfos

Answer:c Explanation:'rbegin' is used to reverse the given the string. Output: tfosorcim

Which is used to return the number of characters in the string? a) length b) size c) both a & b d) None of the mentioned

Answer:c Explanation:Both will return the number of characters that conform the string's content.

Which is used to use a function from one source file to another? a) code b) declaration c) prototype d) none of the mentioned

Answer:c Explanation:By defining a function's prototype in another file means, we can inherit all the features from the source function.

Which is used to do the dereferencing? a) pointer without asterix b) value without asterix c) pointer with asterix d) value with asterix

Answer:c Explanation:Derefencing is using a pointer with asterix. For example, *(abc).

What does a default header file contain? a) prototype b) implementation c) declarations d) none of the mentioned

Answer:c Explanation:In the header file, we define something that to be manipulated in the program.

What is the output of this program? #include <iostream> #include <string> using namespace std; int main () { string str ("Ubuntu"); cout << str.capacity(); cout << str.max_size(); return 0; } a) 61073741820 b) 51073741820 c) 6 and max size depends on compiler d) none of the mentioned

Answer:c Explanation:In this program, We are printing the capacity and max size of the string. Output: $ g++ stri5.cpp $ a.out 61073741820

What is the output of this program? #include <iostream> using namespace std; ostream & operator<<(ostream & i, int n) { return i; } int main() { cout << 5 << endl; cin.get(); return 0; } a) 5 b) 6 c) error d) runtime error

Answer:c Explanation:In this program, there will arise an ambiguous overload for 5.

What is the output of this program? #include <iostream> using namespace std; int main() { char name[30]; cout << "Enter name: "; gets(name); cout << "Name: "; puts(name); return 0; } a) jobsjobs b) jobs c) compile time error d) program will not run

Answer:c Explanation:In this program,we need to string header file to run this program.

Pick out the correct statement. a) A friend function may be a member of another class. b) A friend function may not be a member of another class. c) A friend function may or may not be a member of another class. d) None of the mentioned

Answer:c Explanation:None.

What is the header file for the string class? a) #include<ios> b) #include<str> c) #include<string> d) None of the mentioned

Answer:c Explanation:None.

What is the use of no linkage? a) make the entity visible to other programs b) make the entity visible to other blocks in the same program. c) make the entity visible only to that block d) none of the mentioned

Answer:c Explanation:None.

Which keyword is used to define the user defined data types? a) def b) union c) typedef d) type

Answer:c Explanation:None.

Which of the following header file does not exist? a) <iostream> b) <string> c) <sstring> d) <sstream>

Answer:c Explanation:None.

subscript operator is used to access which elements? a) string b) char c) array d) all of the mentioned

Answer:c Explanation:None.

How to access the object in the class? a) scope resolution operator b) ternary operator c) direct member access operator d) none of the mentioned

Answer:c Explanation:Objects in the method can be accessed using direct member access operator which is (.).

What is the output of this program? #include <iostream> using namespace std; int main() { int x = 9; int* p = &x; cout << sizeof(p); return 0; } a) 4 b) 2 c) Depends on compiler d) none of the mentioned

Answer:c Explanation:The size of a datatype mainly depends on complier only. Output: $ g++ def3.cpp $ a.out 4

How many real types are there in complex numbers? a) 1 b) 2 c) 3 d) 4

Answer:c Explanation:There are three real types in complex numbers. They are float complex, double complex, long double complex.

How many specifiers are present in access specifiers in class? a) 1 b) 2 c) 3 d) 4

Answer:c Explanation:There are three types of access specifiers. They are public, protected and private.

How any types of linkage are there in c++? a) 1 b) 2 c) 3 d) 4

Answer:c Explanation:There are three types of linkage in c++. They are internal linkage, external linkage and no linkage.

How many types of user-defined data type are in c++? a) 1 b) 2 c) 3 d) 4

Answer:c Explanation:There are three types of user-defined data types. They are typedef, union, enumerator.

What is the output of this program? #include using namespace std; void duplicate (int& a, int& b, int& c) { a *= 2; b *= 2; c *= 2; } int main () { int x = 1, y = 3, z = 7; duplicate (x, y, z); cout << x << y << z; return 0; } a) 1468 b) 2812 c) 2614 d) none of the mentioned

Answer:c Explanation:We are passing the values by reference and modified the data on the function block. Output: $ g++ call1.cpp $ a.out 2614

What is the output of this program? #include <iostream> using namespace std; class sample { private: int var; public: void input() { cout << var; } void output() { cout << "Variable entered is "; cout << var << "\n"; } }; int main() { sample object; object.input(); object.output(); object.var(); return 0; } a) Enter an integer 5 Variable entered is 5 b) runtime error c) error d) none of the mentioned

Answer:c Explanation:While using private member, you can't access it variable.

What is the output of this program? #include <iostream> using namespace std; int main() { typedef int num; typedef char let; let w = "steve"; num a = 10, b = 15; num c = a + w; cout << c; return 0; } a) 10steve b) steve10 c) compile time error d) compile but not run

Answer:c Explanation:error: invalid conversion from 'const char*' to 'let {aka char}'

What is the output of this program? #include <iostream> using namespace std; class sample1 { float i, j; }; class sample2 { int x, y; public: sample2 (int a, int b) { x = a; y = b; } int result() { return x + y; } }; int main () { sample1 d; sample2 * padd; padd = (sample2*) &d; cout < result(); return 0; } a) 20 b) runtime error c) random number d) c or b

Answer:d Explanation:As it assigns to a reference to an object of another incompatible type using explicit type-casting. Output: 14032334

What is the output of this program? #include <iostream> #include <string> using namespace std; int main () { string str ("nobody does like this"); string key ("nobody"); size_t f; f = str.rfind(key); if (f != string::npos) str.replace (f, key.length(), "everybody"); cout << str << endl; return 0; } a) nobody does like this b) nobody c) everybody d) everybody does like this

Answer:d Explanation: rfind is used to find the characters in the string and replace is used to replace with certain characters. Output: everbody does like this

How many objects can present in a single class? a) 1 b) 2 c) 3 d) as many as possible

Answer:d Explanation:Because a class may contain any number of objects according to it's compliance.

Which of these following members are not accessed by using direct member access operator? a) public b) private c) protected d) Both b & c

Answer:d Explanation:Because of the access given to the private and protected, We can't access them by using direct member access operator.

What is the return type of the conversion operator? a) void b) int c) float d) no return type

Answer:d Explanation:Conversion operator doesn't have any return type not even void

What is the output of this program? #include <iostream> #include <cstring> using namespace std; int main () { char str1[10] = "Hello"; char str2[10] = "World"; char str3[10]; int len ; strcpy( str3, str1); strcat( str1, str2) len = strlen(str1); cout << len << endl; return 0; } a) 5 b) 55 c) 11 d) 10

Answer:d Explanation:In the program, We are concatanating the str1 and str2 and printing it's total length. So the length is 10. Output: $ g++ stri.cpp $ a.out 10

What is the output of this program? #include <iostream> using namespace std; int main() { int a, b; int* c; c = &a; a = 200; b = 200; *c = 100; b = *c; cout << *c << " " << b; return 0; } a) 100 200 b) 100 0 c) 200 200 d) 100 100

Answer:d Explanation:In this program, We are making the assignments and invoking the both b and c values as 100 by dereference operator. Output: 100 100

What is the output of this program? #include <stdio.h> using namespace std; int main() { int num1 = 5; int num2 = 3; int num3 = 2; num1 = num2++; num2 = --num3; cout << num1 << num2 << num3; return 0; } a) 532 b) 235 c) 312 d) 311

Answer:d Explanation:In this program, We are preincrementing and postincrementing the operands and saving it. Output: $ g++ incre5.cpp $ a.out 311

What is the output of this program? #include <iostream> using namespace std; class sample { private: int a, b; public: void test() { a = 100; b = 200; } friend int compute(sample e1); }; int compute(sample e1) { return int(e1.a + e1.b) - 5; } int main() { sample e; e.test(); cout << compute(e); return 0; } a) 100 b) 200 c) 300 d) 295

Answer:d Explanation:In this program, we are finding a value from the given function by using the friend for compute function. Output: 295

What is the output of this program? #include <iostream> using namespace std; class sample; class sample1 { int width, height; public: int area () { return (width * height);} void convert (sample a); }; class sample { private: int side; public: void set_side (int a) { side = a; } friend class sample1; }; void sample1::convert (sample a) { width = a.side; height = a.side; } int main () { sample sqr; sample1 rect; sqr.set_side(6); rect.convert(sqr); cout << rect.area(); return 0; } a) 24 b) 35 c) 16 d) 36

Answer:d Explanation:In this program, we are using the friend for the class and calculating the area of the square. Output: $ g++ friend2.cpp $ a.out 36

What is the output of this program? #include <iostream> using namespace std; class A { public: int x; A(int n = 0) : x(n) {}; int& operator[](int n) { cout << "0" ; return x; } int operator[](int n) const { cout << "1" ; return x; } }; void foo(const A& a) { int z = a[2]; } int main() { A a(7); a[3] = 8; int z = a[2]; foo(a); return 0; } a) 110 b) 111 c) 011 d) 001

Answer:d Explanation:In this program, we overloading the operator[] by using subscript operator. Output: $ g++ sub3.cpp $ a.out 001

What will happen when the function call operator is overloaded? a) It will not modify the functions. b) It will modify the functions. c) It will modify the object. d) It will modify the operator to be interpreted.

Answer:d Explanation:It will modifies how the operator is to be interpreted when applied to objects of a given type.

8. Which of the following statements is NOT valid about operator overloading? a) Only existing operators can be overloaded. b) Overloaded operator must have at least one operand of its class type. c) The overloaded operators follow the syntax rules of the original operator. d) None of the mentioned

Answer:d Explanation:None.

Pick out the other definition of objects. a) member of the class b) associate of the class c) attribute of the class d) instance of the class

Answer:d Explanation:None.

Which method do we use to append more than one character at a time? a) append b) operator+= c) data d) both a & b

Answer:d Explanation:None.

Which of the following is not a function of complex values? a) real b) imag c) norm d) cartesian

Answer:d Explanation:None.

Operator overloading is a) making c++ operator works with objects b) giving new meaning to existing operator c) making new operator d) both a & b

Answer:d Explanation:Operator overloading is the way adding operation to the existing operators.

Which other keywords are also used to declare the class other than class? a) struct b) union c) object d) both a & b

Answer:d Explanation:Struct and union take the same definition of class but differs in the access techniques.

What is the output of this program? #include <iostream> #include <string> using namespace std; int main () { string str ("Microsoft"); for (size_t i = 0; i < str.length();) { cout << str.at(i-1); } return 0; } a) M b) Microsoft c) Micro d) runtime error

Answer:d Explanation:This program will terminate because the cout element is out of range.

What does the data type defined by union will do? a) It allow one different portion of memory to be accessed as same data types b) It allow one same portion of memory to be accessed as same data types c) It allow one different portion of memory to be accessed as different data types d) It allow one same portion of memory to be accessed as different data types

Answer:d Explanation:Union is used to define the data types of our choice and it will store the data type in one location make them accessible.

What is the output of this program? #include <iostream> using namespace std; class Box { double width; public: friend void printWidth( Box box ); void setWidth( double wid ); }; void Box::setWidth( double wid ) { width = wid; } void printWidth( Box box ) { box.width = box.width * 2; cout << "Width of box : " << box.width << endl; } int main( ) { Box box; box.setWidth(10.0); printWidth( box ); return 0; } a) 40 b) 5 c) 10 d) 20

Answer:d Explanation:We are using the friend function for printwidth and multiplied the width value by 2, So we got the output as 20 Output: $ g++ friend.cpp $ a.out 20

Vectors

Contiguous memory. Pre-allocates space for future elements, so extra space required beyond what's necessary for the elements themselves. Each element only requires the space for the element type itself (no extra pointers). Can re-allocate memory for the entire vector any time that you add an element. Insertions at the end are constant, amortized time, but insertions elsewhere are a costly O(n). Erasures at the end of the vector are constant time, but for the rest it's O(n). You can randomly access its elements. Iterators are invalidated if you add or remove elements to or from the vector. You can easily get at the underlying array if you need an array of the elements.

lists

Non-contiguous memory. No pre-allocated memory. The memory overhead for the list itself is constant. Each element requires extra space for the node which holds the element, including pointers to the next and previous elements in the list. Never has to re-allocate memory for the whole list just because you add an element. Insertions and erasures are cheap no matter where in the list they occur. It's cheap to combine lists with splicing. You cannot randomly access elements, so getting at a particular element in the list can be expensive. Iterators remain valid even when you add or remove elements from the list. If you need an array of the elements, you'll have to create a new one and add them all to it, since there is no underlying array.

What is the output of this program? #include <stdio.h> using namespace std; int main() { int x = 5, y = 5, z; x = ++x; y = --y; z = x + ++x; cout << z; return 0; } a) 11 b) 12 c) 13 d) 14

View Answer Answer:d Explanation:In this program, we are adding the x value after preincrementing two times. Output: $ g++ incre4.cpp $ a.out 14


संबंधित स्टडी सेट्स

CompTIA A+: Guide to IT Technical Support (Chapter 1)

View Set

Chapter 4- Measurement Systems, Units, & Equivalencies

View Set

Immunity and the Allergic Response

View Set