Total Pageviews

Friday, August 15, 2008

DATA STRUCTURES

Object Oriented Programming:


1. List few features of object oriented programming.
Object oriented programming features:
Follows bottom up approach.
Emphasis is on data.
Programs are divided into objects.
Functions and data are bound together.
Communication is done through objects.
Data is hidden.
2. List features of procedure oriented programming.
Procedure oriented programming features:
Follows top down approach.
Emphasis is on procedure.
Programs are divided into functions.
Data moves around freely.
3. What are the basic concepts of OOPs?
The following are the basic concepts of OOPs:
Classes, Objects, Data abstraction and encapsulation, Polymorphism, Inheritance, Message Passing, and Dynamic Binding.
4. What is a class?
Class is an entity which consists of member data and member functions which operate on the member data bound together.
5. What is an object?
Objects are instances of classes. Class is a collection of similar kind of objects. When a class is created it doesn’t occupy any memory, but when instances of class is created i.e., when objects are created they occupy memory space.
6. What is data encapsulation?
Wrapping up of member data and member functions together in a class is called data encapsulation.
7. What is data abstraction?
Data abstraction refers to the act of providing only required features and hiding all the non-essential details for usage.
8. What are ADTs?
ADTs stand for abstract data types. Classes which provide data abstraction are referred to as ADTs.
9. What is inheritance?
The process of inheriting the properties of one object by another object is called inheritance.
10. What is polymorphism?
The feature of exhibiting many forms is called polymorphism.
11. What are the steps involved in message passing?
The following are the steps involved in message passing:
Creating classes, creating objects, and creating communication between objects.
12. What is dynamic binding?
The feature that the associated code of a given function is not known till run time is called dynamic binding.
13. What are the advantages of OOP?
Data hiding helps create secure programs.
Redundant code can be avoided by using inheritance.
Multiple instances of objects can be created.
Work can be divided easily based on objects.
Inheritance helps to save time and cost.
Easy upgrading of systems is possible using object oriented systems.
14. Give an example for object based programming language.
Ada is an example for object based programming language.
15. Write the features of object based programming language.
Data hiding, data encapsulation, operator overloading and automatic initialization and clear up of objects are the important features exhibited by object based programming languages.
16. Give some examples of pure object oriented languages.
Eiffel, Java, Simula, Smalltalk are some pure object oriented languages.
17. List the areas of applications of object oriented programming?
The following are few areas of applications of object oriented programming:
CAD/CAM systems
Office automation and decision support systems
Object oriented databases
Real time systems
Simulation and modelling.
18. What is the difference between structure in C and class in C++?
In C structure, by default the members are public. Whereas in C++ class, by default the members are private.
19. What are the sections in class specification?
There are basically two sections in class specification: Class declaration and class function definition.
20. Write the syntax for class declaration.
Syntax:
class
{
private:
variables;
functions;
public:
variables;
functions;
};
21. What are class members?
The variables and functions used in a class are called class members.
22. What are the visibility labels?
Private, public and protected are the visibility labels.
23. Give an example for class declaration.
Ex.:
class area
{
int r;
public:
void get(int r);
void area(int r);
};
24. How does a class provide data hiding?
Data hiding is provided by a class by the use of visibility label private which allows only the member functions to access the data declared as private.
25. What are the ways of defining member functions?
Member functions can be defined in two ways, one inside the class definition and the other outside the class definition.
26. Write the syntax for defining member functions inside the class.
Syntax:
class
{
private:
variables;
public:
variables:
return type
{
statements;
}
};
27. Write the syntax for defining member functions outside the class.
Syntax:
return type :: (arguments)
{
body;
}
28. What does member functions represent?
Member functions of a class represent the behaviour of a class.
29. Write the syntax for making an outside function inline?
Member functions can be made inline even though we define them outside the class by using the keyword inline.
Syntax:
class
{
variables;
public:
return type (arguments);
};
inline return type :: (arguments)
{
body;
}
30. What is an object?
A region of storage with associated semantics is called an object.
31. What is instantiation?
The process of creating objects from a class is called instantiation.
32. Define attribute.
Attribute is the property of an object and cannot exist independently.
33. What is null object?
Null object is an object of a class which is used to indicate that a real object of that class does not exist.
34. What is class invariant?
A class invariant is a condition that defines all valid states of an object. It ensures the proper working of class.
35. What is stack unwinding?
Stack unwinding is the process during exception handling when destructor is called for all local objects between the place where the exception was thrown and caught.
36. What are proxy objects?
Proxy objects are the objects that stand for other objects.
37. What is the other name for proxy objects?
Surrogates.
38. Write the syntax for accessing member functions?
Syntax: . (arguments);
39. How do you access member data?
Member data can be accessed in two ways.
a. Using the member functions.
b. Direct access through objects.
syntax: variable name =
40. What is nesting of member functions?
Calling of a member function from another member function of the same class is called nesting of member functions.
41. When is the memory space allocated for class?
The class doesn’t occupy any memory only the objects occupy the memory and is created only when the objects are declared.
42. What are the characteristics of a static member variable?
The following are the characteristics of a static member variable:
Static member variable is initialized to zero when the first object of class is created.
Visible only in the class.
Single copy of static member variable is created and used by all the objects of the class.
43. Why are the static member variables called class variables?
Static member variables are treated separately from a class object, and are related with a class directly, so they are called as class variables.
44. What are the characteristics of member functions?
The following are the characteristics of member functions:
Static member functions can be called directly using the class name.
Static member functions can access only static member variables or static member functions.
45. Write the syntax for accessing static member functions using class.
Syntax: :: ;
46. What is persistence?
Persistence is the property of object to persist in terms of identity, state and description regardless of the session that creates or utilizes them.
47. What is a modifier?
A modifier is a member function that changes the value of atleast one data member.
48. What is the other name for modifier?
Modifier is also called mutator.
49. What is an accessor?
The accessor is a function that doesn’t modify that state of an object.

50. What are arrays of objects?
Arrays of objects are the arrays of variables of type class.
51. How can you pass objects as function parameters?
Objects can be passed as function parameters in two ways:
Entire object is passes as a copy.
Only address of the object is passed.
52. What do you mean pass by value in terms of object?
Pass by value is the way of passing objects as function parameters in which only a copy of the object is passed and any changes made to the object inside the function doesn’t reflect in the original program.
53. What do you mean by pass by reference in terms of object?
Pass by reference is the way of passing objects as function parameters in which any changes made in the passed object reflect in the original object.
54. Which of the following is more useful “pass by value” or “pass by reference”?
Pass by reference is more useful because in this only address of the object is passed which avoids the need to send entire object.
55. What is the use of friend functions?
Friend functions are used to access the private members of a class, although it is not a member function of that class.
56. What are the characteristics of friend functions?
The following are the characteristics of friend functions:
It cannot access member variables directly and has to use object to do so.
It cannot be called using the object as it a normal function.
It has the objects as arguments.
It can be declared under any visibility label.
57. Write the syntax of friend function.
Syntax:
class
{
………..
………..
public:
friend void (arguments);
};
58. What is forward declaration?
When a function is used as a friend for 2 classes, as it takes arguments of 2 classes, the compiler is not aware of the 2nd class which is not declared, so Inorder to acknowledge the compiler about it, the 2nd class is declared at the beginning of the program, this declaration is called forward declaration.
59. Write the syntax of friend function using 2 classes.
class ; //forward declaration
class
{
………..
friend void (, );
};
class
{
……….
friend void (, );
};
void (arguments)
{
……….
}
60. Write the syntax for defining a pointer to a member variable?
Syntax: int ::* = & :: ;
61. What are local classes?
Classes defined inside a function or blocks are called local classes.
62. What are the limitations of local classes?
The following are the limitations of local classes:
Member functions should be defined inside the class.
Local classes cannot have static members.
The function in which local class is defined cannot access the private data of local class.
63. How can you make a member function constant?
Member function can be made constant by appending const keyword to the function prototype.
And these member functions cannot alter any data of the class.
64. Write the syntax for making a function constant.
Syntax: (arguments) const;
65. What is the use of the keyword mutable?
If there is a const object or function in which we require to modify a data item, then we can declare that data item as mutable so that we can modify it.
66. How is automatic initialization of objects done in C++?
Automatic initialization of objects is done using constructors.
67. What is a constructor?
Constructor is a member function which is used to initialize member data when the objects of the class are created.
68. What are the characteristics of a constructor?
The following are the characteristics of a constructor:
Constructor name should be same as class name.
It should be declared in public section.
It cannot return values.
Constructor is invoked automatically when objects are created.
It cannot be virtual.
It cannot be inherited.
Constructor can invoke new and delete for memory allocation.
Constructor address cannot be referred.
69. What is a default constructor?
A constructor without any arguments is called default constructor.
70. What are the types of constructors?
The following are the types of constructors:
Simple constructor
Parameterized constructor
Overloaded constructor
Copy constructor
Constructors with default arguments
Dynamic constructors
71. Write the syntax for simple constructor.
Syntax:
class
{
…………
public:
{ } //Simple constructor
};
72. Given an example for constructor.
class sum
{
int a, b;
public:
sum()
{
a=3;
b=4;
}
…………
};
73. What are parameterized constructors?
Parameterized constructors are the ones which can take arguments.
74. Write the syntax for parameterized constructor.
Syntax:
class
{
variable declaration;
public:
(arguments)
{
………..
}
};
75. Give an example for parameterized constructor.
class sum
{
int a, b;
public:
sum (int c, int d)
{
a=c;
b=d;
}
……………
};
76. What are the ways of passing arguments to constructors?
Arguments can be passed to constructors in 2 ways:
Explicit calling of constructor.
Ex. : sum s = sum(3, 4);
Implicit calling of constructor
Ex.: sum s(3, 4);
77. What are overloaded constructors?
Overloaded constructors are the one which share the same class name.
78. Give an example for overloaded constructors.
Ex.:
class sum
{
int a, b;
public:
sum () { }
sum (int a) {….}
sum (int a, int b) {……}
………………..
};
79. Give an example for constructor with default arguments.
Ex.:
sum (int a, int b=5) //constructor with default arguments
{
……….
}
……….
sum s(3); // value 5 is assigned for 2nd variable
80. What is copy constructor?
Copy constructor is used to declare and initialize objects from another object.
81. What is the limitation of copy constructor?
The limitation is that copy constructor is that copies the class object directly i.e., if the file has file pointers or dynamic memory allocation it will point to the same location.
82. What is copy initialization?
Copy initialization is the initialization process through copy constructor.
83. What are dynamic constructors?
The constructors which allocate memory at the time of creation of objects are called dynamic constructors.
84. What is the use of explicit keyword?
Explicit keyword is used to declare the construction to make the conversion explicit and a constructor declared as explicit cannot perform implicit conversion.
85. Write syntax for creating constant objects.
Syntax: const (arguments).
86. What is the limitation of constant objects?
A constant object can call only constant member functions.
87. What is a destructor?
Destructor is used to destroy the objects and release the memory occupied by the objects.
88. Write the syntax to call a destructor explicitly.
Syntax:
.~ ();
89. Can you overload a destructor?
No, a destructor cannot be overloaded.
90. How do you invoke a destructor?
Destructors are invoked automatically as and when the corresponding object is destroyed.
91. What is the use of member assignment operator?
Member assignment operator is used to copy a source object to the invoking target object in an assignment statement.
92. What is operator overloading?
Adding a special meaning to an operator apart from its normal function is called operator overloading.
93. What are the steps involved in operator overloading?
Operator overloading involves following steps:
Creation of class.
Declaring operator function in public section.
Defining the operator function.
94. Write the syntax of operator function.
Syntax:
:: operator op (arguments)
{
…………..
}
95. List the operators which cannot be overloaded.
The following are the list of operators that cannot be overloaded:
Scope resolution operator (::)
Sizeof operator
Class member access operators (., .*)
Conditional operator (?:)
96. When we use operator overloading do we use pass by reference or pass by value?
When operator overloading is used, we should use pass by reference.
97. What is the difference between friend functions and member functions when we overload binary operators?
When we overload binary operators member function requires only argument to be passed and friend function requires two arguments.
98. What is the difference between friend functions and member functions when we overload unary operators?
When we overload unary operators member function doesn’t require any arguments whereas friend function takes one argument.
99. Which operand is used to invoke operator function when we overload binary operator?
When we overload binary operator left hand operand is used to invoke operator function.
100. Which operand is used as an argument when we overload binary operator?
When we overload binary operator right hand operand is used as an argument.
101. What are the rules for overloading operators?
The following are the rules for overloading operators:
Basic meaning of operator cannot be changed.
Only the existing operators are overloaded.
Not all the operators can be overloaded.
Syntax rules of actual operators are to be followed.
102. Which operators cannot be used with friend functions for overloading?
The following operators cannot be overload when we use friend functions:
Assignment operator, function call operator, class member access operator, subscript operator.
103. Write the syntax for overloaded casting operator function.
Syntax:
operator ()
{
………
………
}
104. What is the difference between operator overloading and function overloading?
The difference is that operator overloading adds a special meaning to an operator apart from its normal function whereas function overloading defines many functions with same name but with different signatures.
105. When does a name clash occur?
A name clash occurs when a name is defined in more than place. Suppose if you use two different class libraries, there may be two classes with same name.
106. What are the conditions to be satisfied by conversion function?
The following conditions are to be satisfied by the conversion function:
It should be a class member.
It should be without any arguments.
There should be no return type.
107. Does C++ support automatic type conversion when we use user defined data types?
No, C++ doesn’t support automatic type conversion when we use user defined data types, they should be designed manually.
108. What is inheritance?
Inheritance is the process of creating a new class from an existing class.
109. What do you call the new class and the old class?
The new class is called derived class or subclass or child class and the old class is called base class or super class or parent class.
110. What is the use of inheritance?
Inheritance helps in code reusability, saves time and cost, and provides reliability.
111. Write the syntax for derived class?
Syntax:
class : visibility label
{
……..
……..
}
112. What are the types of visibility labels?
Private, protected and public are the visibility labels.
113. What does the visibility limit specify in the derived class definition?
Visibility limit specifies how the features of base class are derived depending on the visibility mode, and also specifies whether the derived class can be further derived or not.
114. What is the default visibility mode in the derived class definition?
Private.
115. What are the types of inheritance?
Inheritance is of 5 types:
Single, multiple, hierarchical, multilevel and hybrid inheritance.
116. What is single inheritance?
A subclass with only base class is called single inheritance.
117. What is multiple inheritance?
A child class with many parent classes is called multiple inheritance.
118. What is hierarchical inheritance?
Many child classes with one base class is called hierarchical inheritance.
119. What is multilevel inheritance?
The process of deriving a class from already derived class is called multilevel inheritance.
120. What is hybrid inheritance?
When two or more types of inheritance are used together, then it is called hybrid inheritance.
121. Write the syntax for single inheritance?
Syntax:
class
{
………
………
};
class :[visibility mode]
{
……...
………
};
122. How is the accessibility affected when a base class is inherited privately?
When a base class is inherited privately by the derived class, the private members of the base class become inaccessible to the derived class. And the public members of the base class become private members of the derived class.
123. How is the accessibility affected when a base class is inherited publicly?
When a base class is inherited publicly by the derived class, the public members of the base class become the public members of the derived class. The private members of the base class are not inherited, i.e., they are not accessible by the member functions of the derived class. But, they can be accessed using the derived member functions of base class.
124. How can you inherit the private members of the base class?
The private members of the base class can be inherited by using the visibility label protected for the private members.
125. How is the accessibility of protected data affected when a base class is inherited privately?
When the protected data is inherited privately, it becomes private in the derived class and cannot be inherited further.
126. How is the accessibility of protected data affected when a base class is inherited publicly?
When the protected data is inherited publicly, it becomes protected in the derived class and available for further inheritance.
127. How is the accessibility of data affected in protected derivation?
When we use protected derivation, the private members are not inherited whereas both the protected and public members become protected in the derived class.
128. Write the syntax for multilevel inheritance?
Syntax:
class
{
…….
};
class : [visibility mode]
{
……..
};
class : [visibility mode]
{
………
};
129. Give an example for multilevel inheritance.
Ex.:
class student
{
…….
};
class marks : public student
{
………
};
class grade : public marks
{
………
};
130. Write the syntax for multiple inheritance.
Syntax:
class
{
……..
};
class
{
……….
};
class
{
………
};
class :[visibility] , [visibility], [visibility]
{
……….
};
131. Give an example for multiple inheritance.
Ex.:
class skill1
{
……..
};
class skill2
{
………
};
class skill3
{
………..
};
class student: public skill1, public skill2, public skill3
{
……….
};
132. What is the use of class resolution operator?
Class resolution operator is to remove the ambiguity when two functions with the same name are to be called in derived class. In such situations by using the class resolution operator, we can call only the function of the desired class.
133. Give an example for class resolution operator.
Ex.:
class skill1
{
……..
void show () {………}
};
class skill2
{
………
void show () {……….}
};
class skill3
{
………..
void show () {……….}
};
class student: public skill1, public skill2, public skill3
{
……….
skill1 :: show (); //class resolution operator
skill2 :: show ();
skill3 :: show ();
………..
};
134. Write the syntax for hierarchical inheritance.
class
{
………..
};
class : [visibility]
{
…………
};

class : [visibility]
{
…………
};
class : [visibility]
{
…………
};
135. Give an example for hierarchical inheritance.
class institute
{
……..
};
class skill1 : public institute
{
………
};
class skill2 : public institute
{
………
};
class skill3 : public institute
{
………
};
136. Give an example for hybrid inheritance.
class A
{
………..
};
class B : public A
{
……….
};
class C : public A
{
…………
};
class D : public B, public C
{
………..
};
137. What is indirect base class?
The base class whose properties will be inherited to the derived class through the other derived classes is called indirect base class.
138. What is proper inheritance?
The inheritance in which the derived class is able to follow the path of base class without any ambiguity is called proper inheritance.
139. How can you overcome the multiple inheritance paths to a child class?
Multiple inheritance paths to a child class can be overcome by making the base class as virtual in intermediate class.
140. What is improper inheritance?
The inheritance in which a base class is used just for code reuse is called improper inheritance.

141. What is the need to make a base class as virtual in inheritance?
Generally, when a child class is derived from two parent classes which are in turn derived from a single base class, the members of the base class are duplicated in the child class via the parent classes and an ambiguity might be raised. Inorder to avoid this situation if we declare the base class as virtual in the intermediate (parent) class declaration, the data won’t be duplicated.
142. Give an example for virtual base classes.
Ex.:
class A
{
………
};
class B: public virtual A
{
……..
};
class C: virtual public A
{
………
};
class D: public B, public C
{
……..
};
143. What is an abstract class?
An abstract class is the one which is used just to get inherited but is not used to create objects.
144. How does the constructors execute in multilevel inheritance?
In case of multilevel inheritance, the constructors get executed in the order in which they are inherited.
145. Give the order in which the constructors are executed for the following example.
class C : public A, public virtual B
{
…….
};
First the virtual base class constructor is invoked i.e., B class constructor, then A class constructor and then the derived class constructor C is executed.
146. Give the order in which the constructors are executed for the following example.
class C : public A, public B
{
…….
};
As it clearly known that constructors are invoked in the order of inheritance, first the class A constructor is invoked, then class B constructor and at last the derived class C constructor is invoked.
147. In which order are the destructors invoked?
Destructors are invoked in reverse order from the constructor calls.
148. What is overriding?
Overriding is the ability to change the definition of an inherited method or attribute in the derived class.
149. What is the difference between method overloading and method overriding?
Method overloading is defining multiple functions with same name but with different signatures whereas method overriding is rewriting the virtual method of the base class by the inherited class.
150. Write the syntax for initializing member data using initialization list in the constructors.
Syntax:
(arguments) : initialization list
{
………
}
151. Give an example for initializing member data using initializing list in the constructors.
Ex.:
class A
{
int c, d;
……….
A (int x, int y): c(x), d (y)
{ }
……..
};
152. What is containership?
Possessing of objects of other classes in a class is called containership or nesting.
153. Give an example for containership.
Ex.:
class A
{
…….
};
class B
{
…….
};
class C
{
A a1;
B b1;
……
};


Continuation from last mail:
154. What is early binding?
Binding of an object to the corresponding function at compile time is called early binding.
155. What are the other names for early binding?
Early binding is also called compile time polymorphism or static binding or static linking.
156. What is polymorphism?
Polymorphism means a single name with multiple forms.
157. What are the types of polymorphism?
Polymorphism is of two types: Compile time polymorphism and run time polymorphism.
158. What is run time polymorphism?
Binding of an object to the corresponding function at run time is called run time polymorphism.
159. What are the other names for run time polymorphism?
Run time polymorphism is also called late binding or dynamic binding.
160. What are pointer variables?
Variables that hold memory addresses are called pointer variables.
161. What are pointer constants?
Pointer constants are the memory addresses in a computer which cannot be changed.
162. Write the syntax for declaring pointer variable.
Syntax: data type *;
163. Write the syntax for initializing a pointer variable.
data type *, var;
= &var;
164. What is ‘&’ operator called as?
‘&’ is called address of or reference operator.
165. What are null pointers?
Null pointers are the one which are not initialized in the program.
166. What is the use of object pointers?
Object pointers are used to create objects at run time.
167. What is the difference between pointers and references?
The difference is that pointers can be initialized and assigned, whereas references can only be initialized.
168. What is an incomplete type?
Incomplete types are the pointers in which there is non availability of the implementation of the referenced location or it points to some location whose value is not available for modification.
169. What is a dangling pointer?
If you try to use the address of an object after its lift time is finished, then dangling pointer is raised.

170. What is a void pointer?
Void pointer is the pointer which can refer to variable of any data type.
171. What is the other name for void pointer?
Void pointer is also called generic pointer.
172. What is ‘*’ operator called as?
‘*” operator is called dereference operator or indirection operator.
173. Write the syntax for accessing the content of data variable.
Syntax: *;
174. List the arithmetic operations which can be performed on pointers.
The following are the arithmetic operations that can be performed on pointers:
a. Increment and decrement operations can be done on pointer variables.
b. Any integer value can be added or deducted from pointer variable.
c. Pointers can be compared using relational operators.
d. Addition of 2 pointer variables is not possible.
175. In which header file are the string handling functions stored?
In
176. What are C-strings or C-style strings?
The null terminated character arrays used to store and manipulate strings are called C-strings.
177. What is callback function?
Callback function is the pointer to a function.
178. What are the types of function pointers?
Function pointers are of two types:
Function pointers pointing to static member functions and
Function pointers pointing to non static member functions.
179. Write the syntax for function pointer.
Syntax: data type( *) ();
180. Which operator has higher precedence dot operator (.) or the indirection operator (*.)?
Dot operator (.) has the higher precedence than the indirection operator (*.).
181. What is “this” pointer?
The pointer that refers to an object that is currently invoking a member function is called this pointer.
182. What is the parameter that is added to every non static member function when it is called?
“this” pointer.
183. How can a base pointer access the members of a derived class?
Base pointer cannot access the members of the derived class but it point to the objects of the derived class.
184. What are the rules to be followed for creating virtual functions?
The following are some rules to be followed for creating virtual functions:
Virtual functions cannot be static members.
They should be members of some class.
They can be friend of other classes.
They need not be redefined in the derived class.
185. What is a pure virtual function?
A function which is defined in the base class but of no use is called pure virtual function.
186. What are abstract base classes?
Classes which cannot be used to create any objects are called abstract base classes.
187. What are “do-nothing” functions?
“Do-nothing” functions are the ones which are just defined but are not used.
188. What is a stream?
The interface between the program and the input/output devices is called a stream.
189. What is input stream?
The source stream which sends data to the program is called input stream.
190. What is output stream?
The destination stream which receives output from the program is called output stream.
191. What are stream classes?
The hierarchy of classes which are used to deal with console and disk files using different streams are called stream classes.
192. What is an adaptor class?
A function that has no functionality of own is called an adaptor class.
193. What is the other name for adaptor class?
Wrapper class.
194. In which class are the input/output operations related streams are stored?
In iostream class.
195. In which file are the objects cout and cin stored?
In iostream file.
196. In which class is the ‘>>’ operator overloaded?
‘>>’ operator is overloaded in the istream class.
197. In which class is the ‘<<’ operator overloaded?
‘<<’ operator is overloaded in the ostream class.
198. What is the limitation of ‘cin’?
Limitation of cin is that it cannot read multiple words.
199. Which member functions are used to handle single character I/O operations?
Get () and put () are the functions used to handle single character I/O operations.
200. Name the line oriented I/O functions.
Getline () and write () are the line oriented I/O functions.
201. Write the syntax for getline ().
Syntax: cin. getline (, size);
202. Write the syntax for write ().
Syntax: cout.write (, size);
203. List some ios format functions.
Width (), precision (), unsetf (), setf (), fill ().
204. What are manipulators?
The functions included in the I/O statements to alter the parameters of a stream are called manipulators.
205. What is the difference between ios member function and the manipulator?
The difference between ios member function and the manipulator is that ios member function returns the previous format state whereas manipulator doesn’t return it.
206. Write the syntax for creating a manipulator?
Syntax:
ostream & manipulator (ostream & output)
{
…….
…….
return output;
}
207. Write the syntax for using width ().
Syntax: cout.width();
208. Write the syntax for setf ().
Syntax:
cout.setf (arg, arg1);

FILES:
209. What is a file?
A file is a collection of related data stored on a disk.
210. Name the classes that define the file handling methods.
The classes that include the file handling methods are ifstream, ofstream, and fstream.
211. In which file are the classes that include the file handling methods exist?
Fstream.
212. What things are to be specified when we perform some operation on a file?
When ever we perform some operations on a file, we have to mention the filename, data structure being used, purpose of using the file, and the method of opening.
213. What is EOF?
EOF stands for End of File, which is used to check for the end of file when a file is being read.
214. What are the parts of a file name?
A file name includes a primary name and an optional period with an extension.
215. What are the ways of opening a file?
A file can be opened using the constructor function of the class and using the member function open () of the class.
216. What is the difference in opening the file using constructor function and open ()?
The difference in opening the file using constructor function and open () is that constructor function uses only one file whereas open () is used when we want to handle multiple files using one stream.
217. What are the steps required to initialize file steam objects?
The following are the steps required to initialize file stream objects:
A file stream is created to manage the I/O stream.
Initialize the file object with file name.
218. Write syntax for to open a file for input?
Syntax: ifstream (“”);
219. Write the syntax to open a file for output?
Syntax: ofstream (“”);
220. Write the syntax for closing a file/
Syntax: .close ();
221. Write the syntax to open multiple files using open ()?
Syntax:
file_stream stream_obj;
stream_obj. open (“”);
stream_obj. open (“”);
222. Give an example to open multiple files using open ()?
Ex.:
ofstream ofile;
ofile. Open (“file1”);
ofile. Open (“file2”);
223. In which class is the function eof () present?
Eof () is exist in the class ios.
224. Write the syntax of open () with arguments.
stream_obj. open (“”, mode);
225. What does the file mode parameter ios::binary mean?
It means the file to be opened is a binary file.
226. What does the file mode parameter ios::app mean?
File is to be opened for appending data to end of file.
227. What does the file mode parameter ios::nocreate mean?
If the file does not exist open fails.
228. What does the file mode parameter ios::trunc mean?
File contents are to be deleted, if the file exists.
229. What is the default value for the file mode ios::in?
The default value for ios::in is open for reading only.
230. What is the default value for the file mode ios::out?
The default value for ios::out is open for writing only.
231. What is the difference between ios::ate and ios::app mode?
The difference between ios::ate and ios::app mode is that ios::ate mode allows us to add data or change data anywhere in the file whereas ios::app mode allows us to add data only to the end of file.
232. When you open a file in ios::out mode, what is the other mode opened by default?
When you open a file in ios::out mode, the file also gets opened by default in ios::trunc mode.
233. What is the use of file pointers?
File pointers are used to move in the file while writing or reading.
234. What are the types of file pointers?
File pointers are of two types: Input pointer and output pointer.
235. What are the other names for input pointer and output pointer?
Input pointer is also called get pointer and the output pointer is also called put pointer.
236. What is the use of input pointer?
The input pointer is used to read the contents in a particular file location.
237. What is the use of output pointer?
The output pointer is used to write the contents in a particular file location.
238. What is the default location to which the input pointer points to when a file is opened in read only mode?
At the beginning of the file.
239. What is the default location to which the output pointer points to when a file is opened in write only mode?
File pointer points to the beginning of the file before which it deletes all the contents of the existing file.
240. In which is the file to be opened to add data to the existing contents?
In append mode.
241. List the functions which are used to control the movement of file pointers?
seekg (), seekp (), tellg () and tellp () are the functions used to control the movement of file pointers.
242. What is the use of seekg ()?
seekg () is used to move input/get pointer to specified position.
243. What is the use of seekp ()?
seekp () is used to move output/put pointer to a specified position.
244. What is the use of tellg ()?
tellg () provides the current position of input/get pointer.
245. What is the use of tellp ()?
tellp () provides the current position of output/put pointer.
246. Write the syntax for seekg () with one and with 2 arguments?
Syntax:
.seekg(no of bytes); //with one argument
.seekg(offset, refposition); //with two arguments
Refposition is the location from where the file pointer moves to the specified offset position.
247. Write the syntax for seekp () with one and with 2 arguments?
Syntax:
.seekp(no of bytes); //with one argument
.seekp(offset, refposition); //with two arguments
Refposition is the location from where the file pointer moves to the specified offset position.
248. What are the types of constants used by refposition of seekg () and seekp ()?
refposition of seekg () and seekp () takes the following constants:
ios::beg – starting of file
ios::cur – current position of file pointer
ios::end – end of file
249. What are the functions used to handle single character at a time?
put () and get () are the functions used to handle single character at a time.
250. What are the functions used to handle blocks of data?
read () and write () are the functions used to handle blocks of data.
251. Write the syntax for write () and read ()?
Syntax:
.write ((char *) & , size of (variable));
.read ((char *) & , size of (variable));
252. List the error handling functions.
eof (), bad (), good () and fail () are the error handling functions.
253. In which class are the error handling functions present?
Error handling functions are present in the class ios.
254. Name the arguments main () can take?
Main () can takes the arguments argc (argument counter) and argv (argument vector).
255. Write the syntax for using command line arguments.
main (int argc, char * argv [])
256. What are command line arguments?
Command line arguments are given after the name of a program in command line operating systems like Dos or Linux, and are passed in to the program from the operating system.
257. What is the use of templates?
Templates are used to create generic classes and functions.
258. What is generic programming?
The method in which generic types are used as arguments in algorithms for different data types and data structures is called generic programming.
259. What is the other name for templates?
Templates are also called parameterized classes or functions.
260. What are parameterized macros?
Parameterized macros are the one which consist of template with insertion points for the addition of parameters.
261. Write the syntax for using template.
Syntax:
template
class
{

…………..
…………..
};
262. What is template class?
The class created from template is called template class.
263. Write the syntax for object of template class?
Syntax:
(arguments);
264. Write the syntax for using multiple generic types in class template.
Syntax:
template
class
{
………….
………….
};
265. Write the syntax for function template.
Syntax:
template
return type (arguments of type T)
{
…………
…………
}
266. Can the template functions be overloaded?
Yes, the template functions can be overloaded.
267. What are the steps in overloading template?
The following are the steps to overload a template:
a. call a normal function with an exact match.
b. call a template function which could be created with an exact match.
c. Follow overloading resolution to normal functions and use the one that matches.
268. Write the syntax for member function templates.
Syntax:
template
return type :: (parameters)
{
…………
…………
}
269. What is the use of template classes and functions?
Template classes and functions are used to eliminate redundancy of code and help in easier program development.
270. What is the difference between a template class and class template?
Template class is a parameterized class not instantiated until the client provides the needed information. A class template specifies how individual classes can be constructed.
271. What is the use of export?
Export is used to instantiate the non inline template classes and functions from different files.
272. What is the use of using?
Using is a namespace scope directive used to declare the accessibility of identifiers declared within a namespace scope.
273. What are the different types of errors encountered with a program?
The following are the different types of errors encountered in a program:
Syntax errors: violation of syntax rules
Run-time errors : mismatch of data, out of range data etc
Logical errors : logically incorrect data
Latent errors : show up only with a particular set of data.
274. What is an exception?
Exception is a run time anomaly or unusual situation that a program encounters while executing.
275. What are the types of exceptions?
Synchronous exceptions and asynchronous exceptions are the type of exceptions.
276. Give examples for synchronous exceptions.
Out of range index, division by zero, overflow etc.
277. What is overflow error?
Overflow error is an arithmetic error caused by the result of an arithmetic operation being greater than the actual space provided by the system.
278. Give an example for asynchronous exceptions.
Keyboard interrupt.
279. What is the use of exception handling?
Exception handling is used to detect exceptions so that a corresponding action can be taken.
280. What are the basic segments of error handling code?
Error handling code consists of two segments one for detecting and throwing exception and the other for catching the exception.
281. What are the steps involved in exception handling?
The following 4 steps are involved in exception handling:
Hit, throw, catch and handle.
282. What is the use of try block?
Try block is used to generate exceptions.
283. What is the use of catch block?
Catch block is used to catch the exceptions thrown by throw statement and handle the exceptions.
284. Write the syntax for try block?
Syntax:
try
{
………..
……….
throw exception;
……….
}
285. Write the syntax for catch block?
Syntax:
catch (data type )
{
………….
………….
}
286. Write the different forms of throw.
The following are the different forms of throw:
throw (exception);
throw exception;
throw;
287. How can you catch all the exceptions without specifying individually?
All the exceptions can be caught without specifying them individually by using ellipsis with catch.
Syntax:
catch (…)
{
………
………
}
288. Write the syntax for exception specification.
Syntax:
type (parameters) throw (type list)
{
……….
……….
}
289. What is translation?
Translation is creation of a new program in an alternate language which is logically equivalent the source language program.
290. What is the difference between ANSI C++ and Visual C++?
ANSI C++ is the earlier version of C++ whereas visual C++ is an IDE for developing GUI based applications.
291. What are the tools added to the visual C++?
Foundation class library, application wizard, class wizard are the tools added to the visual C++.
292. What is the use of Microsoft foundation class library?
MFC library would help us reduce the code and development time.
293. What is the use of application wizard?
Application wizard provides a frame work for creating initial applications.
294. What is the use of class wizard?
Class wizard helps in customizing the classes.
295. What is an iterator class?
An iterator class is used to traverse through the objects maintained by a container class.

No comments: