SlideShare a Scribd company logo
1 of 27
The C++ Language
www.myassignmenthelp.net
Overview of ‘C++’
• Bjarne Stroupstrup, the language’s creator
• C++ was designed to provide Simula’s facilities for program organization
together with C’s efficiency and flexibility for systems programming.
• Modern C and C++ are siblings
www.myassignmenthelp.net
Outline
• C++ basic features
– Programming paradigm and statement syntax
• Class definitions
– Data members, methods, constructor, destructor
– Pointers, arrays, and strings
– Parameter passing in functions
– Templates
– Friend
– Operator overloading
• I/O streams
– An example on file copy
• Makefile
C++ Features
• Classes
• User-defined types
• Operator overloading
• Attach different meaning to expressions such as a + b
• References
• Pass-by-reference function arguments
• Virtual Functions
• Dispatched depending on type at run time
• Templates
• Macro-like polymorphism for containers (e.g., arrays)
• Exceptions
www.myassignmenthelp.net
Compiling and Linking
• A C++ program consists of one or more source files.
• Source files contain function and class declarations and definitions.
– Files that contain only declarations are incorporated into the source files that
need them when they are compiled.
• Thus they are called include files.
– Files that contain definitions are translated by the compiler into an intermediate
form called object files.
– One or more object files are combined with to form the executable file by the
linker.
www.myassignmenthelp.net
A Simple C++ Program
#include <cstdlib>
#include <iostream>
using namespace std;
int main ( ) {
intx, y;
cout << “Please enter two numbers:”;
cin >> x >> y;
int sum = x + y;
cout << “Their sum is “ << sum << endl;
return EXIT_SUCCESS;
}
www.myassignmenthelp.net
The #include Directive
• The first two lines:
#include <iostream>
#include <cstdlib>
incorporate the declarations of the iostream and cstdlib libraries into the
source code.
• If your program is going to use a member of the standard library, the
appropriate header file must be included at the beginning of the source
code file.
www.myassignmenthelp.net
The using Statement
• The line
using namespace std;
tells the compiler to make all names in the predefined namespace std
available.
• The C++ standard library is defined within this namespace.
• Incorporating the statement
using namespace std;
is an easy way to get access to the standard library.
– But, it can lead to complications in larger programs.
• This is done with individual using declarations.
using std::cin;
using std::cout;
using std::string;
using std::getline;
www.myassignmenthelp.net
Compiling and Executing
• The command to compile is dependent upon the compiler and operating
system.
• For the gcc compiler (popular on Linux) the command would be:
– g++ -o HelloWorld HelloWorld.cpp
• For the Microsoft compiler the command would be:
– cl /EHsc HelloWorld.cpp
• To execute the program you would then issue the command
– HelloWorld
www.myassignmenthelp.net
C++ Data Type
www.myassignmenthelp.net
• Basic Java types such as int, double, char have C++ counterparts of the
same name, but there are a few differences:
• Boolean is bool in C++. In C++, 0 means false and anything else means
true.
• C++ has a string class (use string library) and character arrays (but they
behave differently).
Constants
www.myassignmenthelp.net
• Numeric Constants:
• 1234 is an int
• 1234U or 1234u is an unsigned int
• 1234L or 1234l is a long
• 1234UL or 1234ul is an unsigned long
• 1.234 is a double
• 1.234F or 1.234f is a float
• 1.234L or 1.234l is a long double.
• Character Constants:
• The form 'c' is a character constant.
• The form 'xhh' is a character constant, where hh is a hexadecimal digit, and hh is between 00
and 7F.
• The form 'x' where x is one of the following is a character constant.
• String Constants:
• The form "sequence of characters“ where sequence of characters does not include ‘"’ is called a
string constant.
• Note escape sequences may appear in the sequence of characters.
• String constants are stored in the computer as arrays of characters followed by a '0'.
Operators
• Bitwise Operators
• ~ (complement)
• & (bitwise and)
• ^ (bitwise exclusive or)
• | (bitwise or)
• << (shift left)
• >> (shift right)
• Assignment Operators
• +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=
• Other Operators
• :: (scope resolution)
• ?: (conditional expression)
• stream << var
• stream >> exp
www.myassignmenthelp.net
Increment and Decrement
• Prefix:
– ++x
• x is replaced by x+1, and the value is x+1
– --x
• x is replaced by x-1, and the value is x-1
• Postfix:
– x++
• x is replaced by x+1, but the value is x
– x--
• x is replaced by x-1, but the value is x
www.myassignmenthelp.net
Object-Oriented Concept (C++)
www.myassignmenthelp.net
• Objects of the program interact by sending messages to each other
Basic C++
www.myassignmenthelp.net
• Inherit all C syntax
– Primitive data types
• Supported data types: int, long, short, float, double, char,
bool, and enum
• The size of data types is platform-dependent
– Basic expression syntax
• Defining the usual arithmetic and logical operations such as
+, -, /, %, *, &&, !, and ||
• Defining bit-wise operations, such as &, |, and ~
– Basic statement syntax
• If-else, for, while, and do-while
Basic C++ (cont)
• Add a new comment mark
– // For 1 line comment
– /*… */ for a group of line comment
• New data type
– Reference data type “&”. Much likes pointer
int ix; /* ix is "real" variable */
int & rx = ix; /* rx is "alias" for ix */
ix = 1; /* also rx == 1 */
rx = 2; /* also ix == 2 */
• const support for constant declaration, just likes C
www.myassignmenthelp.net
Class Definitions
www.myassignmenthelp.net
• A C++ class consists of data members and methods (member functions).
class IntCell
{
public:
explicit IntCell( int initialValue = 0 )
: storedValue( initialValue ) {}
int read( ) const
{ return storedValue;}
void write( int x )
{ storedValue = x; }
private:
int storedValue;
}
Avoid implicit type conversion
Initializer list: used to initialize the data
members directly.
Member functions
Indicates that the member’s invocation does
not change any of the data members.
Data member(s)
Information Hiding in C++
• Two labels: public and private
– Determine visibility of class members
– A member that is public may be accessed by any method in any class
– A member that is private may only be accessed by methods in its class
• Information hiding
– Data members are declared private, thus restricting access to internal
details of the class
– Methods intended for general use are made public
www.myassignmenthelp.net
Constructors
• A constructor is a special method that describes how an
instance of the class (called object) is constructed
• Whenever an instance of the class is created, its constructor is
called.
• C++ provides a default constructor for each class, which is a
constructor with no parameters. But, one can define multiple
constructors for the same class, and may even redefine the
default constructor
www.myassignmenthelp.net
Destructor
• A destructor is called when an object is deleted either
implicitly, or explicitly (using the delete operation)
– The destructor is called whenever an object goes out of scope or is
subjected to a delete.
– Typically, the destructor is used to free up any resources that were
allocated during the use of the object
• C++ provides a default destructor for each class
– The default simply applies the destructor on each data member. But
we can redefine the destructor of a class. A C++ class can have only
one destructor.
– One can redefine the destructor of a class.
• A C++ class can have only one destructor
www.myassignmenthelp.net
Constructor and Destructor
class Point {
private :
int _x, _y;
public:
Point() {
_x = _y = 0;
}
Point(const int x, const int y);
Point(const Point &from);
~Point() {void}
void setX(const int val);
void setY(const int val);
int getX() { return _x; }
int getY() { return _y; }
};
www.myassignmenthelp.net
Constructor and Destructor
Point::Point(const int x, const int y) : _x(x), _y(y) {
}
Point::Point(const Point &from) {
_x = from._x;
_y = from._y;
}
Point::~Point(void) {
/* nothing to do */
}
www.myassignmenthelp.net
C++ Operator Overloading
class Complex {
...
public:
...
Complex operator +(const Complex &op) {
double real = _real + op._real,
imag = _imag + op._imag;
return(Complex(real, imag));
}
...
};
In this case, we have made operator + a member of class
Complex. An expression of the form
c = a + b;
is translated into a method call
c = a.operator +(a, b);
www.myassignmenthelp.net
Operator Overloading
• The overloaded operator may not be a member of a class: It can rather
defined outside the class as a normal overloaded function. For
example, we could define operator + in this way:
class Complex {
...
public:
...
double real() { return _real; }
double imag() { return _imag; }
// No need to define operator here!
};
Complex operator +(Complex &op1, Complex &op2)
{
double real = op1.real() + op2.real(),
imag = op1.imag() + op2.imag();
return(Complex(real, imag));
}
www.myassignmenthelp.net
Friend
• We can define functions or classes to be friends of a class
to allow them direct access to its private data members
class Complex {
...
public:
...
friend Complex operator +(
const Complex &,
const Complex &
);
};
Complex operator +(const Complex &op1, const Complex &op2) {
double real = op1._real + op2._real,
imag = op1._imag + op2._imag;
return(Complex(real, imag));
}
www.myassignmenthelp.net
Standard Input/Output Streams
• Stream is a sequence of characters
• Working with cin and cout
• Streams convert internal representations to character streams
• >> input operator (extractor)
• << output operator (inserter)
www.myassignmenthelp.net
Thank You
www.myassignmenthelp.net

More Related Content

What's hot

C++ Overview
C++ OverviewC++ Overview
C++ Overviewkelleyc3
 
Overview of c++ language
Overview of c++ language   Overview of c++ language
Overview of c++ language samt7
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointJavaTpoint.Com
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language Mohamed Loey
 
Keywords, identifiers ,datatypes in C++
Keywords, identifiers ,datatypes in C++Keywords, identifiers ,datatypes in C++
Keywords, identifiers ,datatypes in C++Ankur Pandey
 
Operator overloading and type conversion in cpp
Operator overloading and type conversion in cppOperator overloading and type conversion in cpp
Operator overloading and type conversion in cpprajshreemuthiah
 
C++ language basic
C++ language basicC++ language basic
C++ language basicWaqar Younis
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java ProgrammingRavi Kant Sahu
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming ConceptsJussi Pohjolainen
 

What's hot (20)

Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
C++ Overview
C++ OverviewC++ Overview
C++ Overview
 
Overview of c++ language
Overview of c++ language   Overview of c++ language
Overview of c++ language
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
C++
C++C++
C++
 
Keywords, identifiers ,datatypes in C++
Keywords, identifiers ,datatypes in C++Keywords, identifiers ,datatypes in C++
Keywords, identifiers ,datatypes in C++
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
 
C if else
C if elseC if else
C if else
 
Operator overloading and type conversion in cpp
Operator overloading and type conversion in cppOperator overloading and type conversion in cpp
Operator overloading and type conversion in cpp
 
C++ language basic
C++ language basicC++ language basic
C++ language basic
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
C# basics
 C# basics C# basics
C# basics
 
C program
C programC program
C program
 
C++ programming function
C++ programming functionC++ programming function
C++ programming function
 
C++ book
C++ bookC++ book
C++ book
 
C++ How to program
C++ How to programC++ How to program
C++ How to program
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming Concepts
 

Viewers also liked

Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language CourseVivek chan
 
C++ Programming : Learn OOP in C++
C++ Programming : Learn OOP in C++C++ Programming : Learn OOP in C++
C++ Programming : Learn OOP in C++richards9696
 
Overview- Skillwise Consulting
Overview- Skillwise Consulting Overview- Skillwise Consulting
Overview- Skillwise Consulting Skillwise Group
 
Support for Object-Oriented Programming (OOP) in C++
Support for Object-Oriented Programming (OOP) in C++Support for Object-Oriented Programming (OOP) in C++
Support for Object-Oriented Programming (OOP) in C++Ameen Sha'arawi
 
Innovative web design in delhi
Innovative web design in delhiInnovative web design in delhi
Innovative web design in delhiJatin Arora
 
#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop InheritanceHadziq Fabroyir
 
C++ OOP Implementation
C++ OOP ImplementationC++ OOP Implementation
C++ OOP ImplementationFridz Felisco
 
Control structures in c++
Control structures in c++Control structures in c++
Control structures in c++Nitin Jawla
 
Pipe & its wall thickness calculation
Pipe & its wall thickness calculationPipe & its wall thickness calculation
Pipe & its wall thickness calculationsandeepkrish2712
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++Swarup Kumar Boro
 
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 eteachingeteaching
 
CBSE Class XI Programming in C++
CBSE Class XI Programming in C++CBSE Class XI Programming in C++
CBSE Class XI Programming in C++Pranav Ghildiyal
 
Multidimensional arrays in C++
Multidimensional arrays in C++Multidimensional arrays in C++
Multidimensional arrays in C++Ilio Catallo
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overviewTAlha MAlik
 
Overview of c++
Overview of c++Overview of c++
Overview of c++geeeeeet
 

Viewers also liked (20)

Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language Course
 
Intro to C++ - language
Intro to C++ - languageIntro to C++ - language
Intro to C++ - language
 
C++ Programming : Learn OOP in C++
C++ Programming : Learn OOP in C++C++ Programming : Learn OOP in C++
C++ Programming : Learn OOP in C++
 
Oop l2
Oop l2Oop l2
Oop l2
 
Overview- Skillwise Consulting
Overview- Skillwise Consulting Overview- Skillwise Consulting
Overview- Skillwise Consulting
 
Support for Object-Oriented Programming (OOP) in C++
Support for Object-Oriented Programming (OOP) in C++Support for Object-Oriented Programming (OOP) in C++
Support for Object-Oriented Programming (OOP) in C++
 
Innovative web design in delhi
Innovative web design in delhiInnovative web design in delhi
Innovative web design in delhi
 
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
 
#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance
 
C++ OOP Implementation
C++ OOP ImplementationC++ OOP Implementation
C++ OOP Implementation
 
Control structures in c++
Control structures in c++Control structures in c++
Control structures in c++
 
Pipe & its wall thickness calculation
Pipe & its wall thickness calculationPipe & its wall thickness calculation
Pipe & its wall thickness calculation
 
Valve selections
Valve selectionsValve selections
Valve selections
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
 
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
 
CBSE Class XI Programming in C++
CBSE Class XI Programming in C++CBSE Class XI Programming in C++
CBSE Class XI Programming in C++
 
Multidimensional arrays in C++
Multidimensional arrays in C++Multidimensional arrays in C++
Multidimensional arrays in C++
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
 
Overview of c++
Overview of c++Overview of c++
Overview of c++
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 

Similar to C++ Language Features and Concepts (20)

C++ language
C++ languageC++ language
C++ language
 
c++ UNIT II.pptx
c++ UNIT II.pptxc++ UNIT II.pptx
c++ UNIT II.pptx
 
c++ Unit I.pptx
c++ Unit I.pptxc++ Unit I.pptx
c++ Unit I.pptx
 
C programming language tutorial
C programming language tutorialC programming language tutorial
C programming language tutorial
 
Cpp-c++.pptx
Cpp-c++.pptxCpp-c++.pptx
Cpp-c++.pptx
 
Net framework
Net frameworkNet framework
Net framework
 
C
CC
C
 
Programming Language
Programming  LanguageProgramming  Language
Programming Language
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
C_plus_plus
C_plus_plusC_plus_plus
C_plus_plus
 
UsingCPP_for_Artist.ppt
UsingCPP_for_Artist.pptUsingCPP_for_Artist.ppt
UsingCPP_for_Artist.ppt
 
Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
 
cs8251 unit 1 ppt
cs8251 unit 1 pptcs8251 unit 1 ppt
cs8251 unit 1 ppt
 
Abhishek lingineni
Abhishek lingineniAbhishek lingineni
Abhishek lingineni
 
CPlusPus
CPlusPusCPlusPus
CPlusPus
 
C language
C languageC language
C language
 
C++ programming intro
C++ programming introC++ programming intro
C++ programming intro
 

More from Steve Johnson

How to create effective powerpoint presentation
How to create effective powerpoint presentationHow to create effective powerpoint presentation
How to create effective powerpoint presentationSteve Johnson
 
How to approach your first assignment
How to approach  your first  assignmentHow to approach  your first  assignment
How to approach your first assignmentSteve Johnson
 
A quick guide on accounting process of bookkeeping
A quick guide on accounting process of bookkeepingA quick guide on accounting process of bookkeeping
A quick guide on accounting process of bookkeepingSteve Johnson
 
Online education vs classroom teaching
Online education vs classroom teachingOnline education vs classroom teaching
Online education vs classroom teachingSteve Johnson
 
Darwin’s theory of evolution
Darwin’s theory of evolutionDarwin’s theory of evolution
Darwin’s theory of evolutionSteve Johnson
 
Learn Vba excel 2007
Learn Vba excel 2007Learn Vba excel 2007
Learn Vba excel 2007Steve Johnson
 
Learn Data Structures With Myassignmenthelp.Net
Learn Data Structures With Myassignmenthelp.NetLearn Data Structures With Myassignmenthelp.Net
Learn Data Structures With Myassignmenthelp.NetSteve Johnson
 
What is a Scientific Presentation ?
What is a Scientific Presentation ?What is a Scientific Presentation ?
What is a Scientific Presentation ?Steve Johnson
 
Difference Between Sql - MySql and Oracle
Difference Between Sql - MySql and OracleDifference Between Sql - MySql and Oracle
Difference Between Sql - MySql and OracleSteve Johnson
 
What is Psychology ?
What is Psychology ?What is Psychology ?
What is Psychology ?Steve Johnson
 

More from Steve Johnson (14)

Science of boredom
Science of boredomScience of boredom
Science of boredom
 
How to create effective powerpoint presentation
How to create effective powerpoint presentationHow to create effective powerpoint presentation
How to create effective powerpoint presentation
 
How to approach your first assignment
How to approach  your first  assignmentHow to approach  your first  assignment
How to approach your first assignment
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
A quick guide on accounting process of bookkeeping
A quick guide on accounting process of bookkeepingA quick guide on accounting process of bookkeeping
A quick guide on accounting process of bookkeeping
 
Online education vs classroom teaching
Online education vs classroom teachingOnline education vs classroom teaching
Online education vs classroom teaching
 
Darwin’s theory of evolution
Darwin’s theory of evolutionDarwin’s theory of evolution
Darwin’s theory of evolution
 
Learn Vba excel 2007
Learn Vba excel 2007Learn Vba excel 2007
Learn Vba excel 2007
 
Learn Data Structures With Myassignmenthelp.Net
Learn Data Structures With Myassignmenthelp.NetLearn Data Structures With Myassignmenthelp.Net
Learn Data Structures With Myassignmenthelp.Net
 
What is a Scientific Presentation ?
What is a Scientific Presentation ?What is a Scientific Presentation ?
What is a Scientific Presentation ?
 
Difference Between Sql - MySql and Oracle
Difference Between Sql - MySql and OracleDifference Between Sql - MySql and Oracle
Difference Between Sql - MySql and Oracle
 
What is Psychology ?
What is Psychology ?What is Psychology ?
What is Psychology ?
 
Biology Assignments
Biology AssignmentsBiology Assignments
Biology Assignments
 
Biology Assignments
Biology AssignmentsBiology Assignments
Biology Assignments
 

Recently uploaded

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

C++ Language Features and Concepts

  • 2. Overview of ‘C++’ • Bjarne Stroupstrup, the language’s creator • C++ was designed to provide Simula’s facilities for program organization together with C’s efficiency and flexibility for systems programming. • Modern C and C++ are siblings www.myassignmenthelp.net
  • 3. Outline • C++ basic features – Programming paradigm and statement syntax • Class definitions – Data members, methods, constructor, destructor – Pointers, arrays, and strings – Parameter passing in functions – Templates – Friend – Operator overloading • I/O streams – An example on file copy • Makefile
  • 4. C++ Features • Classes • User-defined types • Operator overloading • Attach different meaning to expressions such as a + b • References • Pass-by-reference function arguments • Virtual Functions • Dispatched depending on type at run time • Templates • Macro-like polymorphism for containers (e.g., arrays) • Exceptions www.myassignmenthelp.net
  • 5. Compiling and Linking • A C++ program consists of one or more source files. • Source files contain function and class declarations and definitions. – Files that contain only declarations are incorporated into the source files that need them when they are compiled. • Thus they are called include files. – Files that contain definitions are translated by the compiler into an intermediate form called object files. – One or more object files are combined with to form the executable file by the linker. www.myassignmenthelp.net
  • 6. A Simple C++ Program #include <cstdlib> #include <iostream> using namespace std; int main ( ) { intx, y; cout << “Please enter two numbers:”; cin >> x >> y; int sum = x + y; cout << “Their sum is “ << sum << endl; return EXIT_SUCCESS; } www.myassignmenthelp.net
  • 7. The #include Directive • The first two lines: #include <iostream> #include <cstdlib> incorporate the declarations of the iostream and cstdlib libraries into the source code. • If your program is going to use a member of the standard library, the appropriate header file must be included at the beginning of the source code file. www.myassignmenthelp.net
  • 8. The using Statement • The line using namespace std; tells the compiler to make all names in the predefined namespace std available. • The C++ standard library is defined within this namespace. • Incorporating the statement using namespace std; is an easy way to get access to the standard library. – But, it can lead to complications in larger programs. • This is done with individual using declarations. using std::cin; using std::cout; using std::string; using std::getline; www.myassignmenthelp.net
  • 9. Compiling and Executing • The command to compile is dependent upon the compiler and operating system. • For the gcc compiler (popular on Linux) the command would be: – g++ -o HelloWorld HelloWorld.cpp • For the Microsoft compiler the command would be: – cl /EHsc HelloWorld.cpp • To execute the program you would then issue the command – HelloWorld www.myassignmenthelp.net
  • 10. C++ Data Type www.myassignmenthelp.net • Basic Java types such as int, double, char have C++ counterparts of the same name, but there are a few differences: • Boolean is bool in C++. In C++, 0 means false and anything else means true. • C++ has a string class (use string library) and character arrays (but they behave differently).
  • 11. Constants www.myassignmenthelp.net • Numeric Constants: • 1234 is an int • 1234U or 1234u is an unsigned int • 1234L or 1234l is a long • 1234UL or 1234ul is an unsigned long • 1.234 is a double • 1.234F or 1.234f is a float • 1.234L or 1.234l is a long double. • Character Constants: • The form 'c' is a character constant. • The form 'xhh' is a character constant, where hh is a hexadecimal digit, and hh is between 00 and 7F. • The form 'x' where x is one of the following is a character constant. • String Constants: • The form "sequence of characters“ where sequence of characters does not include ‘"’ is called a string constant. • Note escape sequences may appear in the sequence of characters. • String constants are stored in the computer as arrays of characters followed by a '0'.
  • 12. Operators • Bitwise Operators • ~ (complement) • & (bitwise and) • ^ (bitwise exclusive or) • | (bitwise or) • << (shift left) • >> (shift right) • Assignment Operators • +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>= • Other Operators • :: (scope resolution) • ?: (conditional expression) • stream << var • stream >> exp www.myassignmenthelp.net
  • 13. Increment and Decrement • Prefix: – ++x • x is replaced by x+1, and the value is x+1 – --x • x is replaced by x-1, and the value is x-1 • Postfix: – x++ • x is replaced by x+1, but the value is x – x-- • x is replaced by x-1, but the value is x www.myassignmenthelp.net
  • 14. Object-Oriented Concept (C++) www.myassignmenthelp.net • Objects of the program interact by sending messages to each other
  • 15. Basic C++ www.myassignmenthelp.net • Inherit all C syntax – Primitive data types • Supported data types: int, long, short, float, double, char, bool, and enum • The size of data types is platform-dependent – Basic expression syntax • Defining the usual arithmetic and logical operations such as +, -, /, %, *, &&, !, and || • Defining bit-wise operations, such as &, |, and ~ – Basic statement syntax • If-else, for, while, and do-while
  • 16. Basic C++ (cont) • Add a new comment mark – // For 1 line comment – /*… */ for a group of line comment • New data type – Reference data type “&”. Much likes pointer int ix; /* ix is "real" variable */ int & rx = ix; /* rx is "alias" for ix */ ix = 1; /* also rx == 1 */ rx = 2; /* also ix == 2 */ • const support for constant declaration, just likes C www.myassignmenthelp.net
  • 17. Class Definitions www.myassignmenthelp.net • A C++ class consists of data members and methods (member functions). class IntCell { public: explicit IntCell( int initialValue = 0 ) : storedValue( initialValue ) {} int read( ) const { return storedValue;} void write( int x ) { storedValue = x; } private: int storedValue; } Avoid implicit type conversion Initializer list: used to initialize the data members directly. Member functions Indicates that the member’s invocation does not change any of the data members. Data member(s)
  • 18. Information Hiding in C++ • Two labels: public and private – Determine visibility of class members – A member that is public may be accessed by any method in any class – A member that is private may only be accessed by methods in its class • Information hiding – Data members are declared private, thus restricting access to internal details of the class – Methods intended for general use are made public www.myassignmenthelp.net
  • 19. Constructors • A constructor is a special method that describes how an instance of the class (called object) is constructed • Whenever an instance of the class is created, its constructor is called. • C++ provides a default constructor for each class, which is a constructor with no parameters. But, one can define multiple constructors for the same class, and may even redefine the default constructor www.myassignmenthelp.net
  • 20. Destructor • A destructor is called when an object is deleted either implicitly, or explicitly (using the delete operation) – The destructor is called whenever an object goes out of scope or is subjected to a delete. – Typically, the destructor is used to free up any resources that were allocated during the use of the object • C++ provides a default destructor for each class – The default simply applies the destructor on each data member. But we can redefine the destructor of a class. A C++ class can have only one destructor. – One can redefine the destructor of a class. • A C++ class can have only one destructor www.myassignmenthelp.net
  • 21. Constructor and Destructor class Point { private : int _x, _y; public: Point() { _x = _y = 0; } Point(const int x, const int y); Point(const Point &from); ~Point() {void} void setX(const int val); void setY(const int val); int getX() { return _x; } int getY() { return _y; } }; www.myassignmenthelp.net
  • 22. Constructor and Destructor Point::Point(const int x, const int y) : _x(x), _y(y) { } Point::Point(const Point &from) { _x = from._x; _y = from._y; } Point::~Point(void) { /* nothing to do */ } www.myassignmenthelp.net
  • 23. C++ Operator Overloading class Complex { ... public: ... Complex operator +(const Complex &op) { double real = _real + op._real, imag = _imag + op._imag; return(Complex(real, imag)); } ... }; In this case, we have made operator + a member of class Complex. An expression of the form c = a + b; is translated into a method call c = a.operator +(a, b); www.myassignmenthelp.net
  • 24. Operator Overloading • The overloaded operator may not be a member of a class: It can rather defined outside the class as a normal overloaded function. For example, we could define operator + in this way: class Complex { ... public: ... double real() { return _real; } double imag() { return _imag; } // No need to define operator here! }; Complex operator +(Complex &op1, Complex &op2) { double real = op1.real() + op2.real(), imag = op1.imag() + op2.imag(); return(Complex(real, imag)); } www.myassignmenthelp.net
  • 25. Friend • We can define functions or classes to be friends of a class to allow them direct access to its private data members class Complex { ... public: ... friend Complex operator +( const Complex &, const Complex & ); }; Complex operator +(const Complex &op1, const Complex &op2) { double real = op1._real + op2._real, imag = op1._imag + op2._imag; return(Complex(real, imag)); } www.myassignmenthelp.net
  • 26. Standard Input/Output Streams • Stream is a sequence of characters • Working with cin and cout • Streams convert internal representations to character streams • >> input operator (extractor) • << output operator (inserter) www.myassignmenthelp.net