2. Sructure
Structure is a collection of variables of different data types under a single
name. It is similar to a class in that, both holds a collection of data of
different data types.
Structure definition
struct tagname
{
data variable name 1
data variable name 2
………………………………..
………………………………..
};
2
3. Array of structure
Structure is collection of different data type. An object of
structure represents a single record in memory, if we want more than one
record of structure type, we have to create an array of structure or object.
struct struct-name
{
datatype var1;
datatype var2;
- - - - - - - - - -
- - - - - - - - - -
datatype varN;
};
struct-name obj [ size ];
3
4. Files-Input & Output
C++ comes with libraries which provides us many ways for performing input
and output.
In C++ input and output is performed in the form of sequence of bytes or
more commonly known as streams.
Input Stream: If the direction of flow of bytes is from device(for example:
Keyboard) to the main memory then this process is called input.
Output Stream: If the direction of flow of bytes is opposite, i.e. from main
memory to device( display screen ) then this process is called output.
4
5. Sequential and Random acess
Sequential Access: The computer system reads or writes information to the
file sequentially, starting from the beginning of the file and proceeding step
by step.
It is faster than random access.
Random Access: The computer system can read or write information
anywhere in the data file.
We can search through it and find the data we need more easily.
5
6. Object oriented programmings(Oops)
Object-Oriented Programming is a methodology or paradigm to design a
program using classes and objects.
It simplifies the software development and maintenance by providing some
concepts.
6
7. Basic concepts of Oops
Object:
Any entity that has state and behavior is known as an object.
For example: chair, pen, table, keyboard, bike etc. It can be physical and logical.
Class:
Collection of objects is called class.
It is a logical entity.
It is a user defined data type.
class class name {
access_specifier_1:
member1;
access_specifier_2:
member2;
...
} object names;
7
8. Basic concepts of Oops
Class member function definitions
Inside of the class definition
class class_name
{
private:
declarations;
public:
function_declaration(parameters)
{
function_body;
}
};
8
9. Basic concepts of Oops
Outside of the class definition
return_type class_name::function_name(parameters)
{
function_body;
}
9
10. Basic concepts of Oops
Data Abstraction:
Data abstraction is a concept which hides the background details and represents
only the needed information to the outside world.
Data Encapsulation:
It is a technique which combines both data members and functions, operates on
that data in a single unit known as a class.
Constructors:
Constructor is a member function with the same name as the name of a class.
It is used to initialize the objects of that class.
They don’t have any return type.
10
11. Basic concepts of Oops
Types of constructor
Default Constructor
A constructor without any parameters is called a default constructor.
Every instance of the class will be initialized to the same values.
Parameterized Constructor
A constructor with at least one parameter is called a parametrized constructor.
parametrized constructor is that you can initialize each instance of the class
with a different value.
Copy Constructor
The constructor which creates an object by copying variables from another
object is called a copy constructor.
It is to initialize a new instance to the values of an existing instance.
11
12. Basic concepts of Oops
Destructor:
Destructor is a member function which destructs or deletes an object.
A destructor has the same name as the class, preceded by a tilde (~).
Rules for Destructor:
Do not accept arguments.
Do not return a value (or void).
Inheritance:
It is basically a method which provides a way that capabilities and properties from
one class to come into another class.
We can form a new class from an existing class.
Here the new class is called as the derived class and the existing class i.e. the class
from which the new class is derived is called as the base class.
12
13. Basic concepts of Oops
Types of inheritance
Single Inheritance: In single inheritance, a class is allowed to inherit from only
one class. i.e. one sub class is inherited by one base class only.
13
14. Multiple Inheritance: Multiple Inheritance is a feature of C++ where a class can
inherit from more than one classes. i.e. one sub class is inherited from more than
one base classes.
14
15. Multilevel Inheritance: In this type of inheritance, a derived class is created from
another derived class.
15
16. Hybrid (Virtual) Inheritance: Hybrid Inheritance is implemented by combining
more than one type of inheritance.
16
17. Hierarchical Inheritance: In this type of inheritance, more than one sub class is
inherited from a single base class. i.e. more than one derived class is created from
a single base class.
17