SlideShare una empresa de Scribd logo
1 de 3
Descargar para leer sin conexión
C++ V2
C++ Classes and Objects
the central feature of C++ that supports object-oriented programming and are often called user-defined types.
C++ Class Definitions
When you define a class, you define a blueprint for a data type.
The keyword public determines the access attributes of the members of the class that follows it.
A public member can be accessed from outside the class anywhere within the scope of the class object.
You can also specify the members of a class as private or protected.
C++ Inheritance
Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an appli
cation.
This also provides an opportunity to reuse the code functionality and fast implementation time.
This existing class is called the base class, and the inherited class is referred to as the derived class.
The idea of inheritance implements the is-a relationship.
Access Control and Inheritance
Access public protected private
Same class yes yes yes
Derived classes yes yes no
Outside classes yes no no
Type of Inheritance
Multiple Inheritance
A C++ class can inherit members from more than one base class and here is the extended syntax −
class derived-class: access baseA, access baseB....
C++ Overloading (Operator and Function)
C++ allows you to specify more than one definition for a function or an operator in the same scope, which is called
function overloading and operator overloading respectively.
Function Overloading in C++
you can have multiple definitions for the same function name in the same scope.
Operators Overloading in C++
You can redefine or overload most of the built-in operators available in C++.
Polymorphism in C++
The word polymorphism means having many forms.
C++ polymorphism means that a call to a member function will cause a different function to be executed depending
on the type of object that invokes the function.
Compile time polymorphism or early binding : eg. Overloading
Run time polymorphism or late binding : eg. Overriding / Virtual Funtions
Pure Virtual Functions : It is possible that we want to include a virtual function in a base class so that it can be redef
ined in a derived class
Data Abstraction in C++
Data abstraction refers to providing only essential information to the outside world and hiding their background deta
ils,
i.e., to represent the needed information in program without presenting the details.
we can implement data abstraction by defining the member variable as private.
Data Encapsulation in C++
Encapsulation is an Object Oriented Programming concept that binds together the data and functions that manipulat
e the data.
Data encapsulation led to the important OOP concept of data hiding
Interfaces in C++ (Abstract Classes)
The C++ interfaces are implemented using abstract classes.
A class is made abstract by declaring at least one of its functions as pure virtual function.
C++ Files and Streams
we have been using the iostream standard library, which provides cin and cout methods for reading from standard i
nput and writing to standard output respectively.
To perform file processing in C++, header files <iostream> and <fstream> must be included in your C++ source file
.
fstream
This data type represents the file stream generally, and has the capabilities of both ofstream and ifstream which mea
ns it can create files, write information to files, and read information from files.
ofstream
This data type represents the output file stream and is used to create files and to write information to files.
ifstream
This data type represents the input file stream and is used to read information from files.
Modes:
ios::app
Append mode. All output to that file to be appended to the end
ios::in
Open a file for reading.
ios::out
Open a file for writing.
ios::trunc
If the file already exists, its contents will be truncated before opening the file.
File Position Pointers
The member functions are seekg ("seek get") for istream and seekp ("seek put") for ostream.
The first argument to seekg and seekp normally is a long integer.
A second argument can be specified to indicate the seek direction. (The seek direction can be ios::beg (the default) ,
ios::cur , ios::end).
C++ Exception Handling
An exception is a problem that arises during the execution of a program.
Exceptions provide a way to transfer control from one part of a program to another.
C++ exception handling is built upon three keywords: try, catch, and throw.
eg.
try {
// protected code
} catch( ExceptionName e ) {
// code to handle ExceptionName exception
}
C++ Dynamic Memory
Memory in your C++ program is divided into two parts −
The stack − All variables declared inside the function will take up memory from the stack.
The heap − This is unused memory of the program and can be used to allocate the memory dynamically when prog
ram runs.
new operator to allocate memory dynamically for any data-type.
you can use delete operator, which de-allocates memory that was previously allocated by new operator.
eg.
double* pvalue = NULL; // Pointer initialized with null
pvalue = new double; // Request memory for the variable
delete pvalue; // Release memory pointed to by pvalue
Dynamic Memory Allocation for Objects
Objects are no different from simple data types.
eg. : Box* myBoxArray = new Box[4];
delete [] myBoxArray; // Delete array

Más contenido relacionado

La actualidad más candente

Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data types
Manisha Keim
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
Rokonuzzaman Rony
 

La actualidad más candente (20)

2 expressions (ppt-2) in C++
2 expressions (ppt-2) in C++2 expressions (ppt-2) in C++
2 expressions (ppt-2) in C++
 
Basic Data Types in C++
Basic Data Types in C++ Basic Data Types in C++
Basic Data Types in C++
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data types
 
Function overloading ppt
Function overloading pptFunction overloading ppt
Function overloading ppt
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
C intro
C introC intro
C intro
 
Unit iii
Unit iiiUnit iii
Unit iii
 
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board ExamsC++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
 
Basic Structure Of C++
Basic Structure Of C++Basic Structure Of C++
Basic Structure Of C++
 
C++ Basics
C++ BasicsC++ Basics
C++ Basics
 
C# String
C# StringC# String
C# String
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
 
The smartpath information systems c plus plus
The smartpath information systems  c plus plusThe smartpath information systems  c plus plus
The smartpath information systems c plus plus
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures
 
Data Handling
Data HandlingData Handling
Data Handling
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteaching
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 

Similar a C++ Version 2

C,c++ interview q&a
C,c++ interview q&aC,c++ interview q&a
C,c++ interview q&a
Kumaran K
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
Jay Patel
 

Similar a C++ Version 2 (20)

Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++
 
7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.doc
7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.doc7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.doc
7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.doc
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
 
My c++
My c++My c++
My c++
 
Introduction to c_plus_plus
Introduction to c_plus_plusIntroduction to c_plus_plus
Introduction to c_plus_plus
 
Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
Unit 5.ppt
Unit 5.pptUnit 5.ppt
Unit 5.ppt
 
SRAVANByCPP
SRAVANByCPPSRAVANByCPP
SRAVANByCPP
 
Introduction to C++ Programming
Introduction to C++ ProgrammingIntroduction to C++ Programming
Introduction to C++ Programming
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1
 
C++ Object Oriented Programming
C++  Object Oriented ProgrammingC++  Object Oriented Programming
C++ Object Oriented Programming
 
Inheritance concepts Presentation (8).pptx
Inheritance concepts Presentation (8).pptxInheritance concepts Presentation (8).pptx
Inheritance concepts Presentation (8).pptx
 
Srgoc dotnet
Srgoc dotnetSrgoc dotnet
Srgoc dotnet
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
Introduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to itIntroduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to it
 
Introduction of C++ By Pawan Thakur
Introduction of C++ By Pawan ThakurIntroduction of C++ By Pawan Thakur
Introduction of C++ By Pawan Thakur
 
C,c++ interview q&a
C,c++ interview q&aC,c++ interview q&a
C,c++ interview q&a
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
 

Más de JIGAR MAKHIJA

Más de JIGAR MAKHIJA (20)

Php gd library
Php gd libraryPhp gd library
Php gd library
 
Php pattern matching
Php pattern matchingPhp pattern matching
Php pattern matching
 
Php cookies
Php cookiesPhp cookies
Php cookies
 
Php functions
Php functionsPhp functions
Php functions
 
Php sessions
Php sessionsPhp sessions
Php sessions
 
Php server variables
Php server variablesPhp server variables
Php server variables
 
Db function
Db functionDb function
Db function
 
SAP Ui5 content
SAP Ui5 contentSAP Ui5 content
SAP Ui5 content
 
Solution doc
Solution docSolution doc
Solution doc
 
Overview on Application protocols in Internet of Things
Overview on Application protocols in Internet of ThingsOverview on Application protocols in Internet of Things
Overview on Application protocols in Internet of Things
 
125 green iot
125 green iot125 green iot
125 green iot
 
Msp430 g2 with ble(Bluetooth Low Energy)
Msp430 g2 with ble(Bluetooth Low Energy)Msp430 g2 with ble(Bluetooth Low Energy)
Msp430 g2 with ble(Bluetooth Low Energy)
 
Embedded system lab work
Embedded system lab workEmbedded system lab work
Embedded system lab work
 
Presentation on iot- Internet of Things
Presentation on iot- Internet of ThingsPresentation on iot- Internet of Things
Presentation on iot- Internet of Things
 
Oracle
OracleOracle
Oracle
 
Learn Japanese -Basic kanji 120
Learn Japanese -Basic kanji 120Learn Japanese -Basic kanji 120
Learn Japanese -Basic kanji 120
 
View Alignment Techniques
View Alignment TechniquesView Alignment Techniques
View Alignment Techniques
 
Letters (complaints & invitations)
Letters (complaints & invitations)Letters (complaints & invitations)
Letters (complaints & invitations)
 
Letter Writing invitation-letter
Letter Writing invitation-letterLetter Writing invitation-letter
Letter Writing invitation-letter
 
Communication skills Revised PPT
Communication skills Revised PPTCommunication skills Revised PPT
Communication skills Revised PPT
 

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Último (20)

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 

C++ Version 2

  • 1. C++ V2 C++ Classes and Objects the central feature of C++ that supports object-oriented programming and are often called user-defined types. C++ Class Definitions When you define a class, you define a blueprint for a data type. The keyword public determines the access attributes of the members of the class that follows it. A public member can be accessed from outside the class anywhere within the scope of the class object. You can also specify the members of a class as private or protected. C++ Inheritance Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an appli cation. This also provides an opportunity to reuse the code functionality and fast implementation time. This existing class is called the base class, and the inherited class is referred to as the derived class. The idea of inheritance implements the is-a relationship. Access Control and Inheritance Access public protected private Same class yes yes yes Derived classes yes yes no Outside classes yes no no Type of Inheritance Multiple Inheritance A C++ class can inherit members from more than one base class and here is the extended syntax − class derived-class: access baseA, access baseB.... C++ Overloading (Operator and Function) C++ allows you to specify more than one definition for a function or an operator in the same scope, which is called function overloading and operator overloading respectively. Function Overloading in C++ you can have multiple definitions for the same function name in the same scope. Operators Overloading in C++ You can redefine or overload most of the built-in operators available in C++. Polymorphism in C++ The word polymorphism means having many forms. C++ polymorphism means that a call to a member function will cause a different function to be executed depending on the type of object that invokes the function. Compile time polymorphism or early binding : eg. Overloading Run time polymorphism or late binding : eg. Overriding / Virtual Funtions Pure Virtual Functions : It is possible that we want to include a virtual function in a base class so that it can be redef ined in a derived class
  • 2. Data Abstraction in C++ Data abstraction refers to providing only essential information to the outside world and hiding their background deta ils, i.e., to represent the needed information in program without presenting the details. we can implement data abstraction by defining the member variable as private. Data Encapsulation in C++ Encapsulation is an Object Oriented Programming concept that binds together the data and functions that manipulat e the data. Data encapsulation led to the important OOP concept of data hiding Interfaces in C++ (Abstract Classes) The C++ interfaces are implemented using abstract classes. A class is made abstract by declaring at least one of its functions as pure virtual function. C++ Files and Streams we have been using the iostream standard library, which provides cin and cout methods for reading from standard i nput and writing to standard output respectively. To perform file processing in C++, header files <iostream> and <fstream> must be included in your C++ source file . fstream This data type represents the file stream generally, and has the capabilities of both ofstream and ifstream which mea ns it can create files, write information to files, and read information from files. ofstream This data type represents the output file stream and is used to create files and to write information to files. ifstream This data type represents the input file stream and is used to read information from files. Modes: ios::app Append mode. All output to that file to be appended to the end ios::in Open a file for reading. ios::out Open a file for writing. ios::trunc If the file already exists, its contents will be truncated before opening the file. File Position Pointers The member functions are seekg ("seek get") for istream and seekp ("seek put") for ostream. The first argument to seekg and seekp normally is a long integer. A second argument can be specified to indicate the seek direction. (The seek direction can be ios::beg (the default) , ios::cur , ios::end). C++ Exception Handling An exception is a problem that arises during the execution of a program. Exceptions provide a way to transfer control from one part of a program to another. C++ exception handling is built upon three keywords: try, catch, and throw. eg. try {
  • 3. // protected code } catch( ExceptionName e ) { // code to handle ExceptionName exception } C++ Dynamic Memory Memory in your C++ program is divided into two parts − The stack − All variables declared inside the function will take up memory from the stack. The heap − This is unused memory of the program and can be used to allocate the memory dynamically when prog ram runs. new operator to allocate memory dynamically for any data-type. you can use delete operator, which de-allocates memory that was previously allocated by new operator. eg. double* pvalue = NULL; // Pointer initialized with null pvalue = new double; // Request memory for the variable delete pvalue; // Release memory pointed to by pvalue Dynamic Memory Allocation for Objects Objects are no different from simple data types. eg. : Box* myBoxArray = new Box[4]; delete [] myBoxArray; // Delete array