0% found this document useful (0 votes)
1 views

OOPPSSSS

The document provides an overview of procedural and object-oriented programming in C++, highlighting their characteristics, differences, and benefits. It explains key concepts of OOP such as classes, encapsulation, inheritance, and polymorphism, and contrasts them with procedural programming. Additionally, it covers basic data types, variables, constants, tokens, and operators in C++, along with the use of streams for input and output operations.
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)
1 views

OOPPSSSS

The document provides an overview of procedural and object-oriented programming in C++, highlighting their characteristics, differences, and benefits. It explains key concepts of OOP such as classes, encapsulation, inheritance, and polymorphism, and contrasts them with procedural programming. Additionally, it covers basic data types, variables, constants, tokens, and operators in C++, along with the use of streams for input and output operations.
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/ 6

Procedural programming

Procedural programming in C++ is a programming paradigm that focuses on procedures (also known as
functions) to operate on data. It's one of the fundamental styles of programming and is heavily
influenced by the C language, from which C++ evolved.

Characteristics of procedure oriented programming


• Large programs are divided into smaller programs known as functions.

• Most of the functions share global data

• Data move openly around the system from function to function

• Function transforms data from one form to another.

• Employs top-down approach in program design.

Object-Oriented Programming (OOP) in C++


Object-Oriented Programming (OOP) is a programming approach that models real-world entities as
"objects" containing both data and functions. C++ is an object-oriented language that supports all the
major concepts of OOP.

Basic Concepts of OOP


Class and Object in C++: A class is a blueprint for creating objects. It defines the data and
functions that operate on the data. An object is an instance of a class.

Encapsulation: Encapsulation is the process of combining data and functions into a single unit
called a class. It hides the internal details of an object and only exposes necessary parts using public
functions. This protects data from accidental modification.

Abstraction: Abstraction means hiding complex implementation details and showing only the
essential features of an object. It helps in reducing complexity and increasing readability.

Inheritance: Inheritance allows one class (derived class) to acquire the properties and behaviors of
another class (base class). It promotes code reusability and helps in building hierarchical relationships
between classes.

Polymorphism: Polymorphism means the ability to take many forms. In C++, polymorphism can
be compile-time (function overloading and operator overloading) or run-time (using virtual functions). It
allows the same function to behave differently for different objects.

Difference Between (POP) & (OOP)


Procedure Oriented Object Oriented Programming
Programming

1 Program is divided into small partscalled Program is divided into parts called
functions. objects.

2 Follows Top Down approach. OOP follows Bottom Up approach.

3 It does not have any proper way for hiding OOP provides Data Hiding so provides
data so it is less secure. more security.

4 Overloading is not possible. Overloading is possible in the form of


Function Overloading.

5 Example are : C, VB Example are : C++, JAVA,

Benefits of OOPs
Reuse code: You can use old code to make new programs without starting from scratch.
Easy to fix: You can fix or change one part without breaking everything.
Data safety: OOP keeps important information safe and only shares what’s needed.
Grows easily: You can add new things to your program without much trouble.
Real-life examples: It helps you design programs by copying how things work in real life.
Difference Between C and C++
C C++

C was developed in 1972 by Dennis Ritchie C++ was developed by Bjarne Stroustrup at
at Bell Laboratories. Bell Laboratories in the early 1980s.

It is a function-driven language. It is an object-driven language.

C has 32 keywords. C++ has 63 keywords.

The file extension of a program in C The file extension of a C++ program is .cpp.
language is .c.

Does not have access modifiers. Has access modifiers.

C uses <stdio.h> header file for C++ uses <iostream.h> header file for
input/output operations. input/output operations.

Tokens
In C++, a token is the smallest unit of a program that has meaning to the compiler. When the C++
compiler reads a program, it breaks the entire source code into meaningful elements called tokens.
There are six types of tokens in C++:
1. Keywords: Reserved words used by the language that have a special meaning. Example:
int, float, if, while, return

2. Identifiers: Names used for variables, functions, arrays, classes, etc. Example: age, sum,
displayResult

3. Constants (Literals): Fixed values that do not change during program execution.
Example: 10, 3.14, 'A', "Hello"

4. Operators: Symbols used to perform operations on variables and values. Example: +, -, *, /,


==, &&

5. Punctuation / Special Symbols: Includes characters like ;, {, }, (), [], #, , which help
structure the code.

6. Strings: A sequence of characters enclosed in double quotes. Example: "Welcome to C++"

Identifiers
Identifiers are the names given to various program elements such as variables, functions, arrays, objects,
etc. They are created by the programmer to uniquely identify elements in the code.

Rules for Identifiers:


• Can contain letters (A–Z or a–z), digits (0–9), and underscore (_)

• Must begin with a letter or underscore (not a digit)

• Cannot use C++ keywords as identifiers (e.g., int, while)

• No spaces or special characters like @, #, $ etc.

• Case-sensitive (Marks and marks are different)

Variables and Constants


Variables
A variable is a named location in memory used to store data that can be changed during program
execution. In C++, variables must be declared before they are used.

Syntax: data_type variable_name;

Types of Variables:
Local Variables: Declared inside functions or blocks; accessible only within that scope.
Global Variables: Declared outside all functions; accessible throughout the program.
Static Variables: Retain their value between function calls.
Constants
A constant is a value that cannot be changed during program execution. It is used to define fixed values
that remain the same throughout the program.

Types of Constants:
Literal Constants: Direct values like 10, 3.14, 'A', "Hello"
Symbolic Constants: Declared using const keyword or #define directive.
Reference variables
Reference variable is an alternative name of already existing variable. It cannot be changed to refer
another variable and should be initialized at the time of declaration and cannot be NULL. The operator
‘&’ is used to declare reference variable.

The following is the syntax of reference variable.


datatype variable_name; // variable declaration

datatype& refer_var = variable_name; // reference variable

C++ Basic Data Types


Data types specify the type of data that a variable can store. Whenever a variable is defined in C++, the
compiler allocates some memory for that variable based on the data type.

1. Character Data Type (char): The character data type is used to store a single character.
The keyword used to define a character is char. Its size is 1 byte and it stores characters enclosed in
single quotes (‘ ‘). It can generally store upto 256 characters according to their ASCII codes.

Syntax char name;

2. Integer Data Type (int): Integer data type denotes that the given variable can store the
integer numbers. The keyword used to define integers is int. Its size is 4-bytes (for 64-bit) systems and
can store numbers for binary, octal, decimal and hexadecimal.

Syntax int name;

3. Boolean Data Type (bool): The boolean data type is used to store logical values: true(1)
or false(0). The keyword used to define a boolean variable is bool. Its size is 1 byte.

Syntax bool name;

4. Floating Point Data Type (float): Floating-point data type is used to store numbers
with decimal points. The keyword used to define floating-point numbers is float. Its size is 4 bytes (on 64-
bit systems).

Syntax float name;

5. Double Data Type (double):The double data type is used to store decimal numbers
with higher precision. The keyword used to define Double Data Type numbers is double. Its size is 8
bytes (on 64- bit systems).

Syntax double name;

6. Void Data Type (void): The void data type represents the absence of value. We cannot
create a variable of void type. It is used for pointer and functions that do not return any value using the
keyword void.

Syntax void functionName();

Streams in C++
In C++, streams are used for input and output (I/O) operations. A stream is a flow of data — either from
input devices to the program (input stream) or from the program to output devices (output stream). C++
handles I/O through the use of streams, provided by the iostream library.

Types of Streams in C++


Input Stream (istream):Used to read data into the program. Standard input stream: cin.
Output Stream (ostream): Used to display data from the program. Standard
output stream: cout

Error Stream (cerr and clog):cerr is used to output error messages (unbuffered). clog is
used for logging information (buffered).

C++ Operators
The C++ programming language provides a wide range of operators to perform mathematical, logical,
and other operations. An operator is a symbol used to perform mathematical and logical operations.

Arithmetic Operators
The arithmetic operators are the symbols that are used to perform basic mathematical operations like
addition, subtraction, multiplication, division and percentage modulo.

Relational Operators
The relational operators are the symbols that are used to compare two values. That means the relational
operators are used to check the relationship between two values.

Logical Operators
The logical operators are the symbols that are used to combine multiple conditions into one condition.

Increment & Decrement Operators


The increment and decrement operators are called unary operators because both need only one
operand. The increment operator adds one to the existing value of the operand and the decrement
operator subtracts one from the existing value of the operand.
Assignment Operators
The assignment operators are used to assign right-hand side value (Rvalue) to the left-hand side variable
(Lvalue). T

Bitwise Operators
The bitwise operators are used to perform bit-level operations in the c programming language. When we
use the bitwise operators, the operations are performed based on the binary values.

Conditional Operator
The conditional operator is also called a ternary operator because it requires three operands. This
operator is used for decision making.

Scope Resolution Operator (: :)


The scope resolution operator in C++ is used to access the global variable when both local and global
variables are having the same name, to refer to the static members of a class, and to define a function
definition outside the class.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy