C++ 2M
C++ 2M
4. Define an Objects
objects are the basic run time entities in an object oriented system. They may represent a
person, a place or any item that a program has to handle.
6. Define a class.
A class is a way to bind data and its associated function together.
A class is a collection of objects with similar attributes and operations. Once the class has
been defined, we can create any number of objects belonging to that class.
Eg. Class – Account
It will create an object account belonging to the class Account
7. Define Encapsulation
The wrapping up of data and functions in a single unit is known as encapsulation. The data
is kept safe from external interference and misuse. The data is not accessible to the outside world
and only those functions which are wrapped in the class can access it. These functions provide the
interface between the objects data and the program.
9. Define Abstraction
Abstraction refers to the act of representing essential features without including the
background details
10. Define ADT
The classes which are using the concept of data abstraction is known as abstract data types
(ADT)
19. What are the differences between “break” and “continue” statements.
Break: Break statement takes the control to the outside of loop. It is used in loop and switch
statement
Continue: continue statement takes the control to the beginning of loop. It can be used only in loop
statement.
28. Give the syntax for member function definition outside class
return-type class_name::function name(arguments)
{
function body;
}
32 Define Constructor?
A constructor is a special member function whose task is to initialize the object of its class.
It is called constructor because it constructs the value of data members of the class.
a) Parameterized manipulators
setw(int width) – sets the field width
setprecision(int prec) – sets the floating point precision
b) Non-parmeterized manipulator:
dec – sets the conversion base to 10
endl – outputs a new line and flushes stream
Fstream: used for handling files on which I/O operations can be performed. It supports
simultaneous I/O operations. It can open() with default input mode and inherits all the functions
from istream and ostream classes through iostream.
61. List any four file modes and their purpose
a) ios::in – open for reading
b) ios::ate – seek to the end of file at opening time
c) ios::nocreate – open fails if file does not exist.
d) ios::binary – opens a binary file