SlideShare a Scribd company logo
1 of 54
Object Oriented
Programming using C++
UNIT 1
BY:Ms SURBHI SAROHA
SYLLABUS
 Introduction to OOPs and C++ Elements
 Introduction to OOPs
 Features & Advantages of OOPs
 Different element of C++(Tokens, Keywords , Indentifiers , variable, constant
operators , Expression , String).
Introduction to OOPs and C++ Elements
 Object-oriented programming – As the name suggests uses objects in programming.
 Object-oriented programming aims to implement real-world entities like
inheritance, hiding, polymorphism, etc. in programming.
 The major purpose of C++ programming is to introduce the concept of object
orientation to the C programming language.
 Object Oriented Programming is a paradigm that provides many concepts such
as inheritance, data binding, polymorphism etc.
 The programming paradigm where everything is represented as an object is known
as truly object-oriented programming language.
 Smalltalk is considered as the first truly object-oriented programming language.
 Object-Oriented Programming is a methodology or paradigm to design a program
using classes and objects.
There are some basic concepts that act
as the building blocks of OOPs i.e.
 Class
 Objects
 Encapsulation
 Abstraction
 Polymorphism
 Inheritance
Characteristics of an Object-Oriented
Programming
Class
 The building block of C++ that leads to Object-Oriented programming is a
Class.
 It is 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 class is like a blueprint for an object.
 For Example: Consider the Class of Cars. There may be many cars with
different names and brands but all of them will share some common
properties like all of them will have 4 wheels, Speed Limit, Mileage range,
etc. So here, the Car is the class, and wheels, speed limits, and mileage are
their properties.
Object
 An Object is an identifiable entity with some characteristics and behavior.
 An Object is an instance of a Class.
 When a class is defined, no memory is allocated but when it is instantiated
(i.e. an object is created) memory is allocated.
 Object means a real word entity such as pen, chair, table etc.
 Any entity that has state and behavior is known as an object.
Encapsulation
 Binding (or wrapping) code and data together into a single unit is known as
encapsulation.
 For example: capsule, it is wrapped with different medicines.
 Encapsulation is typically understood as the grouping of related pieces of
information and data into a single entity.
 Encapsulation is the process of tying together data and the functions that work
with it in object-oriented programming.
 Take a look at a practical illustration of encapsulation: at a company, there are
various divisions, including the sales division, the finance division, and the
accounts division.
 All financial transactions are handled by the finance sector, which also maintains
records of all financial data.
 In a similar vein, the sales section is in charge of all tasks relating to sales and
maintains a record of each sale.
Cont…..
 Now, a scenario could occur when, for some reason, a financial official
requires all the information on sales for a specific month.
 Under the umbrella term "sales section," all of the employees who can
influence the sales section's data are grouped together.
 Data abstraction or concealing is another side effect of encapsulation.
 In the same way that encapsulation hides the data.
 In the aforementioned example, any other area cannot access any of the data
from any of the sections, such as sales, finance, or accounts.
Abstraction
 Hiding internal details and showing functionality is known as abstraction.
 Data abstraction is the process of exposing to the outside world only the
information that is absolutely necessary while concealing implementation or
background information.
 For example: phone call, we don't know the internal processing.
 In C++, we use abstract class and interface to achieve abstraction.
Polymorphism
 When one task is performed by different ways i.e. known as polymorphism.
 For example: to convince the customer differently, to draw something e.g.
shape or rectangle etc.
 Different situations may cause an operation to behave differently.
 The type of data utilized in the operation determines the behavior.
Inheritance
 When one object acquires all the properties and behaviours of parent
object i.e. known as inheritance. It provides code reusability. It is used to
achieve runtime polymorphism.
 Sub class - Subclass or Derived Class refers to a class that receives properties
from another class.
 Super class - The term "Base Class" or "Super Class" refers to the class from
which a subclass inherits its properties.
 Reusability - As a result, when we wish to create a new class, but an existing
class already contains some of the code we need, we can generate our new
class from the old class thanks to inheritance. This allows us to utilize the
fields and methods of the pre-existing class.
There are mainly five types of
Inheritance in C++ . They are as follows:
 Single Inheritance
 Multiple Inheritance
 Multilevel Inheritance
 Hierarchical Inheritance
 Hybrid Inheritance
Single Inheritance
 Single inheritance is defined as the inheritance in which a derived class is
inherited from the only one base class.
Where 'A' is the base class, and 'B' is the derived class.
Let's see the example of single level
inheritance which inherits the fields only.
 #include <iostream>
 using namespace std;
 class Account {
 public:
 float salary = 60000;
 };
 class Programmer: public Account {
 public:
 float bonus = 5000;
 };
 int main(void) {
Cont….
 Programmer p1;
 cout<<"Salary: "<<p1.salary<<endl;
 cout<<"Bonus: "<<p1.bonus<<endl;
 return 0;
 }
Let's see another example of inheritance
in C++ which inherits methods only.
 #include <iostream>
 using namespace std;
 class Animal {
 public:
 void eat() {
 cout<<"Eating..."<<endl;
 }
 };
 class Dog: public Animal
 {
 public:
 void bark(){
Cont….
 cout<<"Barking...";
 }
 };
 int main(void) {
 Dog d1;
 d1.eat();
 d1.bark();
 return 0;
 }
C++ Multilevel Inheritance
 Multilevel inheritance is a process of deriving a class from another derived
class.
When one class inherits another class which is further
inherited by another class, it is known as multi level
inheritance in C++. Inheritance is transitive so the last
derived class acquires all the members of all its base
classes.
Let's see the example of multi level
inheritance in C++.
 #include <iostream.h>
 using namespace std;
 class Animal {
 public:
 void eat() {
 cout<<"Eating..."<<endl;
 }
 };
 class Dog: public Animal
 {

Cont….
 public:
 void bark(){
 cout<<"Barking..."<<endl;
 }
 };

 class BabyDog: public Dog
 {
 public:
 void weep() {

Cont….
 cout<<"Weeping...";
 }
 };
 int main(void) {
 BabyDog d1;
 d1.eat();
 d1.bark();
 d1.weep();
 return 0;
 }
C++ Multiple Inheritance
 Multiple inheritance is the process of deriving a new class that inherits the
attributes from two or more classes.
Let's see a simple example of multiple
inheritance.
 #include <iostream>
 using namespace std;
 class A
 {
 protected:
 int a;
 public:
 void get_a(int n)
 {
 a = n;
 }
 };

Cont….
 class B
 {
 protected:
 int b;
 public:
 void get_b(int n)
 {
 b = n;
 }
 };
Cont…..
 class C : public A,public B
 {
 public:
 void display()
 {
 std::cout << "The value of a is : " <<a<< std::endl;
 std::cout << "The value of b is : " <<b<< std::endl;
 cout<<"Addition of a and b is : "<<a+b;
 }
 };
 int main()
 {
Cont….
 C c;
 c.get_a(10);
 c.get_b(20);
 c.display();

 return 0;
 }
C++ Hybrid Inheritance
 Hybrid inheritance is a combination of more than one type of inheritance.
Let's see a simple example:
 #include <iostream>
 using namespace std;
 class A
 {
 protected:
 int a;
 public:
 void get_a()
 {
 std::cout << "Enter the value of 'a' : " << std::endl;
 cin>>a;
 }
 };
Cont….
 class B : public A
 {
 protected:
 int b;
 public:
 void get_b()
 {
 std::cout << "Enter the value of 'b' : " << std::endl;
 cin>>b;
 }
 };
Cont….
 class C
 {
 protected:
 int c;
 public:
 void get_c()
 {
 std::cout << "Enter the value of c is : " << std::endl;
 cin>>c;
 }
 };
Cont…..
 class D : public B, public C
 {
 protected:
 int d;
 public:
 void mul()
 {
 get_a();
 get_b();
 get_c();
 std::cout << "Multiplication of a,b,c is : " <<a*b*c<< std::endl;
 }
 };
Cont….
 int main()
 {
 D d;
 d.mul();
 return 0;
 }
Output
 Enter the value of 'a' :
 10
 Enter the value of 'b' :
 20
 Enter the value of c is :
 30
 Multiplication of a,b,c is : 6000
C++ Hierarchical Inheritance
 Hierarchical inheritance is defined as the process of deriving more than one
class from a base class.
Syntax of Hierarchical inheritance:
 class A
 {
 // body of the class A.
 }
 class B : public A
 {
 // body of class B.
 }
 class C : public A
Cont….
 {
 // body of class C.
 }
 class D : public A
 {
 // body of class D.
 }
What Are Child and Parent classes?
 To clearly understand the concept of Inheritance, you must learn about two
terms on which the whole concept of inheritance is based - Child class and
Parent class.
 Child class: The class that inherits the characteristics of another class is
known as the child class or derived class. The number of child classes that can
be inherited from a single parent class is based upon the type of inheritance.
A child class will access the data members of the parent class according to
the visibility mode specified during the declaration of the child class.
 Parent class: The class from which the child class inherits its properties is
called the parent class or base class. A single parent class can derive multiple
child classes (Hierarchical Inheritance) or multiple parent classes can inherit
a single base class (Multiple Inheritance). This depends on the different types
of inheritance in C++.
The syntax for defining the child class and
parent class in all types of Inheritance in C++
is given below:
 class parent_class
 {
 //class definition of the parent class
 };
 class child_class : visibility_mode parent_class
 {
 //class definition of the child class
 };
Syntax Description
 parent_class: Name of the base class or the parent class.
 child_class: Name of the derived class or the child class.
 visibility_mode: Type of the visibility mode (i.e., private, protected, and
public) that specifies how the data members of the child class inherit from
the parent class.
Advantages of OOPs
 1. Troubleshooting is easier with the OOP language
 Suppose the user has no idea where the bug lies if there is an error within the
code.
 Also, the user has no idea where to look into the code to fix the error.
 This is quite difficult for standard programming languages.
 However, when Object-Oriented Programming is applied, the user knows
exactly where to look into the code whenever there is an error.
 There is no need to check other code sections as the error will show where
the trouble lies.
2. Code Reusability
 One of two important concepts that are provided by Object-Oriented Programming is the
concept of inheritance.
 Through inheritance, the same attributes of a class are not required to be written repeatedly.
 This avoids the issues where the same code has still to be written multiple times in a code.
 With the introduction of the concept of classes, the code section can be used as many times
as required in the program.
 Through the inheritance approach, a child class is created that inherits the fields and
methods of the parent class.
 The methods and values that are present in the parent class can be easily overridden.
 Through inheritance, the features of one class can be inherited by another class by extending
the class.
 Therefore, inheritance is vital for providing code reusability and also multilevel inheritance.
3. Productivity
 The productivity of two codes increases through the use of Object-Oriented
Programming.
 This is because the OOP has provided so many libraries that new programs
have become more accessible.
 Also, as it provides the facility of code reusability, the length of a code is
decreased, further enhancing the faster development of newer codes and
programs.
4. Data Redundancy
 By the term data redundancy, it means that the data is repeated twice.
 This means that the same data is present more than one time.
 In Object-Oriented programming the data redundancy is considered to be an
advantage.
 For example, the user wants to have a functionality that is similar to almost
all the classes.
 In such cases, the user can create classes with similar functionaries and
inherit them wherever required.
5. Code Flexibility
 The flexibility is offered through the concept of Polymorphism.
 A scenario can be considered for a better understanding of the concept.
 A person can behave differently whenever the surroundings change.
 For example, if the person is in a market, the person will behave like a
customer, or the behavior might get changed to a student when the person is
in a school or any institution.
6. Solving problems
 Problems can be efficiently solved by breaking down the problem into smaller
pieces and this makes as one of the big advantages of object-oriented
programming.
 If a complex problem is broken down into smaller pieces or components, it
becomes a good programming practice.
 Considering this fact, OOPS utilizes this feature where it breaks down the
code of the software into smaller pieces of the object into bite-size pieces
that are created one at a time.
 Once the problem is broken down, these broken pieces can be used again to
solve other problems.
Different element of C++
 Tokens
 A C++ program is composed of tokens which are the smallest individual
unit. Tokens can be one of several things, including keywords, identifiers,
constants, operators, or punctuation marks.
 There are 6 types of tokens in c++:
 Keyword
 Identifiers
 Constants
 Strings
 Special symbols
 Operators
Keywords
 In C++, keywords are reserved words that have a specific meaning in the
language and cannot be used as identifiers.
 Keywords are an essential part of the C++ language and are used to perform
specific tasks or operations.
 There are 95 keywords in c++.
 If you try to use a reserved keyword as an identifier, the compiler will
produce an error because it will not know what to do with the keyword.
Indentifiers
 The C++ identifier is a name used to identify a variable, function, class,
module, or any other user-defined item.
 An identifier starts with a letter A to Z or a to z or an underscore (_) followed
by zero or more letters, underscores, and digits (0 to 9).
 C++ does not allow punctuation characters such as @, $, and % within
identifiers.
 C++ is a case-sensitive programming language.
 Thus, Manpower and manpower are two different identifiers in C++.
Variable
 Variables in C++ is a name given to a memory location.
 It is the basic unit of storage in a program.
 The value stored in a variable can be changed during program execution.
 A variable is only a name given to a memory location, all the operations done
on the variable effects that memory location.
Constant operators
 Constants refer to fixed values that the program may not alter and they are
called literals.
 Constants can be of any of the basic data types and can be divided into
Integer Numerals, Floating-Point Numerals, Characters, Strings and Boolean
Values.
 Constants are treated just like regular variables except that their values
cannot be modified after their definition.
Expression
 An expression in C++ is an order collection of operators and operands which
specifies a computation.
 An expression can contain zero or more operators and one or more operands,
operands can be constants or variables.
 In addition, an expression can contain function calls as well which return
constant values.
 Examples of C++ expression:
 (a+b) - c
 (x/y) -z
 4a2 - 5b +c
 (a+b) * (x+y)
String
 Strings are used for storing text.
 A string variable contains a collection of characters surrounded by double
quotes.
 Example
 Create a variable of type string and assign it a value:
 string greeting = "Hello“;
 Example
 #include <iostream>
 #include <string>
 using namespace std;
Cont….
 int main() {
 string greeting = "Hello";
 cout << greeting;
 return 0;
 }
 THANK YOU 

More Related Content

What's hot

[OOP - Lec 08] Encapsulation (Information Hiding)
[OOP - Lec 08] Encapsulation (Information Hiding)[OOP - Lec 08] Encapsulation (Information Hiding)
[OOP - Lec 08] Encapsulation (Information Hiding)Muhammad Hammad Waseem
 
Abstraction in c++ and Real Life Example of Abstraction in C++
Abstraction in c++ and Real Life Example of Abstraction in C++Abstraction in c++ and Real Life Example of Abstraction in C++
Abstraction in c++ and Real Life Example of Abstraction in C++Hitesh Kumar
 
Object oriented programming concepts
Object oriented programming conceptsObject oriented programming concepts
Object oriented programming conceptsrahuld115
 
Object Oriented Programming Concepts for beginners
Object Oriented Programming Concepts for beginners Object Oriented Programming Concepts for beginners
Object Oriented Programming Concepts for beginners Vibhawa Nirmal
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingMoutaz Haddara
 
Abstract class and Interface
Abstract class and InterfaceAbstract class and Interface
Abstract class and InterfaceHaris Bin Zahid
 
Concept of OOPS with real life examples
Concept of OOPS with real life examplesConcept of OOPS with real life examples
Concept of OOPS with real life examplesNeha Sharma
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oopcolleges
 
Classes and objects
Classes and objectsClasses and objects
Classes and objectsNilesh Dalvi
 
Encapsulation in C++
Encapsulation in C++Encapsulation in C++
Encapsulation in C++Hitesh Kumar
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops conceptsNilesh Dalvi
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++Ankur Pandey
 
Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)MD Sulaiman
 
Introduction to oop
Introduction to oop Introduction to oop
Introduction to oop Kumar
 

What's hot (20)

[OOP - Lec 08] Encapsulation (Information Hiding)
[OOP - Lec 08] Encapsulation (Information Hiding)[OOP - Lec 08] Encapsulation (Information Hiding)
[OOP - Lec 08] Encapsulation (Information Hiding)
 
Oop
OopOop
Oop
 
Abstraction in c++ and Real Life Example of Abstraction in C++
Abstraction in c++ and Real Life Example of Abstraction in C++Abstraction in c++ and Real Life Example of Abstraction in C++
Abstraction in c++ and Real Life Example of Abstraction in C++
 
Object oriented programming concepts
Object oriented programming conceptsObject oriented programming concepts
Object oriented programming concepts
 
Object Oriented Programming Concepts for beginners
Object Oriented Programming Concepts for beginners Object Oriented Programming Concepts for beginners
Object Oriented Programming Concepts for beginners
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented Programming
 
Abstract class and Interface
Abstract class and InterfaceAbstract class and Interface
Abstract class and Interface
 
Oop Presentation
Oop PresentationOop Presentation
Oop Presentation
 
Concept of OOPS with real life examples
Concept of OOPS with real life examplesConcept of OOPS with real life examples
Concept of OOPS with real life examples
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oop
 
Wrapper classes
Wrapper classes Wrapper classes
Wrapper classes
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Encapsulation in C++
Encapsulation in C++Encapsulation in C++
Encapsulation in C++
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops concepts
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
 
Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Introduction to oop
Introduction to oop Introduction to oop
Introduction to oop
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
encapsulation
encapsulationencapsulation
encapsulation
 

Similar to Object Oriented Programming using C++(UNIT 1)

Similar to Object Oriented Programming using C++(UNIT 1) (20)

OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
香港六合彩 &raquo; SlideShare
香港六合彩 &raquo; SlideShare香港六合彩 &raquo; SlideShare
香港六合彩 &raquo; SlideShare
 
Introduction to object oriented programming concepts
Introduction to object oriented programming conceptsIntroduction to object oriented programming concepts
Introduction to object oriented programming concepts
 
C++ largest no between three nos
C++ largest no between three nosC++ largest no between three nos
C++ largest no between three nos
 
EEE 3rd year oops cat 3 ans
EEE 3rd year  oops cat 3  ansEEE 3rd year  oops cat 3  ans
EEE 3rd year oops cat 3 ans
 
Unit 5.ppt
Unit 5.pptUnit 5.ppt
Unit 5.ppt
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
 
Class and object C++.pptx
Class and object C++.pptxClass and object C++.pptx
Class and object C++.pptx
 
Oop concepts
Oop conceptsOop concepts
Oop concepts
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
 
Chapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classChapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-class
 
C++ oop
C++ oopC++ oop
C++ oop
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
SEMINAR
SEMINARSEMINAR
SEMINAR
 
Seminar
SeminarSeminar
Seminar
 
chapter-10-inheritance.pdf
chapter-10-inheritance.pdfchapter-10-inheritance.pdf
chapter-10-inheritance.pdf
 
Oop.concepts
Oop.conceptsOop.concepts
Oop.concepts
 

More from SURBHI SAROHA

Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2SURBHI SAROHA
 
Management Information System(Unit 2).pptx
Management Information System(Unit 2).pptxManagement Information System(Unit 2).pptx
Management Information System(Unit 2).pptxSURBHI SAROHA
 
Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)SURBHI SAROHA
 
Management Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxManagement Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxSURBHI SAROHA
 
Introduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptxIntroduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptxSURBHI SAROHA
 
Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)SURBHI SAROHA
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)SURBHI SAROHA
 
Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1SURBHI SAROHA
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)SURBHI SAROHA
 

More from SURBHI SAROHA (20)

Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2
 
Management Information System(Unit 2).pptx
Management Information System(Unit 2).pptxManagement Information System(Unit 2).pptx
Management Information System(Unit 2).pptx
 
Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)
 
Management Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxManagement Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptx
 
Introduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptxIntroduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptx
 
JAVA (UNIT 5)
JAVA (UNIT 5)JAVA (UNIT 5)
JAVA (UNIT 5)
 
DBMS (UNIT 5)
DBMS (UNIT 5)DBMS (UNIT 5)
DBMS (UNIT 5)
 
DBMS UNIT 4
DBMS UNIT 4DBMS UNIT 4
DBMS UNIT 4
 
JAVA(UNIT 4)
JAVA(UNIT 4)JAVA(UNIT 4)
JAVA(UNIT 4)
 
OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)
 
OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)
 
DBMS UNIT 3
DBMS UNIT 3DBMS UNIT 3
DBMS UNIT 3
 
JAVA (UNIT 3)
JAVA (UNIT 3)JAVA (UNIT 3)
JAVA (UNIT 3)
 
Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)
 
DBMS (UNIT 2)
DBMS (UNIT 2)DBMS (UNIT 2)
DBMS (UNIT 2)
 
JAVA UNIT 2
JAVA UNIT 2JAVA UNIT 2
JAVA UNIT 2
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)
 
Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
 

Recently uploaded

Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 

Recently uploaded (20)

Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 

Object Oriented Programming using C++(UNIT 1)

  • 1. Object Oriented Programming using C++ UNIT 1 BY:Ms SURBHI SAROHA
  • 2. SYLLABUS  Introduction to OOPs and C++ Elements  Introduction to OOPs  Features & Advantages of OOPs  Different element of C++(Tokens, Keywords , Indentifiers , variable, constant operators , Expression , String).
  • 3. Introduction to OOPs and C++ Elements  Object-oriented programming – As the name suggests uses objects in programming.  Object-oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism, etc. in programming.  The major purpose of C++ programming is to introduce the concept of object orientation to the C programming language.  Object Oriented Programming is a paradigm that provides many concepts such as inheritance, data binding, polymorphism etc.  The programming paradigm where everything is represented as an object is known as truly object-oriented programming language.  Smalltalk is considered as the first truly object-oriented programming language.  Object-Oriented Programming is a methodology or paradigm to design a program using classes and objects.
  • 4. There are some basic concepts that act as the building blocks of OOPs i.e.  Class  Objects  Encapsulation  Abstraction  Polymorphism  Inheritance
  • 5. Characteristics of an Object-Oriented Programming
  • 6. Class  The building block of C++ that leads to Object-Oriented programming is a Class.  It is 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 class is like a blueprint for an object.  For Example: Consider the Class of Cars. There may be many cars with different names and brands but all of them will share some common properties like all of them will have 4 wheels, Speed Limit, Mileage range, etc. So here, the Car is the class, and wheels, speed limits, and mileage are their properties.
  • 7. Object  An Object is an identifiable entity with some characteristics and behavior.  An Object is an instance of a Class.  When a class is defined, no memory is allocated but when it is instantiated (i.e. an object is created) memory is allocated.  Object means a real word entity such as pen, chair, table etc.  Any entity that has state and behavior is known as an object.
  • 8. Encapsulation  Binding (or wrapping) code and data together into a single unit is known as encapsulation.  For example: capsule, it is wrapped with different medicines.  Encapsulation is typically understood as the grouping of related pieces of information and data into a single entity.  Encapsulation is the process of tying together data and the functions that work with it in object-oriented programming.  Take a look at a practical illustration of encapsulation: at a company, there are various divisions, including the sales division, the finance division, and the accounts division.  All financial transactions are handled by the finance sector, which also maintains records of all financial data.  In a similar vein, the sales section is in charge of all tasks relating to sales and maintains a record of each sale.
  • 9. Cont…..  Now, a scenario could occur when, for some reason, a financial official requires all the information on sales for a specific month.  Under the umbrella term "sales section," all of the employees who can influence the sales section's data are grouped together.  Data abstraction or concealing is another side effect of encapsulation.  In the same way that encapsulation hides the data.  In the aforementioned example, any other area cannot access any of the data from any of the sections, such as sales, finance, or accounts.
  • 10. Abstraction  Hiding internal details and showing functionality is known as abstraction.  Data abstraction is the process of exposing to the outside world only the information that is absolutely necessary while concealing implementation or background information.  For example: phone call, we don't know the internal processing.  In C++, we use abstract class and interface to achieve abstraction.
  • 11. Polymorphism  When one task is performed by different ways i.e. known as polymorphism.  For example: to convince the customer differently, to draw something e.g. shape or rectangle etc.  Different situations may cause an operation to behave differently.  The type of data utilized in the operation determines the behavior.
  • 12. Inheritance  When one object acquires all the properties and behaviours of parent object i.e. known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism.  Sub class - Subclass or Derived Class refers to a class that receives properties from another class.  Super class - The term "Base Class" or "Super Class" refers to the class from which a subclass inherits its properties.  Reusability - As a result, when we wish to create a new class, but an existing class already contains some of the code we need, we can generate our new class from the old class thanks to inheritance. This allows us to utilize the fields and methods of the pre-existing class.
  • 13. There are mainly five types of Inheritance in C++ . They are as follows:  Single Inheritance  Multiple Inheritance  Multilevel Inheritance  Hierarchical Inheritance  Hybrid Inheritance
  • 14. Single Inheritance  Single inheritance is defined as the inheritance in which a derived class is inherited from the only one base class. Where 'A' is the base class, and 'B' is the derived class.
  • 15. Let's see the example of single level inheritance which inherits the fields only.  #include <iostream>  using namespace std;  class Account {  public:  float salary = 60000;  };  class Programmer: public Account {  public:  float bonus = 5000;  };  int main(void) {
  • 16. Cont….  Programmer p1;  cout<<"Salary: "<<p1.salary<<endl;  cout<<"Bonus: "<<p1.bonus<<endl;  return 0;  }
  • 17. Let's see another example of inheritance in C++ which inherits methods only.  #include <iostream>  using namespace std;  class Animal {  public:  void eat() {  cout<<"Eating..."<<endl;  }  };  class Dog: public Animal  {  public:  void bark(){
  • 18. Cont….  cout<<"Barking...";  }  };  int main(void) {  Dog d1;  d1.eat();  d1.bark();  return 0;  }
  • 19. C++ Multilevel Inheritance  Multilevel inheritance is a process of deriving a class from another derived class. When one class inherits another class which is further inherited by another class, it is known as multi level inheritance in C++. Inheritance is transitive so the last derived class acquires all the members of all its base classes.
  • 20. Let's see the example of multi level inheritance in C++.  #include <iostream.h>  using namespace std;  class Animal {  public:  void eat() {  cout<<"Eating..."<<endl;  }  };  class Dog: public Animal  { 
  • 21. Cont….  public:  void bark(){  cout<<"Barking..."<<endl;  }  };   class BabyDog: public Dog  {  public:  void weep() { 
  • 22. Cont….  cout<<"Weeping...";  }  };  int main(void) {  BabyDog d1;  d1.eat();  d1.bark();  d1.weep();  return 0;  }
  • 23. C++ Multiple Inheritance  Multiple inheritance is the process of deriving a new class that inherits the attributes from two or more classes.
  • 24. Let's see a simple example of multiple inheritance.  #include <iostream>  using namespace std;  class A  {  protected:  int a;  public:  void get_a(int n)  {  a = n;  }  }; 
  • 25. Cont….  class B  {  protected:  int b;  public:  void get_b(int n)  {  b = n;  }  };
  • 26. Cont…..  class C : public A,public B  {  public:  void display()  {  std::cout << "The value of a is : " <<a<< std::endl;  std::cout << "The value of b is : " <<b<< std::endl;  cout<<"Addition of a and b is : "<<a+b;  }  };  int main()  {
  • 27. Cont….  C c;  c.get_a(10);  c.get_b(20);  c.display();   return 0;  }
  • 28. C++ Hybrid Inheritance  Hybrid inheritance is a combination of more than one type of inheritance.
  • 29. Let's see a simple example:  #include <iostream>  using namespace std;  class A  {  protected:  int a;  public:  void get_a()  {  std::cout << "Enter the value of 'a' : " << std::endl;  cin>>a;  }  };
  • 30. Cont….  class B : public A  {  protected:  int b;  public:  void get_b()  {  std::cout << "Enter the value of 'b' : " << std::endl;  cin>>b;  }  };
  • 31. Cont….  class C  {  protected:  int c;  public:  void get_c()  {  std::cout << "Enter the value of c is : " << std::endl;  cin>>c;  }  };
  • 32. Cont…..  class D : public B, public C  {  protected:  int d;  public:  void mul()  {  get_a();  get_b();  get_c();  std::cout << "Multiplication of a,b,c is : " <<a*b*c<< std::endl;  }  };
  • 33. Cont….  int main()  {  D d;  d.mul();  return 0;  }
  • 34. Output  Enter the value of 'a' :  10  Enter the value of 'b' :  20  Enter the value of c is :  30  Multiplication of a,b,c is : 6000
  • 35. C++ Hierarchical Inheritance  Hierarchical inheritance is defined as the process of deriving more than one class from a base class.
  • 36. Syntax of Hierarchical inheritance:  class A  {  // body of the class A.  }  class B : public A  {  // body of class B.  }  class C : public A
  • 37. Cont….  {  // body of class C.  }  class D : public A  {  // body of class D.  }
  • 38. What Are Child and Parent classes?  To clearly understand the concept of Inheritance, you must learn about two terms on which the whole concept of inheritance is based - Child class and Parent class.  Child class: The class that inherits the characteristics of another class is known as the child class or derived class. The number of child classes that can be inherited from a single parent class is based upon the type of inheritance. A child class will access the data members of the parent class according to the visibility mode specified during the declaration of the child class.  Parent class: The class from which the child class inherits its properties is called the parent class or base class. A single parent class can derive multiple child classes (Hierarchical Inheritance) or multiple parent classes can inherit a single base class (Multiple Inheritance). This depends on the different types of inheritance in C++.
  • 39. The syntax for defining the child class and parent class in all types of Inheritance in C++ is given below:  class parent_class  {  //class definition of the parent class  };  class child_class : visibility_mode parent_class  {  //class definition of the child class  };
  • 40. Syntax Description  parent_class: Name of the base class or the parent class.  child_class: Name of the derived class or the child class.  visibility_mode: Type of the visibility mode (i.e., private, protected, and public) that specifies how the data members of the child class inherit from the parent class.
  • 41. Advantages of OOPs  1. Troubleshooting is easier with the OOP language  Suppose the user has no idea where the bug lies if there is an error within the code.  Also, the user has no idea where to look into the code to fix the error.  This is quite difficult for standard programming languages.  However, when Object-Oriented Programming is applied, the user knows exactly where to look into the code whenever there is an error.  There is no need to check other code sections as the error will show where the trouble lies.
  • 42. 2. Code Reusability  One of two important concepts that are provided by Object-Oriented Programming is the concept of inheritance.  Through inheritance, the same attributes of a class are not required to be written repeatedly.  This avoids the issues where the same code has still to be written multiple times in a code.  With the introduction of the concept of classes, the code section can be used as many times as required in the program.  Through the inheritance approach, a child class is created that inherits the fields and methods of the parent class.  The methods and values that are present in the parent class can be easily overridden.  Through inheritance, the features of one class can be inherited by another class by extending the class.  Therefore, inheritance is vital for providing code reusability and also multilevel inheritance.
  • 43. 3. Productivity  The productivity of two codes increases through the use of Object-Oriented Programming.  This is because the OOP has provided so many libraries that new programs have become more accessible.  Also, as it provides the facility of code reusability, the length of a code is decreased, further enhancing the faster development of newer codes and programs.
  • 44. 4. Data Redundancy  By the term data redundancy, it means that the data is repeated twice.  This means that the same data is present more than one time.  In Object-Oriented programming the data redundancy is considered to be an advantage.  For example, the user wants to have a functionality that is similar to almost all the classes.  In such cases, the user can create classes with similar functionaries and inherit them wherever required.
  • 45. 5. Code Flexibility  The flexibility is offered through the concept of Polymorphism.  A scenario can be considered for a better understanding of the concept.  A person can behave differently whenever the surroundings change.  For example, if the person is in a market, the person will behave like a customer, or the behavior might get changed to a student when the person is in a school or any institution.
  • 46. 6. Solving problems  Problems can be efficiently solved by breaking down the problem into smaller pieces and this makes as one of the big advantages of object-oriented programming.  If a complex problem is broken down into smaller pieces or components, it becomes a good programming practice.  Considering this fact, OOPS utilizes this feature where it breaks down the code of the software into smaller pieces of the object into bite-size pieces that are created one at a time.  Once the problem is broken down, these broken pieces can be used again to solve other problems.
  • 47. Different element of C++  Tokens  A C++ program is composed of tokens which are the smallest individual unit. Tokens can be one of several things, including keywords, identifiers, constants, operators, or punctuation marks.  There are 6 types of tokens in c++:  Keyword  Identifiers  Constants  Strings  Special symbols  Operators
  • 48. Keywords  In C++, keywords are reserved words that have a specific meaning in the language and cannot be used as identifiers.  Keywords are an essential part of the C++ language and are used to perform specific tasks or operations.  There are 95 keywords in c++.  If you try to use a reserved keyword as an identifier, the compiler will produce an error because it will not know what to do with the keyword.
  • 49. Indentifiers  The C++ identifier is a name used to identify a variable, function, class, module, or any other user-defined item.  An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores, and digits (0 to 9).  C++ does not allow punctuation characters such as @, $, and % within identifiers.  C++ is a case-sensitive programming language.  Thus, Manpower and manpower are two different identifiers in C++.
  • 50. Variable  Variables in C++ is a name given to a memory location.  It is the basic unit of storage in a program.  The value stored in a variable can be changed during program execution.  A variable is only a name given to a memory location, all the operations done on the variable effects that memory location.
  • 51. Constant operators  Constants refer to fixed values that the program may not alter and they are called literals.  Constants can be of any of the basic data types and can be divided into Integer Numerals, Floating-Point Numerals, Characters, Strings and Boolean Values.  Constants are treated just like regular variables except that their values cannot be modified after their definition.
  • 52. Expression  An expression in C++ is an order collection of operators and operands which specifies a computation.  An expression can contain zero or more operators and one or more operands, operands can be constants or variables.  In addition, an expression can contain function calls as well which return constant values.  Examples of C++ expression:  (a+b) - c  (x/y) -z  4a2 - 5b +c  (a+b) * (x+y)
  • 53. String  Strings are used for storing text.  A string variable contains a collection of characters surrounded by double quotes.  Example  Create a variable of type string and assign it a value:  string greeting = "Hello“;  Example  #include <iostream>  #include <string>  using namespace std;
  • 54. Cont….  int main() {  string greeting = "Hello";  cout << greeting;  return 0;  }  THANK YOU 