SlideShare a Scribd company logo
1 of 34
C++ - Introduction
Sangharsh Agarwal
Introduction of C++
• C++ is successor to C, a procedural language.
• C++ (Previously named as ‘C with classes’) was
developed in early 1980’s by Bjarne
Stroustrup of AT&T Bell labs.
• Most of C is subset of C++.
• C++ is Object Oriented Programming language
(Not completly OOP language due to its
predecessor i.e. C).
Programming
• Programming is the
craft of transforming
requirements into
something that
computer can
execute.
• Programmer creates
the “recipe” that
computer can
understand and
execute.
Procedural programming
• Programmer
implements
requirement by breaking
down them to small
steps (functional
decomposition).
Object oriented programming
• Break down requirements into objects with
responsibilities, not into functional steps.
• Lets you think about object hierarchies and
interactions instead of program control flow.
• A completely different programming
paradigm.
Why OOPS?
• To modularize software development, just like
any other engineering discipline.
• To make software projects more manageable and
predictable.
• For better maintainability, since software
maintenance costs were more than the
development costs.
• For more re-use code and prevent ‘reinvention of
wheel’** every time.
**reinventing the wheel is a phrase that means to duplicate a basic method that has
already previously been created or optimized by others
Features of OOP
• Emphasis on data rather on procedure.
• Programs are divided into what are known as
“objects”.
• Functions that operate on data of an object
are tied together in a data structure.
• Object may communicate with each other
through functions.
• New data and functions can be added easily
whenever necessary.
Features of OOP
• Classes and Objects
• Message and Methods
• Encapsulation
• Inheritance
• Polymorphism
• Abstraction
Classes and Objects
• Object oriented programming uses objects.
• An object is a thing, both tangible and
intangible. Account, Vehicle, Employee etc.
• To create an object inside a compute program
we must provide a definition for objects – how
they behave and what kinds of information
they maintain – called a class.
• An object is called an instance of a class.
• Object interacts with each other via message.
Encapsulation
• Encapsulation is the packing of data and
functions into a single component. The features
of encapsulation are supported using classes in
most object-oriented programming languages,
although other alternatives also exist.
• Encapsulation is:
– A language mechanism for restricting access to some
of the object's components. (public, private,
protected)
– A language construct that facilitates the bundling of
data with the methods (or other functions) operating
on that data.
Inheritance
• Inheritance is a mechanism in OOP to design
two or more entities that are different but
share many common features.
– Feature common to all classes are defined in the
superclass.
– The classes that inherit common features from the
superclass are called subclasses.
Inheritance Example
Polymorphism
• Polymorphism indicates the meaning of “many
forms”.
• Polymorphism present a method that can have
many definitions. Polymorphism is related to
“overloading” and “overriding”.
• Overloading indicates a method can have
different definitions by defining different type of
parameters.
– getPrice() : void
– getPrice(string name) : void
Polymorphism….
• Overriding indicates subclass and the parent
class has the same methods, parameters and
return type(namely to redefine the methods
in parent class).
Abstraction
• Abstraction is the process of modeling only
relevant features
– Hide unnecessary details which are irrelevant for
current for current purpose (and/or user).
• Reduces complexity and aids understanding.
• Abstraction provides the freedom to defer
implementation decisions by avoiding
commitments to details.
Abstraction example
#include <iostream>
using namespace std;
class Adder{
public:
// constructor
Adder(int i = 0)
{
total = i;
}
// interface to outside world
void addNum(int number)
{
total += number;
}
// interface to outside world
int getTotal()
{
return total;
};
private:
// hidden data from outside world
int total;
};
int main( )
{
Adder a;
a.addNum(10);
a.addNum(20);
a.addNum(30);
cout << "Total " << a.getTotal()
<<endl;
return 0;
}
Getting Started
• Step 1: Write the Source Code:
• Step 2: Build the Executable Code:
Getting Started….
• Step 3: Run the Executable Code:
• /* ...... */
// ... until the end of the line
– These are called comments. Comments are NOT executable and are
ignored by the compiler; but they provide useful explanation and
documentation to your readers (and to yourself three days later). There
are two kinds of comments:
• Multi-line Comment: begins with /* and ends with */. It may span more than one
lines (as in Lines 1-3).
• End-of-line Comment: begins with // and lasts until the end of the current line (as in
Lines 4, 7, 8, 9 and 10).
• #include <iostream>
using namespace std;
– The "#include" is called a preprocessor directive.
– Preprocessor directives begin with a # sign.
– They are processed before compilation.
– The directive "#include <iostream>" tells the preprocessor to
include the "iostream" header file to support input/output operations.
– The "using namespace std;" statement declares std as the default
namespace used in this program. The names cout and endl, which is
used in this program, belong to the std namespace. These two lines shall
be present in all our programs.
• int main() { ... body ... }
– defines the so-called main() function. The main() function is the entry point of program
execution. main() is required to return an int (integer).
• cout << "hello, world" << endl;
– "cout" refers to the standard output (or Console OUTput). The symbol << is called the
stream insertion operator (or put-to operator), which is used to put the string "hello,
world" to the console. "endl" denotes the END-of-Line or newline, which is put to the
console to bring the cursor to the beginning of the next line.
• return 0;
– terminates the main() function and returns a value of 0 to the operating system.
Typically, return value of 0 signals normal termination; whereas value of non-zero
(usually 1) signals abnormal termination. This line is optional. C++ compiler will implicitly
insert a "return 0;" to the end of the main() function.
C++ Terminology and Syntax
• Statement: A programming statement performs a piece of programming
action. It must be terminated by a semicolon (;) (just like an English
sentence is ended with a period), as in Lines 5, 8 and 9.
• Preprocessor Directive: The #include (Line 4) is a preprocessor directive
and NOT a programming statement. A preprocessor directive begins with
hash sign (#). It is processed before compiling the program. A preprocessor
directive is NOT terminated by a semicolon - take note of this unusual rule.
• Block: A block is a group of programming statements enclosed by braces {
}. This group of statements is treated as one single unit. There is one block
in this program, which contains the body of the main() function. There is
no need to put a semicolon after the closing brace.
C++ Terminology and Syntax…
• Comments: A multi-line comment begins with /* and ends with */, which
may span more than one line. An end-of-line comment begins with // and
lasts till the end of the line. Comments are NOT executable statements
and are ignored by the compiler; but they provide useful explanation and
documentation. Use comments liberally.
• Whitespaces: Blank, tab, and newline are collectively called whitespaces.
Extra whitespaces are ignored, i.e., only one whitespace is needed to
separate the tokens. Nevertheless, extra white spaces and newlines could
help you and your readers better understand your program. Use extra
whitespaces and newlines liberally.
• Case Sensitivity: C++ is case sensitive - a ROSE is NOT a Rose, and is NOT a
rose.
The Process of Writing a C++ Program
• Step 1: Write the source codes (.cpp) and
header files (.h).
• Step 2: Pre-process the source codes
according to the preprocessor directives.
Preprocessor directives begin with a hash
sign (#), e.g., #include and #define. They
indicate that certain manipulations (such
as including another file or replacement of
symbols) are to be performed BEFORE
compilation.
• Step 3: Compile the pre-processed source
codes into object codes (.obj, .o).
• Step 4: Link the compiled object codes
with other object codes and the library
object codes (.lib, .a) to produce the
executable code (.exe).
• Step 5: Load the executable code into
computer memory.
• Step 6: Run the executable code, with the
input to produce the desried output.
C++ Program Template
Pointers
• A pointer is a variable whose value is the address of another
variable.
• The general form of a pointer variable declaration is:
type *var-name;
• Here, type is the pointer's base type; it must be a valid C++ type
and var-name is the name of the pointer variable.
• int *ip; // pointer to an integer
• double *dp; // pointer to a double
• float *fp; // pointer to a float
• char *ch // pointer to character
Reading Pointers in C++:
1. const char * ptr :- ptr is pointer to character constant.
2. char const * ptr :- ptr is pointer to constant character. Both 1 and 2 is
same.
3. char *const ptr :- ptr is constant pointer to character.
4. const char * const ptr :- ptr is constant pointer to constant character.
Pointers in C++…
Output:
Value of var variable: 20
Address stored in ip variable: 0xbfc601ac
Value of *ip variable: 20
C++ References
• A reference variable is an alias, that is, another name for an
already existing variable. Once a reference is initialized with
a variable, either the variable name or the reference name
may be used to refer to the variable.
• Creating References in C++:
– Think of a variable name as a label attached to the variable's
location in memory. You can then think of a reference as a
second label attached to that memory location. Therefore, you
can access the contents of the variable through either the
original variable name or the reference. For example, suppose
we have the following example:
• int i = 17;
– We can declare reference variables for i as follows.
• int& r = i;
C++ References…
Output:
Value of i : 5
Value of i reference : 5
Value of d : 11.7
Value of d reference : 11.7
C++ References vs Pointers:
• References are often confused with pointers but
three major differences between references and
pointers are: (Program)
– You cannot have NULL references. You must always be
able to assume that a reference is connected to a
legitimate piece of storage.
– Once a reference is initialized to an object, it cannot
be changed to refer to another object. Pointers can be
pointed to another object at any time.
– A reference must be initialized when it is created.
Pointers can be initialized at any time.
Classes example:
• A class is used to specify the form of an object and it combines data
representation and methods for manipulating that data into one neat
package. The data and functions within a class are called members of the
class.
• C++ class definitions:
class Box {
public:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box };
• Define C++ Objects
Box Box1; // Declare Box1 of type Box
Box Box2; // Declare Box2 of type Box
Classes with Constructor
• A class constructor is a special member
function of a class that is executed whenever
we create new objects of that class.
Constructor..
Output:
Object is being created
Length of line : 6
Parameterized Constructor
Output:
Object is being created, length = 10
Length of line : 10
Length of line : 6
References
• http://ocw.mit.edu/courses/electrical-
engineering-and-computer-science/6-096-
introduction-to-c-january-iap-2011/lecture-
notes/MIT6_096IAP11_lec03.pdf
• http://www.slideshare.net/sangharshcs/advan
ce-oops-concepts-8752156

More Related Content

What's hot

FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT03062679929
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in javaNilesh Dalvi
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Michelle Anne Meralpis
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaTech_MX
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHPVibrant Technologies & Computers
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops conceptsNilesh Dalvi
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functionsHarsh Patel
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)Ritika Sharma
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++Muhammad Waqas
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member FunctionsMOHIT AGARWAL
 
Procedural vs. object oriented programming
Procedural vs. object oriented programmingProcedural vs. object oriented programming
Procedural vs. object oriented programmingHaris Bin Zahid
 

What's hot (20)

FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops concepts
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Constructors and Destructor in C++
Constructors and Destructor in C++Constructors and Destructor in C++
Constructors and Destructor in C++
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Procedural vs. object oriented programming
Procedural vs. object oriented programmingProcedural vs. object oriented programming
Procedural vs. object oriented programming
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 

Viewers also liked

Viewers also liked (20)

Lecture01
Lecture01Lecture01
Lecture01
 
Intro to c++
Intro to c++Intro to c++
Intro to c++
 
History of C/C++ Language
History of C/C++ LanguageHistory of C/C++ Language
History of C/C++ Language
 
c++ program on bookshop for class 12th boards
c++ program on bookshop for class 12th boardsc++ program on bookshop for class 12th boards
c++ program on bookshop for class 12th boards
 
Overview of c++ language
Overview of c++ language   Overview of c++ language
Overview of c++ language
 
C vs c++
C vs c++C vs c++
C vs c++
 
C++11
C++11C++11
C++11
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Language
 
C vs c++
C vs c++C vs c++
C vs c++
 
difference between c c++ c#
difference between c c++ c#difference between c c++ c#
difference between c c++ c#
 
C++ ppt
C++ pptC++ ppt
C++ ppt
 
Bookstore powerpoint
Bookstore powerpointBookstore powerpoint
Bookstore powerpoint
 
School Management (c++)
School Management (c++) School Management (c++)
School Management (c++)
 
Project report
Project reportProject report
Project report
 
Online bookshop
Online bookshopOnline bookshop
Online bookshop
 
Ppt on ONLINE BOOK STORE
Ppt on ONLINE BOOK STOREPpt on ONLINE BOOK STORE
Ppt on ONLINE BOOK STORE
 
College management project
College management projectCollege management project
College management project
 
01 c++ Intro.ppt
01 c++ Intro.ppt01 c++ Intro.ppt
01 c++ Intro.ppt
 
Ch15 software reuse
Ch15 software reuseCh15 software reuse
Ch15 software reuse
 
C++ ppt
C++ pptC++ ppt
C++ ppt
 

Similar to Introduction Of C++

C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...ANUSUYA S
 
Object oriented programming 7 first steps in oop using c++
Object oriented programming 7 first steps in oop using  c++Object oriented programming 7 first steps in oop using  c++
Object oriented programming 7 first steps in oop using c++Vaibhav Khanna
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 
Whole c++ lectures ITM1 Th
Whole c++ lectures ITM1 ThWhole c++ lectures ITM1 Th
Whole c++ lectures ITM1 ThAram Mohammed
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++cpjcollege
 
PRINCE PRESENTATION(1).pptx
PRINCE PRESENTATION(1).pptxPRINCE PRESENTATION(1).pptx
PRINCE PRESENTATION(1).pptxSajalKesharwani2
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.pptManiMala75
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.pptManiMala75
 
Chapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptChapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptANISHYAPIT
 
C++ vs C#
C++ vs C#C++ vs C#
C++ vs C#sudipv
 

Similar to Introduction Of C++ (20)

Presentation c++
Presentation c++Presentation c++
Presentation c++
 
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
 
Prog1-L1.pdf
Prog1-L1.pdfProg1-L1.pdf
Prog1-L1.pdf
 
Object oriented programming 7 first steps in oop using c++
Object oriented programming 7 first steps in oop using  c++Object oriented programming 7 first steps in oop using  c++
Object oriented programming 7 first steps in oop using c++
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
C++ basics
C++ basicsC++ basics
C++ basics
 
SRAVANByCPP
SRAVANByCPPSRAVANByCPP
SRAVANByCPP
 
Whole c++ lectures ITM1 Th
Whole c++ lectures ITM1 ThWhole c++ lectures ITM1 Th
Whole c++ lectures ITM1 Th
 
73d32 session1 c++
73d32 session1 c++73d32 session1 c++
73d32 session1 c++
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
 
C++
C++C++
C++
 
PRINCE PRESENTATION(1).pptx
PRINCE PRESENTATION(1).pptxPRINCE PRESENTATION(1).pptx
PRINCE PRESENTATION(1).pptx
 
Chap 2 c++
Chap 2 c++Chap 2 c++
Chap 2 c++
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
2CPP02 - C++ Primer
2CPP02 - C++ Primer2CPP02 - C++ Primer
2CPP02 - C++ Primer
 
Chapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptChapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this ppt
 
C++ vs C#
C++ vs C#C++ vs C#
C++ vs C#
 

Recently uploaded

cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 

Recently uploaded (20)

cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 

Introduction Of C++

  • 2. Introduction of C++ • C++ is successor to C, a procedural language. • C++ (Previously named as ‘C with classes’) was developed in early 1980’s by Bjarne Stroustrup of AT&T Bell labs. • Most of C is subset of C++. • C++ is Object Oriented Programming language (Not completly OOP language due to its predecessor i.e. C).
  • 3. Programming • Programming is the craft of transforming requirements into something that computer can execute. • Programmer creates the “recipe” that computer can understand and execute.
  • 4. Procedural programming • Programmer implements requirement by breaking down them to small steps (functional decomposition).
  • 5. Object oriented programming • Break down requirements into objects with responsibilities, not into functional steps. • Lets you think about object hierarchies and interactions instead of program control flow. • A completely different programming paradigm.
  • 6. Why OOPS? • To modularize software development, just like any other engineering discipline. • To make software projects more manageable and predictable. • For better maintainability, since software maintenance costs were more than the development costs. • For more re-use code and prevent ‘reinvention of wheel’** every time. **reinventing the wheel is a phrase that means to duplicate a basic method that has already previously been created or optimized by others
  • 7. Features of OOP • Emphasis on data rather on procedure. • Programs are divided into what are known as “objects”. • Functions that operate on data of an object are tied together in a data structure. • Object may communicate with each other through functions. • New data and functions can be added easily whenever necessary.
  • 8. Features of OOP • Classes and Objects • Message and Methods • Encapsulation • Inheritance • Polymorphism • Abstraction
  • 9. Classes and Objects • Object oriented programming uses objects. • An object is a thing, both tangible and intangible. Account, Vehicle, Employee etc. • To create an object inside a compute program we must provide a definition for objects – how they behave and what kinds of information they maintain – called a class. • An object is called an instance of a class. • Object interacts with each other via message.
  • 10. Encapsulation • Encapsulation is the packing of data and functions into a single component. The features of encapsulation are supported using classes in most object-oriented programming languages, although other alternatives also exist. • Encapsulation is: – A language mechanism for restricting access to some of the object's components. (public, private, protected) – A language construct that facilitates the bundling of data with the methods (or other functions) operating on that data.
  • 11. Inheritance • Inheritance is a mechanism in OOP to design two or more entities that are different but share many common features. – Feature common to all classes are defined in the superclass. – The classes that inherit common features from the superclass are called subclasses.
  • 13. Polymorphism • Polymorphism indicates the meaning of “many forms”. • Polymorphism present a method that can have many definitions. Polymorphism is related to “overloading” and “overriding”. • Overloading indicates a method can have different definitions by defining different type of parameters. – getPrice() : void – getPrice(string name) : void
  • 14. Polymorphism…. • Overriding indicates subclass and the parent class has the same methods, parameters and return type(namely to redefine the methods in parent class).
  • 15. Abstraction • Abstraction is the process of modeling only relevant features – Hide unnecessary details which are irrelevant for current for current purpose (and/or user). • Reduces complexity and aids understanding. • Abstraction provides the freedom to defer implementation decisions by avoiding commitments to details.
  • 16. Abstraction example #include <iostream> using namespace std; class Adder{ public: // constructor Adder(int i = 0) { total = i; } // interface to outside world void addNum(int number) { total += number; } // interface to outside world int getTotal() { return total; }; private: // hidden data from outside world int total; }; int main( ) { Adder a; a.addNum(10); a.addNum(20); a.addNum(30); cout << "Total " << a.getTotal() <<endl; return 0; }
  • 17. Getting Started • Step 1: Write the Source Code: • Step 2: Build the Executable Code:
  • 18. Getting Started…. • Step 3: Run the Executable Code:
  • 19. • /* ...... */ // ... until the end of the line – These are called comments. Comments are NOT executable and are ignored by the compiler; but they provide useful explanation and documentation to your readers (and to yourself three days later). There are two kinds of comments: • Multi-line Comment: begins with /* and ends with */. It may span more than one lines (as in Lines 1-3). • End-of-line Comment: begins with // and lasts until the end of the current line (as in Lines 4, 7, 8, 9 and 10). • #include <iostream> using namespace std; – The "#include" is called a preprocessor directive. – Preprocessor directives begin with a # sign. – They are processed before compilation. – The directive "#include <iostream>" tells the preprocessor to include the "iostream" header file to support input/output operations. – The "using namespace std;" statement declares std as the default namespace used in this program. The names cout and endl, which is used in this program, belong to the std namespace. These two lines shall be present in all our programs.
  • 20. • int main() { ... body ... } – defines the so-called main() function. The main() function is the entry point of program execution. main() is required to return an int (integer). • cout << "hello, world" << endl; – "cout" refers to the standard output (or Console OUTput). The symbol << is called the stream insertion operator (or put-to operator), which is used to put the string "hello, world" to the console. "endl" denotes the END-of-Line or newline, which is put to the console to bring the cursor to the beginning of the next line. • return 0; – terminates the main() function and returns a value of 0 to the operating system. Typically, return value of 0 signals normal termination; whereas value of non-zero (usually 1) signals abnormal termination. This line is optional. C++ compiler will implicitly insert a "return 0;" to the end of the main() function.
  • 21. C++ Terminology and Syntax • Statement: A programming statement performs a piece of programming action. It must be terminated by a semicolon (;) (just like an English sentence is ended with a period), as in Lines 5, 8 and 9. • Preprocessor Directive: The #include (Line 4) is a preprocessor directive and NOT a programming statement. A preprocessor directive begins with hash sign (#). It is processed before compiling the program. A preprocessor directive is NOT terminated by a semicolon - take note of this unusual rule. • Block: A block is a group of programming statements enclosed by braces { }. This group of statements is treated as one single unit. There is one block in this program, which contains the body of the main() function. There is no need to put a semicolon after the closing brace.
  • 22. C++ Terminology and Syntax… • Comments: A multi-line comment begins with /* and ends with */, which may span more than one line. An end-of-line comment begins with // and lasts till the end of the line. Comments are NOT executable statements and are ignored by the compiler; but they provide useful explanation and documentation. Use comments liberally. • Whitespaces: Blank, tab, and newline are collectively called whitespaces. Extra whitespaces are ignored, i.e., only one whitespace is needed to separate the tokens. Nevertheless, extra white spaces and newlines could help you and your readers better understand your program. Use extra whitespaces and newlines liberally. • Case Sensitivity: C++ is case sensitive - a ROSE is NOT a Rose, and is NOT a rose.
  • 23. The Process of Writing a C++ Program • Step 1: Write the source codes (.cpp) and header files (.h). • Step 2: Pre-process the source codes according to the preprocessor directives. Preprocessor directives begin with a hash sign (#), e.g., #include and #define. They indicate that certain manipulations (such as including another file or replacement of symbols) are to be performed BEFORE compilation. • Step 3: Compile the pre-processed source codes into object codes (.obj, .o). • Step 4: Link the compiled object codes with other object codes and the library object codes (.lib, .a) to produce the executable code (.exe). • Step 5: Load the executable code into computer memory. • Step 6: Run the executable code, with the input to produce the desried output.
  • 25. Pointers • A pointer is a variable whose value is the address of another variable. • The general form of a pointer variable declaration is: type *var-name; • Here, type is the pointer's base type; it must be a valid C++ type and var-name is the name of the pointer variable. • int *ip; // pointer to an integer • double *dp; // pointer to a double • float *fp; // pointer to a float • char *ch // pointer to character Reading Pointers in C++: 1. const char * ptr :- ptr is pointer to character constant. 2. char const * ptr :- ptr is pointer to constant character. Both 1 and 2 is same. 3. char *const ptr :- ptr is constant pointer to character. 4. const char * const ptr :- ptr is constant pointer to constant character.
  • 26. Pointers in C++… Output: Value of var variable: 20 Address stored in ip variable: 0xbfc601ac Value of *ip variable: 20
  • 27. C++ References • A reference variable is an alias, that is, another name for an already existing variable. Once a reference is initialized with a variable, either the variable name or the reference name may be used to refer to the variable. • Creating References in C++: – Think of a variable name as a label attached to the variable's location in memory. You can then think of a reference as a second label attached to that memory location. Therefore, you can access the contents of the variable through either the original variable name or the reference. For example, suppose we have the following example: • int i = 17; – We can declare reference variables for i as follows. • int& r = i;
  • 28. C++ References… Output: Value of i : 5 Value of i reference : 5 Value of d : 11.7 Value of d reference : 11.7
  • 29. C++ References vs Pointers: • References are often confused with pointers but three major differences between references and pointers are: (Program) – You cannot have NULL references. You must always be able to assume that a reference is connected to a legitimate piece of storage. – Once a reference is initialized to an object, it cannot be changed to refer to another object. Pointers can be pointed to another object at any time. – A reference must be initialized when it is created. Pointers can be initialized at any time.
  • 30. Classes example: • A class is used to specify the form of an object and it combines data representation and methods for manipulating that data into one neat package. The data and functions within a class are called members of the class. • C++ class definitions: class Box { public: double length; // Length of a box double breadth; // Breadth of a box double height; // Height of a box }; • Define C++ Objects Box Box1; // Declare Box1 of type Box Box Box2; // Declare Box2 of type Box
  • 31. Classes with Constructor • A class constructor is a special member function of a class that is executed whenever we create new objects of that class.
  • 32. Constructor.. Output: Object is being created Length of line : 6
  • 33. Parameterized Constructor Output: Object is being created, length = 10 Length of line : 10 Length of line : 6