0% found this document useful (0 votes)
23 views10 pages

Procedure Oriented Programming Language

The document provides an overview of Procedure Oriented Programming (POP) and C++, detailing their characteristics, advantages, and disadvantages. It explains key concepts of C++ such as classes, objects, inheritance, polymorphism, encapsulation, and constructors, along with syntax examples. Additionally, it covers access specifiers, tokens, keywords, identifiers, constants, strings, and operators in C++.

Uploaded by

Sarla Jangir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views10 pages

Procedure Oriented Programming Language

The document provides an overview of Procedure Oriented Programming (POP) and C++, detailing their characteristics, advantages, and disadvantages. It explains key concepts of C++ such as classes, objects, inheritance, polymorphism, encapsulation, and constructors, along with syntax examples. Additionally, it covers access specifiers, tokens, keywords, identifiers, constants, strings, and operators in C++.

Uploaded by

Sarla Jangir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Procedure Oriented Programming Language

 In the procedure oriented approach, the problem is viewed as sequence of things to be done such as
reading , calculation and printing.
 Procedure oriented programming basically consist of writing a list of instruction or actions for the
computer to follow and organizing these instruction into groups known as functions

The disadvantage of the procedure oriented programming languages is:


1. Global data access
2. It does not model real word problem very well
3. No data hiding

Characteristics of procedure oriented programming:


1. Emphasis is on doing things(algorithm)
2. Large programs are divided into smaller programs known as functions.
3. Most of the functions share global data
4. Data move openly around the system from function to function
5. Function transforms data from one form to another.
6. Employs top-down approach in program design

What is C++?
C++ Introduction and History
 C++ is a high level language “Semi Object Oriented ” programming language developed by bjarne
Sroustrup in 1979 at Bell Labs.
 C++ is a "general purpose", case-sensitive, "free-from" programming Language that supports "object-
Oriented" Procedural generic programming.
 C++ is a "middle - Level language. As it encapsulates both high and Low Level Language features.
 In earlier the name of C++ was C with classes".
 It is an imperative and a Compiled Language.
“Object oriented programming as an approach that provides a way of modularizing programs by
creating partitioned memory area for both data and functions that can be used as templates for
creating copies of such modules on demand”.

Define Syantax of C++

#include <iostream.h> header file


#include <conio.h>
Using namespace std; Namespace
return-type main () Main method
{ → Opening bracket for main function
/*multi Line Comment */ multi comment

Print Statement
cout << " Output Statement";
// Single Line Comment Single Comment
return value of return; main function return Statement
} Close bracket of the main function

Program

#include <iostream.h>

Void main()
{
Cout << "Hello world”;
}
Output - Hello world
What is C++ OOPS Concepts? Explain.
Object
Class
Polymorphism
Abstraction
Inheritance
Encapsulation
Message Passing
Dynamic Binding

1. Object
Any Entity that has state and behaviour is known as object.
Object is a "Active" Entity.
An object is an instance of a class.
When a Class is defined, no memory is allocated but When it is instantiated (ie an object is created)
memory is allocated.

2. Class
Class is a Collection of objects.
Class is a "Passive" Entity.
Class is a User-defined data type which has data members and member functions.
EX: class and object

Class box
{
Private:
Data member int a,b
Public:
Member function void main(), void display
},b1,b2,b3

Box b1 Box b2 Box b3 Objects

3. Inheritance
When One Class Access the property (data member and member function) of another class is called
Inheritance.
Super class /Base class Class A
Parent class

Sub Class/ derived class Class B


Child class
Syntax
Class A
{
};
ClassB : Public A
{
};
4. Polymorphism (poly + morphism)
When one task is performed by different ways are known as polymorphism.
for Ex => A person at the same can have different character Like a father, a husband and Employee. So the
Same person possess different behavior in different situations. This is Called Polymorphism.
Polymorphism

Compile time polymorphism Runtime polymorphism

Function overloading Operator overloading Virtual function

5. Abstraction
Hiding internal details and showing functionality
For Ex Phone Call, we don't know the internal processing.
Note In C++We use abstract Class and Interface to achieve abstraction.

6. Encapsulation ⇒ Binding (or wrapping)


Code and data wrapped together into a Single Unit known as Encapsulation.
For Ex = Capsule, It is wrapped with different medicines

7. Dynamic Binding
In dynamic Binding, the Code to be Executed in response to function Call is decided at runtime.
C++ has virtual function to Support this.

8. Message Passing
Objects Communicate With One another by sending and receiving information to Each other through
Message Passing
message
Object A Object B
Sending object Receiving object.

Features of C++
1) Simple
It is a Simple Language in the Sense that programs Can be broken down into logical Unit and parts has rich
library support.

2) Machine Independent or Portable


C Programs Can be executed in many machines with little bit or no change. But it is not platform
independent.

3) Mid-level Programming Language


Through C++ We can do both Systems - Programming and build Large-Scale user application so it is called
mid-level Programming.

4) Structured Programming Language →


C++ is a Structure Programming Language that means we can break the program into parts using
functions, so it is easy to understand and modify.

5) Rich Library →
C++ provides a lot of in built functions that makes the development fast.

6) Memory Management →
It supports the feature of Dynamic memory allocation. In C++ we can free the allocated memory at any
time by Calling the free function.
7) Speed
The Compilation and execution time of C++ Language is fast.

8) Pointer
C++ Provide the features of pointer. We can directly interact with the memory by using the Pointer.

9) Extensible
It is Extensible because it can easily adopt new features.
10) Structured
11) Compiler Based
12) Object Oriented

TOKENS:
The smallest individual units in program are known as tokens. C++ has the following
tokens.
i. Keywords
ii. Identifiers
iii. Constants
iv. Strings
v. Operators

KEYWORDS:
The keywords implement specific C++ language feature.
They are explicitly reserved identifiers and can’t be used as names for the program variables or other user
defined program elements.
The meaning and working of these keywords are already known to the compiler.
C++ KEYWORDS:

Asm double new switch


Auto else operator template
Break enum private this
Case extern protected throw
Catch float public try
Char for register typedef
Class friend return union
Const goto short unsigned
Continue if signed virtual
Default inline sizeof void
Delete long struet while
IDENTIFIERS:
Identifiers refers to the name of variable , functions, array, class etc. created by programmer. Each
language has its own rule for naming the identifiers.
The following rules are common for both C and C++.

1. Only alphabetic chars, digits and under score are permitted.


2. The name can’t start with a digit.
3. Upper case and lower case letters are distinct.
4. A declared keyword can’t be used as a variable name.
In ANSI C the maximum length of a variable is 32 chars but in C++ there is no bar.

CONSTANTS:
 Constants are like a variable except that their value never change during execution once defined.
 C++ support several kinds of literal constant. They include integer, character, floating point number and
string.

STRINGS:
 String in C++ are used to store letters and digits.
 String can be referred to as an array of characters as well as individual data type.
EX= char[30] = “hello”;
Or
String name = “hello”;

OPERATORS:
 C++ operator is a symbol that is used to perform mathematical or logical manipulation.
 Arithmetic operator
 Relational operator
 Logical operator
 Increment and decrement operator
 Bitwise operator
 Assignment operator
 Conditional operator

C++ Classes and objects:


Class
 A Class in C++ is the building blocks that leads to Object-Oriented programming.
 Classis a user-defined data type, which holds. its own data members and member functions, which can be
accessed and used by Creating an instance of that class.
 A C++ class is like a blueprint for an Object.
 A Class is a user defined data type which has data members and member functions.

Syntax:
Keyword……… Class ClassName ……….user-defined Name
{
Access specifier: // Can be private,Public or Protected
Data Members; // Variables to be used
Member functions () // methods to access data member
{
Body of function;
}
} // class Name end with a cob.n..Syantax
Object
 An object is an instance. of a class. when a Class is defined no memory is allocated but when It is
instantiated (such as an object is Created) memory is allocated.

Declaring object
 when a class is defined,Only the Specification for the object is defined, no memory or Storage is allocated
 To use the data and Access functions. defined in the class, you need to create Object

Syntax »
Classname object Name;
Access data members and member functions →
The data Members and member function of class Can be accessed using dot (•) operator with object.
Syntax =>
object Name. memberdata;
Object Name. Memberfunction ();
Ex Class Student
{
public:
int Rollno; } member data
string name; } member data
void show() } member function
{
Cout << “your name = "<<name;
}
};
int main()
{
Student ob;
Ob.Rollno = 30;
ob.name="kailash";
ob. Show ();
return 0;
}

WAP for class and objects and access data member and member functtion

#include<iostream>
using namespace std;
class Simple
{
public:
string name;
void display()
{
cout<<"your name is: "<<name;
}
};

int main()
{
Simple ob;
ob.name="kailash joshi";
ob.display();
return 0;
}

Access Specifiers in C++


 Access Specifiers define how the members (attributes and methods) of a class can be accessed.
 Access modifiers are used to implement an important aspect of object-oriented Programming known as
Data Hiding
 There are three access modifier in C++
1) Public: members are accessible from Outside the class
2) Private: members cannot be accessed or view from outside the class.
3) Protected: members cannot be accessed from outside the class, however, they Can be accessed in
inherited Classes.
Syntax
Class Classname
{
public:
Data member;
member function;
Private:
Data member;
member function;
Protected:
Data member;
member function;
};
Class Methods in C++
 Method are functions that belongs to the Class.
 There are two ways to define functions that belongs to a class.
1) Inside Class definition / Inline
2) Outside class definition.
1. Inside Class definition =>
 The member function is defined inside the Class definition it can be defined directly.
 Similar to accessing a data member in the Class, we can also access the public member functions through
the Class object using the dot operator (•).
Syntax
Class ClassName
{
Public:
returntype Method Name () // method inside class definition
{
Body of member function.
}
}

Example Class Student


{
Public:
void Show ()
{
cout<<" show method Call";
} };
2. Outside Class definition methods →
 To define a function outside the class definition, you have to declare it inside the class then define it outside
of the Class. This is done by Specifying the Name of the Class followed by Scope resolution :: operator,
followed by the name of the function.
 NOTE you access methods just like you access attributes, by creating an object of the class and using the
dot Syntax (•).
Syntax
Class Classname ()
{
public:
returntype method Name ();
};
// method/ function definition outside the class.
return type Classname :: methodname ()
{
Body of the method;
}// Then Create object of class and call method.

Ex Class student
{
public:
Void show();
};
Void Student:: show ()
{
Cout<< “this i's show function”;
}

Ex Class student
{
public:
void show();
};
Void student :: Show ().
{
Cout<< “this i's show function”;
}
int main()
Student ob;
Ob.show();
return 0;
}
Constructors in C++
 A Constructor is a special type of member function of a Class which initializes object of a Class.
 In C++, Constructor is automatically Called When object is Created.
 It is special member function of a class because it does not have any return type. How Constructors are
different from normal member function?
1) Constructor has same name as the Class itself...
2) Constructor don't have return type
3) A constructor is automatically called When an object is created.
4) Default Constructor don't have input argument however, Copy and Parameterized Constructors
have input arguments.
5) Constructor must be placed in public Section of class.
6) Constructor used to initialize the data. members of new object generally.
Class Student
{
public:
Student ()
{
"Cout << " Constructor initiated
}
};
int main()
{
Student Ob;
Return 0;
}

Type of Constructors in C++

 Default ⇒Class name()


 There are three types of Constructor in C++

 Parameterized ⇒ Class.name (parameter)


 Copy ⇒Class name (Const Class name old-object)

Default Constructor
 Default Constructor is the Constructor which does not take any argument, It has no parameters.
Syntax
Class Classname
{public:
Classname ()
{
member data, member function,
} };

You might also like