Types of Queue
Linear Queue
Algorithm: Insert Operation on Queue
Step 1: If Rear=Max-1
Print “Overflow : Queue is full” and Exit
End If
Step 2: If Front=-1
Set Front =0
End If
Step 3: Rear=Rear+1
Step 4: Queue[Rear]=Element
Step 5: End
Algorithm: Delete Operation on Queue
Step 1: If Front=-1
Print “Underflow: Queue is empty” and Exit
End if
Step 2: Set Del_element=Queue[Front]
Step 3: If Front=Rear
Set Front=Rear=-1
Else
Front=Front+1
End If
Step 4: Return Del_Element
Step 5: End
]]>Algorithm: PUSH Operation on Stack
Step 1: If Top=Max-1
Print “Overflow : Stack is full” and Exit
End If
Step 2: Top=Top+1
Step 3: Stack[TOP]=Element
Step 4: End
Algorithm: POP Operation on Stack
Step 1: If TOP=-1
Print “Underflow: Stack is empty” and Exit
End if
Step 2: Set Del_element=Stack[Top]
Step 3: Top=Top-1
Step 4: Return Del_Element
Step 5: End
]]>Operation on Data Structure
Different data structures allow different types of operations. Various operations that can be performed on data structures are:
Friend Function :-
Properties of Friend Function
There are following properties of friend function.
Syntax:-
class class_name
{
friend return_type function_name(Arguments);
};
Example
class num
{
private:
int a,b,c;
friend void sum(num);
};
void sum(num obj)
{
Accessible private or public data
}
]]>Inheritance
Rules for inheritance:
Base class can be inherited in two ways or mode.
Public:– when a base class is inherited in public mode then Public members of base class become public member of derived class and protected members of base class become protected member of derived class.
Private:- When a base class is inherited in private mode the public and protected members of base class become private members of derived class.
Syntax for inheritance
class Derived_Class : Mode Base class
{
…………………
………………..
};
Example
Class nips
{
public:
int a,b;
};
class jac : public nips
{
………….
………….//a, b are accessible here
};
Types of inheritance
There are different types of inheritance in C++.
Single inheritance / single level inheritance
When a Derived class inherits only one base class , is known as single inheritance or single level inheritance.
]]>Constructor
Characteristics of Constructor
Types of Constructor
There are three types of constructors in c++.
Default constructor
A constructor without parameter or Argument is known as default constructor.
class num
{
public:
num()
{
// default constructor
}
};
]]>We use certain steps to setup a C++ development Environment with Visual Studio code(VS Code)
Step 1:- Dowload VS(Visual studio code) Editor
https://code.visualstudio.com/download
Step 2: Install VS Code.
Step 3: Click on Extension.It shows at Left side bottom.
(Ctrl+Shift+ X)
Step 4: Install Code runner for C++
Step 5: Install intellisense for C++
]]>Object Oriented Programming (OOP) is way of programming that allows modularization of a program by forming separate memory area for data as well as function.
There are following characteristics of Object Oriented Programming.
Advantages of OOP:
Object Oriented Program can be easily upgraded without affecting the other parts of the program.
Redundant program code can be eliminated using inheritance.
OOP allows Po;ymorphism, Encapsulatioin, and other characteristics of OOP.
OOP enhances the thought process of a programmer to rapid development of a software in sort time.
Uses of OOP:
Example of OOP Language
What is Class ?
Object
Method / Function
An operation required for an object when coded in a class is called method.
Data Abstraction
The representation of essential feature without including the background details, is called data abstraction.
Abstraction is a mechanism or technique to hide irrelevant (unwanted) details and representation of only essential feature so that one can focus on important thing at a time. For example while driving a car a driver knows only essential feature such as how to use the clutch, gears, break , accelerator etc.
Polymorphism
The capability of taking more than one form for different purpose is called polymorphism.
Polymorphism allows the same function to act differently.
It is a greek term which means multiple forms.
example: Function overloading , Operator overloading.
Encapsulation
The packing of data and function into a single component is known as encapsulation.
Inheritance
It is the method by which object of one class gets the properties of objects of another class.
Inheritance is one of the most powerful feature of OOP language that allows to derive a new class from existing class.
Data Hiding
It means declaring data members and member functions in private section so that it can’t be accessed directly outside of the class.
]]>Q. Write a program to find sum of two numbers using class.
#include<iostream.h>
#include<conio.h>
class nips
{
public:
int a,b,c;
void show()
{
a=10;
b=5;
c=a+b;
cout<<"Sum="<<c;
}
};
void main()
{
clrscr();
nips n1;
n1.show();
getch();
}
Output
Sum=15
]]>Input through keyboard and output on the monitor/ screen is known as console input output.
To perform input /output operations , there are various functions.
console input / output can be divided into two categories.
Unformatted input / output functions
It is mainly used for characters. No any control string is used.
Unformatted input functions
1. getch()
It takes entry of a single character. Entered key doesn’t display on the screen . It has defined in #include<conio.h> header file.
2. getche()
It takes a single character and very similar to getch( ). Entered character prints on the screen . It has defined in #include<conio.h> header file.
3. getchar()
It is used to take entry of single character form keyboard. It has defined in #include<stdio.h> header file.
4. gets()
It is used to take entry of a string(more than one words at a time) from the keyboard. It has defined in #include<stdio.h> header file.
Unformatted output functions
1. putch( )
It displays the character on the screen. It has defined in #include<conio.h> header file.
2. putchar( )
It displays the character on the screen. It has defined in #include<stdio..h> header file.
3.puts( )
It is used to display string on the monitor. It has defined in #include<stdio.h> header file.
]]>