CBSE - MCQ Question Banks (के. मा. शि. बो . -प्रश्नमाला )

PreviousNext

Q. 189901 If, a class object can be declared anywhere within the program, then it is called a


A. outer class.

B. local class.

C. global class.

D. super class.

Right Answer is: C

SOLUTION

A class is said to be a global class, if its definition occurs outside the bodies of all functions in a program.


Q. 189902 If the object is declared within the function body, then it is called a


A. local object.

B. global object

C. outer object.

D. inner object.

Right Answer is: A

SOLUTION

A local object can be accessed only within the function body and it cannot be used outside the function. A local object can be created from both types: local and global.


Q. 189903 If the object is declared outside all the function bodies, then it is called a


A. local object.

B. global object.

C. inner object.

D. outer object.

Right Answer is: B

SOLUTION

The global object is available to all the functions in the program, i.e., this object can be used anywhere in the program. A global object only is declared using a global class type.


Q. 189904 When a member function is called by another member function, it is known as


A. nested class.

B. enclosing class.

C. nesting of member functions.

D. binding of member functions.

Right Answer is: C

SOLUTION

The public member functions of a class can be invoked only by using an object of that class using a dot operator. However, a member function of the same class can call another member function of the same class using its name. We do not need an object to call them. When a member function is called by another member function, it is known as nesting of member functions.


Q. 189905 Accessor functions are also known as


A. setters.

B. getters.

C. mutator functions.

D. manager functions.

Right Answer is: B

SOLUTION

Accessor functions are those member functions that allow us to access the data members of an object. However, accessor functions cannot/do not change the value of data members.


Q. 189906 Interface is also known as


A. virtual class.

B. dependent class.

C. pure abstract class.

D. class.

Right Answer is: C

SOLUTION

Interface generally refers to an abstraction that an entity provides of itself to the outside. This separates the methods of external communication from internal operation and allows it to be internally modified without affecting the way outside entities interact with it, as well as provide multiple abstractions of itself.


Q. 189907 A class whose definition occurs outside bodies of all functions in program, is called


A. global class.

B. local class.

C. friend class.

D. nested class.

Right Answer is: A

SOLUTION

A class is said to be global class if its definition occurs outside the bodies of all functions in a program, which means that object of this class type can be declared from anywhere in the program.


Q. 189908 A good example of a method that is shared by all instance of a class is


A. a constructor.

B. an attribute.

C. a constructor and an attribute.

D. an overloading.

Right Answer is: A

SOLUTION

A constructor is a special member function which will construct an object with user-defined values whenever object is created. It is a special method used in OOP, which puts the object member into a valid state.


Q. 189909 The essential characteristics of an object which distinguish it from all other kinds of objects, is


A. aggregation.

B. abstraction.

C. modularity.

D. encapsulation.

Right Answer is: B

SOLUTION

Abstraction is focusing on the details of an object leaving behind the implementation details, which are not essential.


Q. 189910 Member functions with specific functions are called


A. mutator functions.

B. accessor functions.

C. manager functions.

D. inline functions.

Right Answer is: C

SOLUTION

Manager functions are member functions with specific functions (e.g., constructors and destructors) that deal with initializing and destroying class instances.


Q. 189911 Reusability of classes is one of the major characteristics of OOPS. It is implemented in C++ through


A. polymorphism.

B. inheritance.

C. data abstraction.

D. encapsulation.

Right Answer is: B

SOLUTION

Inheritance is the property by which derived class inherits the characteristics and properties of the base class and thus reuse it.


Q. 189912 A structure containing a member that is a pointer to the same structure type is referred to as


A. self–referential structure.

B. structure.

C. base structure.

D. derived structure.

Right Answer is: A

SOLUTION

Self–referential structures are the structure containing a member that is a pointer to the same structure type. Self–referential structures are useful for forming lined data structures such as linked lists, stacks and trees.


Q. 189913 Inline functions' defintions start with the keyword


A. abstract.

B. inline.

C. inlined.

D. inlining.

Right Answer is: B

SOLUTION

The inline functions are a C++ enhancement designed to speed up programs. The coding of the normal functions and inline functions is similar except that inline functions' definitions start with the keyword inline. An inline function definition should be placed above all the functions that call it.


Q. 189914 The disadvantage of inline function call is,


A. it increases time as function is invoked again and again.

B. a fragmentation of code.

C. its memory is wasted.

D. it does not return any value.

Right Answer is: C

SOLUTION

Whenever the function is invoked the same function code is inserted in the program for every function call, so memory is wasted.


Q. 189915 The number of access labels provided by class are


A. one.   

B. two.

C. three.

D. four.

Right Answer is: C

SOLUTION

There are 3 access labels provided by the class: private, protected and public.


Q. 189916 Overuse of inline function can cause


A. make programs slower.

B. code union.

C. insecurity of data.

D. encapsulation of data.

Right Answer is: A

SOLUTION

Inline functions improve performance by avoiding the overhead of the call itself but their overuse can lead to negative performance and make programs slower.


Q. 189917 A function is made inline function, when


A. it is very big just like macros.

B. it is very small and does not return any value or contain any static variables.

C. it contains static variables and return a value.

D. it is a very big function and does not contain any static variables.

Right Answer is: B

SOLUTION

An inline function is a function whose code gets inserted into the caller’s stream code. The functions should be inlined only when they are small. There is no point inlining large functions as there would be heavy memory penalty.


Q. 189918 Private members of a class are available to


A. only members outside the class.

B. only members of the class.

C. members of a program.

D. members of  a package.

Right Answer is: B

SOLUTION

Any member having private keyword is accessible to members within the class.


Q. 189919 void display (void); This code in C++ program signifies


A. member function.

B. data member.

C. object.

D. class.

Right Answer is: A

SOLUTION

There are two kinds of members in a class: data members and member functions. Data members are exactly like the variables in a structure and member functions act on data members in the class.


Q. 189920 Member access specifiers always end with


A. colon.

B. semicolon.

C. comma.

D. dot.

Right Answer is: A

SOLUTION

Member access specifiers like private, protected and public can appear any number of times in a class and they are always terminated with a colon (:).


Q. 189921 The code statement c3.add_complex(c1,c2); adds two complex numbers c1 and c2 and the result


A. will give an error in this case.

B. needs to be stored in another variable c4.

C. will return a value in another variable.

D. gets stored in c3 automatically.

Right Answer is: D

SOLUTION

There is no need to return a value, as the result gets stored in c3 when the function is called.


Q. 189922 We can give additional meaning to operators in C++ using


A. function overloading.

B. operator overloading.

C. virtual pointers.

D. polymorphism.

Right Answer is: B

SOLUTION

By overloading operators like +,*,-which are supposed to work on standard data types like ints, floats etc, they can work differently. Example, by overloading + operator it can be used to add two strings which is not possible in c.


Q. 189923 The default arguments are given in the


A. function prototype only.

B. function definition.

C. function parameter.

D. function calling.

Right Answer is: A

SOLUTION

In C++, we have an option to define default values for arguments that are not passed when the function call is made. The compiler uses the prototype information to build a call, not the function definition.


Q. 189924 A class having another class definition inside its defintion is called


A. nested class.

B. inner class.

C. disclosing class.

D. enclosing class.

Right Answer is: D

SOLUTION

A class may be declared within another class. A class declared within another class is called a nested class. The outer class is known as enclosing class and the inner class is known as nested class.


Q. 189925 The operator, which allocates memory from free store, is


A. delete.

B. new.

C. malloc( ).

D. free( ).

Right Answer is: B

SOLUTION

The new operator, when used with the pointer to a data type, a structure, or an array, allocates memory for the item and assigns the address of that memory to the pointer.


Q. 189926 A member function of a class that does not alter any data in the class is known as a


A. constant member function.

B. manager function.

C. mutator function.

D. accessor function.

Right Answer is: A

SOLUTION

A constant member function is denoted using the keyword const. The qualifier const appears both in member function declarations and definitions. Once a member function declared as const, it cannot alter data values of the class.


Q. 189927 Member functions of a class can be accessed


A. by a object of another class.

B. using scope resolution operator by an object of different class.

C. using dot operator by an object of that class.

D. by constructor of that class.

Right Answer is: C

SOLUTION

Member function is always called to operate on the specific object, not on the class in general. It is accessed using dot operator, which is also known as “ class member access operator ”.


Q. 189928 Member functions are functions defined within a class that act on


A. the data members in the class.

B. the data members outside the class.

C. the methods within the class.

D. the objects.

Right Answer is: A

SOLUTION

There are two kinds of members in a class: data members and member functions. Data members are exactly like the variables in a structure and member functions act on data members in the class.


Q. 189929 A function declared within the definition of a class is called


A. data.

B. method.

C. variable.

D. scope resolution operator.

Right Answer is: B

SOLUTION

A class is a collection of data types and functions, which operate on them. The functions defined within a class, are known as member functions or methods.


Q. 189930 Mutators are also known as


A. setters.

B. getters.

C. manager functions.

D. accessor functions.

Right Answer is: A

SOLUTION

Mutator functions are also known as setters. these are the member functions that allow us to change the data members of an object.


Q. 189931 Private keyword is used in C++ to implement a concept called


A. data binding.

B. data hiding.

C. security.

D. polymorphism.

Right Answer is: B

SOLUTION

When we use private keyword it means that data is accessible within a class and it cannot be accessed outside the class. thus maintain data hiding.


Q. 189932 Like a structure, the body of the class is terminated by


A. colon.

B. comma.

C. semicolon.

D. colon.

Right Answer is: C

SOLUTION

The body of a class is delimited by braces and terminated by semicolon.


Q. 189933 The process of creating an object is called


A. object creation.

B. object formation.

C. instantiation.

D. instant object.

Right Answer is: C

SOLUTION

An object is an instance of a class. It is the root of class hierarchy and the process of creating it is called instantiation.


Q. 189934 Can we declare an array of a structure with a nested structure?  Give an example.
A. object creation.
B. object formation.
C. instantiation.
D. instant object.

Right Answer is:

SOLUTION

Yes we can.  Consider the structure definition below- 

struct date{ int day;

                 int mon;

                 int year;

             };

 

struct employee{

                   int ecode;

                   char ename[20] ;

                   char addr[30]   ;

                   date dob;

                   };

The array of structures is declared as -       employee E[10];

Simple members may accept data as -         cin>>E[i].ecode;

Members of nested structure date can accept data as -

    cin>>E[i].dob.day;

    cin>>E[i].dob.mon;

    cin>>E[i].dob.year;

where i is the array index.                  

              


Q. 189935 An array holds numbers of items of same data type. How is it possible to store number of items of different data types?
A. object creation.
B. object formation.
C. instantiation.
D. instant object.

Right Answer is:

SOLUTION

An arrya is used to hold homogeneous data types. To store items of different data types we can use structures. A structure is a collection of variables under a single name. Varibales can be of any data type like int, float, char,etc.


Q. 189936 Is there any way out to group data of different types as one entity?
A. object creation.
B. object formation.
C. instantiation.
D. instant object.

Right Answer is:

SOLUTION

Yes, we can group data of different types using structures. A structure is a collection of variables types grouped together. Structures are useful whenever a lot of data needs to be grouped together. For example, when dealing with the students in a college, many variables of different types are needed like name, address, age, grade, subject. All these are grouped under one entity, i.e. structure.


Q. 189937 Identify errors in the following structure definition-
               struct info{ int flatno;                                     char building[20];                                     char city[15];                                      int pincode;                                     date date_purchased;                                 } ;                   struct date{ int day;                                     int mon;                                     int year;                                 } ;
A. object creation.
B. object formation.
C. instantiation.
D. instant object.

Right Answer is:

SOLUTION

Structure date is a nested member of struct info, it should be defined before info.                


Q. 189938 Define a structure  for the information provided –  Use appropriate data types.
 
NAME CLASS ROLLNO DATE_OF_BIRTH ADDRESS
             
      DAY HOUSE NO
      MONTH AREA
      YEAR CITY
        PINCODE
             
 
A. object creation.
B. object formation.
C. instantiation.
D. instant object.

Right Answer is:

SOLUTION

          struct date{ int day;
                                  int mon;

                                  int year;

                                } ;

 

                struct addrs{  int houseno;

                                    char area[20];

                                    char city[15]; 

                                    long pincode;

                                } ;

 

                struct student{ char name[15];

                                      char class[6];

                                      int rollno;

                                      date date_of_birth;

                                      addrs address;

                                } ;                                                   


Q. 189939 Given the following definitions and declarations, answer the questions that follow –
          struct date{ int day;                                   int mon;                                   int year;                               } ;             struct DATE{ int day;                                    int mon;                                    int year;                               } ;             date d1,d2;           DATE D1,D2;           Which of the following are incorrect?  Why ?          i)    d1=d2;                   ii)   D1=d2;          iii)  date d3={22,8,2005};          iv)  date d4;  d4={12,2,2005};          v)   DATE D={4,3,1999};          vi)  d1.day=D1.day;     
A. object creation.
B. object formation.
C. instantiation.
D. instant object.

Right Answer is:

SOLUTION

i)    d1=d2;                              Correct – same data type

ii)   D1=d2;                              Incorrect, D1 and d2 are different data types, DATE and date

iii)  date d3={22,8,2005};          Correct, initialization possible    

iv)  date d4;  d4={12,2,2005};   Incorrect, for a declared variable, assign values to members 

v)   DATE D={4,3,1999};           Correct    

vi)  d1.day=D1.day;                  Correct, both are the same data type i.e. int              


Q. 189940 What are macros?  Give an example.
A. object creation.
B. object formation.
C. instantiation.
D. instant object.

Right Answer is:

SOLUTION

A macro is an operation defined in #define  preprocessor directive. Macros may be equivalent to expressions, complete statements or groups of statements.  A macro defined in one file is not recognized in another file.  Macro definitions are placed at the beginning of the file.

#include< iostream.h>                                #include< iostream.h>

#define area l*b                                        #define square(a) a*a

void main(){                                              void main(){

  int l,b;                                                    int a=5;

  cout<<"enter length : "; cin>>l;                  cout<< square(a);

  cout<<"nbreadth : "; cin>>b;                      } 

  cout<<"area = "<< area;

}

After preprocessing, in Example 1 area will be replaced by l*b and in Example 2 square(a) will be replaced by a*a.  


Q. 189941 Write a program to accept roll number, class, name  and marks in English, Science, Math, Social Science subjects of students. Also display the total of the marks.  Use a structure with appropriate variables.
A. object creation.
B. object formation.
C. instantiation.
D. instant object.

Right Answer is:

SOLUTION

//using simple structures
          #include < iostream.h>

#include < conio.h>

struct S{

          char clas[6];

          int rollno;

          char name[20];

  int eng;

  int science;

  int math;

  int socsc;

};

 

void main(){

   S s;

   char c;

   clrscr();

   cout<<"Class and Section : ";cin.getline(s.clas,6);

   cout<<"Roll number : ";cin>>s.rollno;

   c=cin.get();

   cout<<"nName : ";cin.getline(s.name,20);

   cout<<"nEnglish marks : ";cin>>s.eng;

   cout<<"nScience marks : ";cin>>s.science;

   cout<<"nMath marks : ";cin>>s.math;

   cout<<"nSoc.Science Marks : ";cin>>s.socsc;

   cout<<"n Total = "<< s.eng+s.science+s.socsc+s.math;

   getch();

}                                              


Q. 189942 Write a program to accept roll number, class, name  and marks in English, Science, Math, Social Science and display the total.  Use a structure with appropriate variables.
A. object creation.
B. object formation.
C. instantiation.
D. instant object.

Right Answer is:

SOLUTION

//using simple structures
          #include < iostream.h>

#include < conio.h>

struct S{

          char clas[6];

          int rollno;

          char name[20];

  int eng;

  int science;

  int math;

  int socsc;

};

 

void main(){

   S s;

   char c;

   clrscr();

   cout<<"Class and Section : ";cin.getline(s.clas,6);

   cout<<"Roll number : ";cin>>s.rollno;

   c=cin.get();

   cout<<"nName : ";cin.getline(s.name,20);

   cout<<"nEnglish marks : ";cin>>s.eng;

   cout<<"nScience marks : ";cin>>s.science;

   cout<<"nMath marks : ";cin>>s.math;

   cout<<"nSoc.Science Marks : ";cin>>s.socsc;

   cout<<"n Total = "<< s.eng+s.science+s.socsc+s.math;

   getch();

}                                              


Q. 189943 Write a program to store record of an employee using structures.
A. object creation.
B. object formation.
C. instantiation.
D. instant object.

Right Answer is:

SOLUTION

#include< iostream.h>
#include< conio.h>

struct Addr
{
int eno;
char name[20];
char address[20];
};

struct Employee
{

int sal;
char dept[20];
Addr ad;

};

void main()
{

Employee emp;
cout<< "nEnter EmpNo:";
cin>> emp.ad.eno;
cout<< "nEnter Name: ";
cin>> emp.ad.name;
cout<< "nEnter sal: ";
cin>> emp.sal;
cout<< "nEnter Dept: ";
cin>> emp.dept;
cout<<"nEnter Address: ";
cin>> emp.ad.address;


cout<< "nEmployee Record: ";

cout<< "Name:"<< emp.ad.name;

cout<< "nEmpNo: "<< emp.ad.eno;

cout<< "nSalary: "<< emp.sal;

cout<< "nDept: "<< emp.dept;

cout<< "nAddress: "<< emp.ad.address ;

}


Q. 189944 Write a program to accept basic data of a class of students (35 in number).  Data includes first name, last name, date of birth, admission number, contact phone.   On giving any admission number, all details should appear on the screen.
A. object creation.
B. object formation.
C. instantiation.
D. instant object.

Right Answer is:

SOLUTION

 //using array of structures

#include < iostream.h>

#include < conio.h>

struct date{

  int dd;

  int mm;

  int yy;

};

struct S{

  int admno;

  char fname[10];

  char lname[10];

  long phone;

  date dob;

};

void main(){

  S s[35];

  int i,adno;

  char c;

  clrscr();

  for(i=0;i<35;i++)

  {

   clrscr();

   cout<<"Admission Number : ";cin>>s[i].admno;

   c=cin.get();

   cout << c;

   cout<<"nFirst Name : ";cin.getline(s[i].fname,10);

   cout<<"nLast Name : ";cin.getline(s[i].lname,10);

   cout<<"nContact telephone : ";cin>>s[i].phone;

   cout<<"n date of birth - day :";

   cin>>s[i].dob.dd;

   cout<<"n  month :";

   cin>>s[i].dob.mm;

   cout<<"n year :";

   cin>>s[i].dob.yy;

   getch();

  }

  clrscr();

  cout<<"Enter Admission Number : "; cin>>adno;

  for(i=0;i<35;i++)

  {

   if (adno= =s[i].admno)

   {

   cout<<"nName : "<< s[i].fname << ' '<< s[i].lname ;

   cout<<"nContact Telephone : "<< s[i].phone;

   cout<<"nDate of Birth = "<< s[i].dob.dd<< '-'<< s[i].dob.mm<< '-'<< s[i].dob.yy;

   break;

   }

  }

  getch();

}                                               


Q. 189945 Write a program in C++ that passes date variables to a function for validation.
A. object creation.
B. object formation.
C. instantiation.
D. instant object.

Right Answer is:

SOLUTION

//passing a date variable to a function by value 
           #include < iostream.h>
         #include < conio.h>

            struct date{ int day;

                 int mon;

                 int year;

               };

 

void main()

{

  date d;

  int val;

  clrscr();

  int valid(date);

  cout<<"nEnter date  - day :";

  cin>>d.day;

  cout<<"n month :";

  cin>>d.mon;

  cout<<"n year :";

  cin>>d.year;

  val=valid(d);

  if (val==1)

    cout<< "nValid date";

  else

    cout<<"nInvalid date";

  getch();

}

int valid(date dt){

  int v; v=0;

  int days[]={31,28,31,30,31,30,31,31,30,31,30,31};

  if(dt.mon==2 && dt.day==29 && dt.year%4==0)

    v=1;

  else

  if (dt.mon<1 || dt.mon>12)

       v=0;

  else

  for(int i=0;i<12;i++){

    if (dt.day<=days[dt.mon-1])

         v=1;

         break;

  }

  return v;

}                                          


Q. 189946 Write a program in C++ to show teacher's details using structure.
A. object creation.
B. object formation.
C. instantiation.
D. instant object.

Right Answer is:

SOLUTION

#include< iostream.h>
#include< conio.h>
struct Teacher
{
 int id;
 char name[20];
 char quali[20];
 char desig[20];

}t={111,"Soumya","MCA","TGT"};

void main()
{
cout<< "nTeachers Record: ";
cout<< "Name:"<< t.name;
cout<< "nId: "<< t.id;
cout<< "nQualification: "<< t.quali;
cout<< "nDesignation: "<< t.desig;
}


Q. 189947 Write a program to store the record of a student using nested structure.
A. object creation.
B. object formation.
C. instantiation.
D. instant object.

Right Answer is:

SOLUTION

#include< iostream.h>
#include< conio.h>

 

struct Info
{
 int rno;
 char name[20];
};

struct Student
{

 int clas;
 int mks;
 Info ob;

}s1={12,345};

void main()
{
cout<< "nEnter Name: ";
cin>>s1.ob.name;
cout<< "nEnter Rno: ";
cin>>s1.ob.rno;
cout<< "nStudent Record: ";
cout<< "Name:"<< s1.ob.name;
cout<< "nRollNo: "<< s1.ob.rno;
cout<< "nClass: "<< s1.clas;
cout<< "nMarks: "<< s1.mks;

}        


Q. 189948 Write a program in C++  to define a structure ITEM with members to store item code, name, unit cost and quantity in stock.  Accept data for at least ten items.  Any item with 0 quantity in stock should be passed to a function that will update it to 100.
A. object creation.
B. object formation.
C. instantiation.
D. instant object.

Right Answer is:

SOLUTION

 //passing to a function by reference.
           
           #include < iostream.h>
           
           #include < conio.h>
            
           struct ITEM
          {
 
                int icode;
             char iname[20];
             int unit_cost ;

       int qty_in_stock;

};

void main()

{

  ITEM I[10];

  char c;

  void update(ITEM&);

  for(int i=0;i<10;i++)
            {

   clrscr();

   cout << "Enter item code : ";

   cin >> I[i].icode;

   c = cin.get();

   cout << "Enter item name : " << c;

   cin.getline(I[i].iname,20);

   cout<<"Enter unit cost : ";

   cin >> I[i].unit_cost;

   cout << "Enter quantity in stock :";

   cin >> I[i].qty_in_stock;

   }

  for(i=0;i<10;i++)
            {

   if(I[i].qty_in_stock==0)

   update(I[i]);

  }

  for(i=0;i<10;i++)
            {

   cout << "Code : " << I[i].icode;

   cout << "Name : "<< I[i].iname;

   cout << "Unit Cost : " << I[i].unit_cost;

   cout << "Current Stock : " << I[i].qty_in_stock;

  }
             getch();

}

void update(ITEM &item)
          {

 item.qty_in_stock=100;

}                                                       


Q. 189949 The statement int s:: count =10; is 


A. the declaration of static data member count of class s.

B. the definition of static data member count of class s, that initializes count with value 10.

C. both declaration and definition of static data member count of class s, assigning value 10 to count.

D. declaration of static data member count of class s, and giving default value 10 to count.

Right Answer is: B

SOLUTION

It is the definition of a static data member count of class s and data member count is given initial value 10 at the time of definition.


Q. 189950 The class member that implements the OOP concept of data hiding is 


A. private.

B. public.

C. protect.

D. default.

Right Answer is: A

SOLUTION

Private members are the class members that are hidden from the outside world. The private members implement the OOP concept of data hiding. 


Q. 189951 The error in the following code is {
int a,b;
public
void read();
}


A. no class declaration only.

B. no class declaration and no colon after public.

C. no class declaration and no semicolon after public.

D. no colon after public keyword only.

Right Answer is: B

SOLUTION

A class declaration having class keyword and class-name is must for every class. There should be colon after all the access specifiers i.e. public, private and protected.


Q. 189952 The qualified name of a class member is


A.  

class-name :: class-member-name.

 

B. class-name : class-member-name.

C. :: class-name :: class-member-name.

D. :: class-name : class-member-name.

Right Answer is: A

SOLUTION

The scope resolution operator (::) is useful to distinguish between class member names and other names. For example,
class A
{
int x;
float y;
public:
void readm( ) const;
....
...
}; In this class the full qualified name of variable x is A::x.        


Q. 189953 When the implementation is substituted into the code where the function call is made, that function is defined as


A. friend.

B. inline.

C. virtual.

D. member function.

Right Answer is: B

SOLUTION

in inline function, at each place where there is a function call in the source file, the actual code from the function would be inserted, instead of a jump to the function.


Q. 189954 What is the precedence of the . (dot) operator?
A. friend.
B. inline.
C. virtual.
D. member function.

Right Answer is:

SOLUTION

It is less than the scope resolution operator ::, the parenthesis ( ) and array access [ ]  operators.   


Q. 189955 What do you understand by macros?
A. friend.
B. inline.
C. virtual.
D. member function.

Right Answer is:

SOLUTION

Macros are also given as preprocessor directives i.e. # define is used to define macros too. Macros may be equivalent to expressions, complete statements or groups of statements. They resemble functions but are treated differently during compilation. A macro defined in one file is not recognized in another file. Macro definitions are customarily placed at the beginning of the file.


Q. 189956 Name the different ways in which the entire structure can be passed to the functions?
A. friend.
B. inline.
C. virtual.
D. member function.

Right Answer is:

SOLUTION

The entire structure can be passed to the functions in two ways : by value and by reference. Passing by value is useful when the original values are not to be  changed and passing by reference is useful when original values are to be changed.        


Q. 189957
 
When is structure assignment possible?
A. friend.
B. inline.
C. virtual.
D. member function.

Right Answer is:

SOLUTION

Structure assignment is possible only if both the structures are of same structure type. Only assignment (=) is possible for two similar structures. Other operations, such as comparisons (== and !=) are not defined for similar structures.                


Q. 189958 Write the syntax for accessing a structure element.
A. friend.
B. inline.
C. virtual.
D. member function.

Right Answer is:

SOLUTION

The structure variable name followed by a period (.) and the element name reference to that individual structure element. The syntax for accessing a structure element is :
structure-name.element-name


Q. 189959 What keyword do we use for structures and how are members declared in a structure, by default?
A. friend.
B. inline.
C. virtual.
D. member function.

Right Answer is:

SOLUTION

In C++, a structure is a class declared with keyword struct and by default, all members are public in a structure.                          


Q. 189960 Create a structure Salesman which has three variables in it, i.e., id, salary, totalsales. Give one advantage of using structures.
A. friend.
B. inline.
C. virtual.
D. member function.

Right Answer is:

SOLUTION

struct Salesman
{
int id;
float salary;
int totalsales;
};
Structures are useful when a lot of data needs to be grouped together. Once defined, the structure name becomes a user defined data type and may be used the same way as other built-in data types.


Q. 189961 Declare and initialize an array of 3 structures that store rollno, name and marks in 3 subjects for students.
A. friend.
B. inline.
C. virtual.
D. member function.

Right Answer is:

SOLUTION

struct student

{ int rollno;

char name[20];

float marks[3];

};

student result[3]

{ {01,"Reena", {82.0,91.5,78.0} }, //structure 0

{02,"Aakash", {68.0,71.0,57.0} }, // structure 1

{03,"Venkat", {61.0,59.0,70.0} }, // structure 2

};

 

 


Q. 189962 What is structure template?
A. friend.
B. inline.
C. virtual.
D. member function.

Right Answer is:

SOLUTION

The structure is a user defined data type that acts as a template for creating variables of that type.
For Example –

struct date{ int day;

                 int mon;

                 int year;

               };

date acts as a template for variables that will have the same component members as given in the structure definition. 


Q. 189963 What is a self referential structure?
A. friend.
B. inline.
C. virtual.
D. member function.

Right Answer is:

SOLUTION

A self referential structure has an element that refers to the structure itself.  This is  actually a pointer that points to a structure of the same type.
For Example –

struct date{ int day;

                 int mon;

                 int year;

                 date *dt;

             };                                          


Q. 189964 Can we declare an array of a structure with a nested structure?  Give an example.
A. friend.
B. inline.
C. virtual.
D. member function.

Right Answer is:

SOLUTION

Yes we can.  Consider the structure definition below- 

struct date{ int day;

                 int mon;

                 int year;

             };

 

struct employee{

                   int ecode;

                   char ename[20] ;

                   char addr[30]   ;

                   date dob;

                   };

The array of structures is declared as -       employee E[10];

Simple members may accept data as -         cin>>E[i].ecode;

Members of nested structure date can accept data as -

    cin>>E[i].dob.day;

    cin>>E[i].dob.mon;

    cin>>E[i].dob.year;

where i is the array index.                  

              


Q. 189965 Distinguish between a class and a structure.
A. friend.
B. inline.
C. virtual.
D. member function.

Right Answer is:

SOLUTION

A class is declared using the keyword class while a structure needs the keyword struct. All members are private by default in a class while in a structure they are public. Traditionally, structures are used to declare data only while classes have both data and functions.


Q. 189966 Differentiate between an array and a structure.
A. friend.
B. inline.
C. virtual.
D. member function.

Right Answer is:

SOLUTION

Array elements are all of the same data type while in a structure they may not be.  In an array, individual elements are accessed using the index number (or subscript) while in a structure, a dot is used to access members.                


Q. 189967 Define preprocessor commands.
A. friend.
B. inline.
C. virtual.
D. member function.

Right Answer is:

SOLUTION

Preprocessor commands are called DIRECTIVES and begin with a pound / hash symbol(#). No white space should appear before the # and a semi colon is NOT required at the end.

 


Q. 189968 Give two examples of preprocessor directives.
A. friend.
B. inline.
C. virtual.
D. member function.

Right Answer is:

SOLUTION

# define and #include are two commonly used preprocessor directives.
#include< iostream.h > - this is an instruction to include the file iostream.h 
#define  PI   3.14        - this defines a symbolic constant PI and replaces every PI in the program with 3.14  

 


Q. 189969 What is the use of typedef?
A. friend.
B. inline.
C. virtual.
D. member function.

Right Answer is:

SOLUTION

typedef is a keyword used to give an alternative name to an existing data type. Once a structure has been declared, typedef can be used to give it an alias. Then onwards,  both the names for the data type can be used. 
Example  -
typedef long telephone;          // telephone can also be used to declare variables of long type

telephone office, residence;

long neighbour;

typedef float money;              // float and money both can be used to declare float variables

float amount;

money interest;                                                                          


Q. 189970 What happens when a pointer to a structure is incremented?
A. friend.
B. inline.
C. virtual.
D. member function.

Right Answer is:

SOLUTION

It is incremented by the size of the structure.                                   


Q. 189971 Declare a structure Customer with following variables:
custnum, salary and commission.
A. friend.
B. inline.
C. virtual.
D. member function.

Right Answer is:

SOLUTION

struct Customer
{
int custnum;
int salary:
float commission:
};


Q. 189972 Explain with an example the self referential structure?
A. friend.
B. inline.
C. virtual.
D. member function.

Right Answer is:

SOLUTION

A self referential structure is used to create data structures like linked list, stacks, etc. It has an element that refers to the structure itself.  This is actually a pointer that points to a structure of the same type.
For Example –

struct node

{
              int data;
              node*next;

}

        


Q. 189973 Why are structures generally defined globally, i.e. outside any function?
A. friend.
B. inline.
C. virtual.
D. member function.

Right Answer is:

SOLUTION

The structures are defined globally so that variables of this structure type can be declared in any function. A structured declared within a function is available only to that function.                             


Q. 189974 The act of representing essential features without including background details is termed as 


A. polymorphism.

B. encapsulation.

C. abstraction.

D. inheritance.

Right Answer is: C

SOLUTION

Simplified view of object that includes only features in which one is interested in and hides unnecessary details is known as data abstraction. For example, while driving a car, we are not concerned about the hidden parts such as fuel injection, disk brake etc.


Q. 189975 The function which has different compilation process, other than the normal functions 


A. constant member function.

B. scope resolution operator.

C. inline function.

D. nesting of member function.  

Right Answer is: C

SOLUTION

Inline functions speed up the program. The only difference between inline functions and  the normal functions is that inline functions' definitions start with the keyword inline. 


Q. 189976 The getRollno( ) is an example of


A. accessor function.

B. mutator function.

C. manager function.

D. constant member function.

Right Answer is: A

SOLUTION

Accessor member functions allow us to access field of object but cannot change the value of data members. For example, getRollno( ) and getMarks( ) which can read the roll number and marks of a student, respectively.


Q. 189977 The advantage of using mutator is -


A. it saves time.

B. it doesn't produce compile time error.

C. it reduces size of the program.

D. data is edited in desired manner.

Right Answer is: D

SOLUTION

By providing accessors and mutators, we make sure that data is edited in desired manner through a mutator. Further, if a user wants to know current value of a private data member, s(he) can get it through an accessor function. Accessor and mutators are also called getters and setters.


Q. 189978 When a member function is called by another member function, it is called 


A. member functions.

B. nesting of member functions.

C. calling of member functions.

D. inlining of member functions.

Right Answer is: B

SOLUTION

The public members of a class can be invoked only by using an object of that class using a dot operator. However, a member function of the same class can call another member function of the same class using its name. We do not need an object to call them. It is known as nesting of member functions.


Q. 189979 The private data in the following code is 
class Test
{
     int a;
    double b;
  public:
     int c;
     void add();
     void print();
     ....
     ...
};                         


A. a and b.

B. only a.

C. add( ) and print( )

D. a, b and c

Right Answer is: A

SOLUTION

The private members can be accessed only from within the class. A class specification involves the declarations of its data member and member functions. There are two ways to layout a class definition. The first way is to place the private data before the public functions and data. The second way is to place the public members first, followed by protected and private members.


Q. 189980 Which of the below given lines will not work and Why?

            1.                class A{ 2.                   int a; 3.                   class B{ 4.                       int b; 5.                     public: 6.                       void dispb(){b=456;cout<<"b="<< b;} 7.                    }; 8.                  public: 9.                     void disp(){a=123;cout<<"a="<< a;}  10.            }; 11.           void main(){ 12.               A a1; 13.               a1.disp(); 14.               A::B b1; 15.               b1.dispb(); 16.           }


A. 9 – no objects declared for class B in class A

B. 3 - class B declared under private

C. 12 – a1 shows no reference to B

D. 14, 15 - B is declared under private in the class A, so, cannot be accessed.

Right Answer is: D

SOLUTION

The private data members can be accessed only from the member functions of the class.


Q. 189981 The concept  illustrated in the given code below is

                class A{         ......   class B{     ......    }; }; A o1; 


A. nested class

B. polymorphism

C. containership

D. inline object

Right Answer is: A

SOLUTION

A class declared within another class is called as nested class. The outer class is known as enclosing class and the inner class is known as nested class.


Q. 189982 The nested class can access public members of its enclosing class


A. using a member function.

B. using a dollar sign.

C. using an object only.

D. using the name of the enclosing class.

Right Answer is: C

SOLUTION

The nested class can access public members of its enclosing class using an object only.The same applies for enclosing class also i.e., it can access public members of nested class through an object.


Q. 189983 Constructor and Destructor can be called as


A. manager functions.

B. mutator functions.

C. accessor functions.

D. inline functions.

Right Answer is: A

SOLUTION

Manager functions are member functions with specific functionality (e.g., constructors and destructors) that deal with initializing and destroying class instances.


Q. 189984 Consider the following code
#include< iostream.h >
void main()
{
    int a, b;
    cin >> a >> b;
    int s = sum(a, b);
    cout << s;
}
void sum(int a, int b)
{
    cout << (a+b);
}

The error(s) in the code is / are  


A. Incorrect header file included.

B. cin >> a >> b;

C. int sum(int a, int b){return (a+b)}

 

D. cout << s;

Right Answer is: C

SOLUTION

The sum function should be so defined to calculate and return the summation result of the given values to the calling function. Therefore, the sum function should be corrected as:
#include< iostream.h >
void main()
{
    int a, b;
    cin >> a >> b;
    int s = sum(a, b);
    cout << s;
}
int sum(int a, int b)
{
    return (a+b);
}


Q. 189985 When one class may have another class defined within it, it is known as


A. encapsulation.

B. nesting.

C. polymorphism.

D. abstraction.

Right Answer is: B

SOLUTION

One class may have another class defined within it, known as nested class. One way of doing so is that a class contain objects of other classes as its members as shown below:
class X
{
   ...
   ...
} class Y
{
    ...
    ...
} class Z
{
  X O1;
  Y O2;
  ...
};  


Q. 189986 Identify the errors in the following code fragment :  

  class X  {           
         int x;          
         static int ctr;    
   public :           
        void init(void)           
        {              
              x = ctr = 0;           
        }         
        static void prn(void)          
       {        
               cout << ctr << x;       
        
       }  
   };


A. declaration of variables cannot be done without access specifier  

B. a function cannot have void as parameter

C. cannot use static modifier with datatypes

D. a static member function is accessing a non-static member

Right Answer is: D

SOLUTION

The static member functions are the functions that can access only the static members. So, in the above code fragment a static member function is trying to access a nonstatic member which is the error.

To correct it the static member function should be as given below :       static void prn(void)      {           cout << ctr;      }      


Q. 189987 The header file to which the abs() function belong to is


A. string.h

B. conio.h

C. math.h

D. ctype.h

Right Answer is: C

SOLUTION

math.h is a header file in the standard library of the C++ programming language designed for basic mathematical operations.


Q. 189988 Consider the following code
class Test
{
   private : int Marks[7];
                 char subjects[20];
   protected :
         char stream[20];
   public:
          void Reportcard();
};   
   The OOP feature that can be depicted from the above code is


A. polymorphism.

B. data hiding.

C. inheritance.

D. nesting.

Right Answer is: B

SOLUTION

In the given code, only the public members are accessible by outside of the class. Data Hiding term is used so that only relevant information is exposed to the user and rest of the information remains hidden from the user. The class groups its members (data and functions) into three sections : private, protected and public, where private and protected members remains hidden from outside world and thereby support data hiding.


Q. 189989 A global object can only be declared using a


A. global class type.

B. private class type.

C. local class type.

D. nested class type.

Right Answer is: A

SOLUTION

A class is said to be global class if its definition occurs outside the bodies of all functions in a program, which means that object of this class type can be declared from anywhere in the program, An object is said to be a global object if its declared outside all the function bodies and it means that this object is globally available to all functions in the program i.e., this object can be used anywhere in the program.


Q. 189990 Count is a static integer variable declared in class X. Its declaration outside the class will be


A. static int X::Count:

B. int X::Count;

C. X::int count;

D. X::static count;

Right Answer is: B

SOLUTION

A static data member of a class is just like a global variable for its class. Two things are needed for making a data member static:
1. declaration within the class definition.
2. definition outside the class definition.

The declaration of a static data member within the class defintion will look like :
class X
{
  static int count ;
  ...
};

The definition of above declared static member count outside the class will be as follows:
int X :: count;

Therefore, the entire class definition would look like as:
class X
{
    static int count;
    ...
};
int X :: count;      


Q. 189991 The member functions are generally defined as public


A. so that they can access global variables.

B. so that they can call private members.

C. so that they can be easily modified.

D. so that they can be called from outside functions.

Right Answer is: D

SOLUTION

Member functions are set of operations that may be applied to objects of that class. The public members can be accessed from outside the class also therefore, it is preferred to define the member functions as public.


Q. 189992 A local object can be created from


A. only local class type.

B. only global class type.

C. both local and global class type.

D. only static class type.

Right Answer is: C

SOLUTION

An object is said to be a local object if it is declared within a function, which means that this object is locally available to the function that declares it and cannot be used outside the function declaring it.


Q. 189993 A parent-child relationship is similar to


A. inheritance.

B. polymorphism.

C. encapsulation.

D. modularity.

Right Answer is: A

SOLUTION

When a class is inherited all the functions and data member are inherited, although not all of them will be accessible by the member functions of the derived class. Similarly, a child inherits properties from both the parents.


Q. 189994 By default, members in a class are


A. data.

B. functions.

C. private.

D. public.

Right Answer is: C

SOLUTION

By default, all the members are public in a structure but private in a class. In a class, the data members are declared similar to the other variable declarations in C++ and the member functions are declared by providing their prototypes.


Q. 189995 The scope of public members is


A. independent of the object being used for referencing them.

B. dependent upon the object being used for referencing them.

C. not defined.

D. always fixed as global scope.

Right Answer is: B

SOLUTION

If the referencing object is a global object, then the scope of public members is also global, whereas if the referencing object is a local object, then the scope of public members is also local.


Q. 189996 Private class members can be accessed


A. only by public member functions.

B. only by the object.

C. by using the class name and scope resolution operator.

D. by other member functions of the same class.

Right Answer is: D

SOLUTION

Private members implement the concept of data hiding.They can be accessed only by member functions of the class in which they are declared.


Q. 189997 Protected members of the class


A. can be inherited.

B. cannot be accessed by member functions of the same class.

C. can be accessed by non-members functions.

D. cannot be inherited.

Right Answer is: A

SOLUTION

Protected members can be used only by member functions and friends of the class in which it is declared.


Q. 189998 If an object is declared as global, then definitely


A. the class must be global

B. function main( ) must be using it

C. the class must be defined in main ( )

D. it must be returned from a function

Right Answer is: A

SOLUTION

An object is said to be global object if it is declared outside all the function bodies.


Q. 189999 Member functions are generally defined as public


A. so that they can access global variables

B. so that they can call private members

C. so that they cannot be called from outside functions

D. so that they can be called from outside functions

Right Answer is: D

SOLUTION

There are three access specifiers: public, private and protected. Public members can be accessed by outside member functions also, whereas private members can be accessed by member functions within the class only. Member functions are generally defined as public so that they can be called from outside functions.


Q. 190000 A class declaration has-


A. keyword Class, followed by class-name, followed by members within braces

B. keyword Class, followed by private members and functions, within braces

C. keyword Class, followed by data members and functions within braces

D. keyword class, followed by class-name, followed by members within braces

Right Answer is: D

SOLUTION

For example: class class-name { data member member function() }


PreviousNext