SlideShare a Scribd company logo
1 of 58
The C++ Language
The C++ Language ,[object Object],C++ was designed to provide Simula’s facilities for program organization together with C’s efficiency and flexibility for systems programming.
C++ Features ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example: A stack in C typedef struct { char s[SIZE]; int  sp; } Stack; stack *create() { Stack *s; s = (Stack *)malloc(sizeof(Stack)); s->sp = 0; return s; } Creator function ensures stack is created properly. Does not help for stack that is automatic variable. Programmer could inadvertently create uninitialized stack.                                                                                                               
Example: A stack in C char pop(Stack *s) { if (sp = 0) error(“Underflow”); return s->s[--sp]; } void push(Stack *s, char v) { if (sp == SIZE) error(“Overflow”); s->s[sp++] = v; } Not clear these are the only stack-related functions. Another part of program can modify any stack any way it wants to, destroying invariants. Temptation to inline these computations, not use functions.
C++ Solution: Class class Stack { char s[SIZE]; int sp; public: Stack() { sp = 0; } void push(char v) { if (sp == SIZE) error(“overflow”); s[sp++] = v; } char pop() { if (sp == 0) error(“underflow”); return s[--sp]; } }; Definition of both representation and operations Constructor: initializes Public: visible outside the class Member functions see object fields like local variables
C++ Stack Class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
C++ Stack Class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Class Implementation ,[object Object],C++ class Stack { char s[SIZE]; int sp; public: Stack() void push(char); char pop(); }; Equivalent C implementation struct Stack { char s[SIZE]; int sp; }; void st_Stack(Stack*); void st_push(Stack*, char); char st_pop(Stack*);
Operator Overloading ,[object Object],[object Object],[object Object],[object Object],Creating objects of the user-defined type Want + to mean something different in this context Promote 2.3 to a complex number here
Example: Complex number type ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Pass-by-reference reduces copying  Operator overloading defines arithmetic operators for the complex type
References ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Complex Number Type ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Complex Number Class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Function Overloading ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Const ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Templates ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Template Stack Class template <class T> class Stack { T s[SIZE]; int sp; public: Stack() { sp = 0; } void push(T v) { if (sp == SIZE) error(“overflow”); s[sp++] = v; } T pop() { if (sp == 0) error(“underflow”); return s[--sp]; } }; T is a type argument Used like a type within the body
Using a template Stack<char> cs; // Instantiates the specialized code cs.push(‘a’); char c = cs.pop(); Stack<double *> dps; double d; dps.push(&d);
Display-list example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Inheritance ,[object Object],[object Object],[object Object],[object Object],[object Object]
Inheritance class Shape { double x, y; // Base coordinates of shape public: void translate(double dx, double dy) { x += dx; y += dy; } }; class Line : public Shape { }; Line l; l.translate(1,3); // Invoke Shape::translate() Line inherits both the representation and member functions of the Shape class
Implementing Inheritance ,[object Object],[object Object],C++ class Shape { double x, y; }; class Box : Shape { double h, w; }; Equivalent C implementation struct Shape { double x, y }; struct Box { double x, y; double h, w; };
Virtual Functions class Shape { virtual void draw(); }; class Line : public Shape { void draw(); }; class Arc : public Shape { void draw(); }; Shape *dl[10]; dl[0] = new Line; dl[1] = new Arc; dl[0]->draw(); // invoke Line::draw() dl[1]->draw(); // invoke Arc::draw() draw() is a virtual function invoked based on the actual type of the object, not the type of the pointer New classes can be added without having to change “draw everything” code
Implementing Virtual Functions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],a b vptr &Virt::foo &Virt::bar Object of type Virt Virtual table for class Virt C++   void f(Virt *v) { v->bar(); } Equivalent C implementation  void f(Virt *v) { (*(v->vptr.bar))(v); }
Cfront ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Default arguments ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Declarations may appear anywhere ,[object Object],void f(int i, const char *p) { if (i<=0) error(); const int len = strlen(p); char c = 0; for (int j = i ; j<len ; j++) c += p[j]; }
Multiple Inheritance ,[object Object],[object Object],[object Object],[object Object],[object Object]
Multiple Inheritance Ambiguities ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Multiple Inheritance Ambiguities ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Duplicate Base Classes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Duplicate Base Classes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Implementing Multiple Inheritance ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],B A C B *b C *c or A *a In-memory representation of a C
Implementation Using VT Offsets ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],x y vptr &C::f 0 &C::f –2 c C’s vtbl vptr z &B::g 0 B in C’s vtbl b
Implementation Using Thunks ,[object Object],[object Object],x y vptr &C::f &C::f_in_B c C’s vtbl vptr z &B::g B in C’s vtbl b void C::f_in_B(void* this) { return C::f(this – 2); }
Namespaces ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],                                                                                                                                   
Namespaces ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Namespaces ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Namespaces ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Namespaces ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Exceptions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Standard Template Library ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
C++ IO Facilities ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
C++ IO Facilities ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
C++ string class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
C++ STL Containers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Iterators ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],… v.begin() v.end()
Other Containers Insert/Delete from front mid. end random access vector O(n) O(n) O(1) O(1) list O(1) O(1) O(1) O(n) deque O(1) O(n) O(1) O(n)
Associative Containers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
C++ in Embedded Systems ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
C++ Features With No Impact ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Inexpensive C++ Features ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Medium-cost Features ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
High-cost Features ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
High-cost Features ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
High-cost Features ,[object Object],[object Object],[object Object],[object Object]
Conclusion ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot (20)

CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesCS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic Services
 
C++ theory
C++ theoryC++ theory
C++ theory
 
C++ Training
C++ TrainingC++ Training
C++ Training
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
C++ book
C++ bookC++ book
C++ book
 
C fundamentals
C fundamentalsC fundamentals
C fundamentals
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 
Visula C# Programming Lecture 2
Visula C# Programming Lecture 2Visula C# Programming Lecture 2
Visula C# Programming Lecture 2
 
20 C programs
20 C programs20 C programs
20 C programs
 
What is c
What is cWhat is c
What is c
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
C Basics
C BasicsC Basics
C Basics
 
Overview of c++ language
Overview of c++ language   Overview of c++ language
Overview of c++ language
 
Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
 
Lex (lexical analyzer)
Lex (lexical analyzer)Lex (lexical analyzer)
Lex (lexical analyzer)
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6
 
C++11
C++11C++11
C++11
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 

Viewers also liked

C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)sachindane
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language CourseVivek chan
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS ConceptBoopathi K
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)Ritika Sharma
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic conceptsAbhinav Vatsa
 
Overview of c language
Overview of c languageOverview of c language
Overview of c languageshalini392
 
Array in c language
Array in c languageArray in c language
Array in c languagehome
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language Mohamed Loey
 
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
 
Stamford International University IT Orientation 3/2016
Stamford International University IT Orientation 3/2016Stamford International University IT Orientation 3/2016
Stamford International University IT Orientation 3/2016Mintra Ruensuk
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programmingavikdhupar
 
C language (Collected By Dushmanta)
C language  (Collected By Dushmanta)C language  (Collected By Dushmanta)
C language (Collected By Dushmanta)Dushmanta Nath
 

Viewers also liked (20)

C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
 
Data types
Data typesData types
Data types
 
OOP
OOPOOP
OOP
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language Course
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
 
Function in c
Function in cFunction in c
Function in c
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic concepts
 
Overview of c language
Overview of c languageOverview of c language
Overview of c language
 
Function in C program
Function in C programFunction in C program
Function in C program
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Array in c language
Array in c languageArray in c language
Array in c language
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming 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
 
Stamford International University IT Orientation 3/2016
Stamford International University IT Orientation 3/2016Stamford International University IT Orientation 3/2016
Stamford International University IT Orientation 3/2016
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 
C language ppt
C language pptC language ppt
C language ppt
 
C language (Collected By Dushmanta)
C language  (Collected By Dushmanta)C language  (Collected By Dushmanta)
C language (Collected By Dushmanta)
 

Similar to C++ Language

c++-language-1208539706757125-9.pdf
c++-language-1208539706757125-9.pdfc++-language-1208539706757125-9.pdf
c++-language-1208539706757125-9.pdfnisarmca
 
Chapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classChapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classDeepak Singh
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 FeaturesJan Rüegg
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Ismar Silveira
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeMicrosoft Tech Community
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeMicrosoft Tech Community
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)Chhom Karath
 
麻省理工C++公开教学课程(二)
麻省理工C++公开教学课程(二)麻省理工C++公开教学课程(二)
麻省理工C++公开教学课程(二)ProCharm
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupSyedHaroonShah4
 
from java to c
from java to cfrom java to c
from java to cVõ Hòa
 
Review constdestr
Review constdestrReview constdestr
Review constdestrrajudasraju
 
Write a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdfWrite a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdfmohdjakirfb
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of cTushar B Kute
 
OO-like C Programming: Struct Inheritance and Virtual Function
OO-like C Programming: Struct Inheritance and Virtual FunctionOO-like C Programming: Struct Inheritance and Virtual Function
OO-like C Programming: Struct Inheritance and Virtual FunctionYu-Sheng (Yosen) Chen
 

Similar to C++ Language (20)

Basics of objective c
Basics of objective cBasics of objective c
Basics of objective c
 
c++-language-1208539706757125-9.pdf
c++-language-1208539706757125-9.pdfc++-language-1208539706757125-9.pdf
c++-language-1208539706757125-9.pdf
 
C++ programs
C++ programsC++ programs
C++ programs
 
Chapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-classChapter27 polymorphism-virtual-function-abstract-class
Chapter27 polymorphism-virtual-function-abstract-class
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 
Oop Presentation
Oop PresentationOop Presentation
Oop Presentation
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ Code
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ Code
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
 
Lecture4
Lecture4Lecture4
Lecture4
 
Lecture4
Lecture4Lecture4
Lecture4
 
麻省理工C++公开教学课程(二)
麻省理工C++公开教学课程(二)麻省理工C++公开教学课程(二)
麻省理工C++公开教学课程(二)
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrup
 
from java to c
from java to cfrom java to c
from java to c
 
Review constdestr
Review constdestrReview constdestr
Review constdestr
 
Write a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdfWrite a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdf
 
Tu1
Tu1Tu1
Tu1
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
 
OO-like C Programming: Struct Inheritance and Virtual Function
OO-like C Programming: Struct Inheritance and Virtual FunctionOO-like C Programming: Struct Inheritance and Virtual Function
OO-like C Programming: Struct Inheritance and Virtual Function
 

More from Vidyacenter

More from Vidyacenter (6)

Example Projectile Motion
Example Projectile MotionExample Projectile Motion
Example Projectile Motion
 
Clanguage
ClanguageClanguage
Clanguage
 
Advance Java
Advance JavaAdvance Java
Advance Java
 
Interview Tips
Interview TipsInterview Tips
Interview Tips
 
Gre Ppt
Gre PptGre Ppt
Gre Ppt
 
Gmat Ppt
Gmat PptGmat Ppt
Gmat Ppt
 

Recently uploaded

Unlocking the Secrets of Affiliate Marketing.pdf
Unlocking the Secrets of Affiliate Marketing.pdfUnlocking the Secrets of Affiliate Marketing.pdf
Unlocking the Secrets of Affiliate Marketing.pdfOnline Income Engine
 
VIP Call Girls Gandi Maisamma ( Hyderabad ) Phone 8250192130 | ₹5k To 25k Wit...
VIP Call Girls Gandi Maisamma ( Hyderabad ) Phone 8250192130 | ₹5k To 25k Wit...VIP Call Girls Gandi Maisamma ( Hyderabad ) Phone 8250192130 | ₹5k To 25k Wit...
VIP Call Girls Gandi Maisamma ( Hyderabad ) Phone 8250192130 | ₹5k To 25k Wit...Suhani Kapoor
 
Call Girls In Panjim North Goa 9971646499 Genuine Service
Call Girls In Panjim North Goa 9971646499 Genuine ServiceCall Girls In Panjim North Goa 9971646499 Genuine Service
Call Girls In Panjim North Goa 9971646499 Genuine Serviceritikaroy0888
 
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...Any kyc Account
 
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableDipal Arora
 
Event mailer assignment progress report .pdf
Event mailer assignment progress report .pdfEvent mailer assignment progress report .pdf
Event mailer assignment progress report .pdftbatkhuu1
 
Monte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMMonte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMRavindra Nath Shukla
 
9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 Delhi
9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 Delhi9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 Delhi
9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 DelhiCall Girls in Delhi
 
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Dipal Arora
 
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLMONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLSeo
 
Best Basmati Rice Manufacturers in India
Best Basmati Rice Manufacturers in IndiaBest Basmati Rice Manufacturers in India
Best Basmati Rice Manufacturers in IndiaShree Krishna Exports
 
Call Girls in Gomti Nagar - 7388211116 - With room Service
Call Girls in Gomti Nagar - 7388211116  - With room ServiceCall Girls in Gomti Nagar - 7388211116  - With room Service
Call Girls in Gomti Nagar - 7388211116 - With room Servicediscovermytutordmt
 
Regression analysis: Simple Linear Regression Multiple Linear Regression
Regression analysis:  Simple Linear Regression Multiple Linear RegressionRegression analysis:  Simple Linear Regression Multiple Linear Regression
Regression analysis: Simple Linear Regression Multiple Linear RegressionRavindra Nath Shukla
 
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Roland Driesen
 
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...Aggregage
 
RSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataRSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataExhibitors Data
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...amitlee9823
 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsP&CO
 
M.C Lodges -- Guest House in Jhang.
M.C Lodges --  Guest House in Jhang.M.C Lodges --  Guest House in Jhang.
M.C Lodges -- Guest House in Jhang.Aaiza Hassan
 

Recently uploaded (20)

Unlocking the Secrets of Affiliate Marketing.pdf
Unlocking the Secrets of Affiliate Marketing.pdfUnlocking the Secrets of Affiliate Marketing.pdf
Unlocking the Secrets of Affiliate Marketing.pdf
 
VIP Call Girls Gandi Maisamma ( Hyderabad ) Phone 8250192130 | ₹5k To 25k Wit...
VIP Call Girls Gandi Maisamma ( Hyderabad ) Phone 8250192130 | ₹5k To 25k Wit...VIP Call Girls Gandi Maisamma ( Hyderabad ) Phone 8250192130 | ₹5k To 25k Wit...
VIP Call Girls Gandi Maisamma ( Hyderabad ) Phone 8250192130 | ₹5k To 25k Wit...
 
Call Girls In Panjim North Goa 9971646499 Genuine Service
Call Girls In Panjim North Goa 9971646499 Genuine ServiceCall Girls In Panjim North Goa 9971646499 Genuine Service
Call Girls In Panjim North Goa 9971646499 Genuine Service
 
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
 
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
 
Event mailer assignment progress report .pdf
Event mailer assignment progress report .pdfEvent mailer assignment progress report .pdf
Event mailer assignment progress report .pdf
 
Monte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMMonte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSM
 
9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 Delhi
9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 Delhi9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 Delhi
9599632723 Top Call Girls in Delhi at your Door Step Available 24x7 Delhi
 
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
 
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLMONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
 
Best Basmati Rice Manufacturers in India
Best Basmati Rice Manufacturers in IndiaBest Basmati Rice Manufacturers in India
Best Basmati Rice Manufacturers in India
 
Call Girls in Gomti Nagar - 7388211116 - With room Service
Call Girls in Gomti Nagar - 7388211116  - With room ServiceCall Girls in Gomti Nagar - 7388211116  - With room Service
Call Girls in Gomti Nagar - 7388211116 - With room Service
 
Regression analysis: Simple Linear Regression Multiple Linear Regression
Regression analysis:  Simple Linear Regression Multiple Linear RegressionRegression analysis:  Simple Linear Regression Multiple Linear Regression
Regression analysis: Simple Linear Regression Multiple Linear Regression
 
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...
 
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
 
RSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataRSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors Data
 
Forklift Operations: Safety through Cartoons
Forklift Operations: Safety through CartoonsForklift Operations: Safety through Cartoons
Forklift Operations: Safety through Cartoons
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and pains
 
M.C Lodges -- Guest House in Jhang.
M.C Lodges --  Guest House in Jhang.M.C Lodges --  Guest House in Jhang.
M.C Lodges -- Guest House in Jhang.
 

C++ Language

  • 2.
  • 3.
  • 4. Example: A stack in C typedef struct { char s[SIZE]; int sp; } Stack; stack *create() { Stack *s; s = (Stack *)malloc(sizeof(Stack)); s->sp = 0; return s; } Creator function ensures stack is created properly. Does not help for stack that is automatic variable. Programmer could inadvertently create uninitialized stack.                                                                                                              
  • 5. Example: A stack in C char pop(Stack *s) { if (sp = 0) error(“Underflow”); return s->s[--sp]; } void push(Stack *s, char v) { if (sp == SIZE) error(“Overflow”); s->s[sp++] = v; } Not clear these are the only stack-related functions. Another part of program can modify any stack any way it wants to, destroying invariants. Temptation to inline these computations, not use functions.
  • 6. C++ Solution: Class class Stack { char s[SIZE]; int sp; public: Stack() { sp = 0; } void push(char v) { if (sp == SIZE) error(“overflow”); s[sp++] = v; } char pop() { if (sp == 0) error(“underflow”); return s[--sp]; } }; Definition of both representation and operations Constructor: initializes Public: visible outside the class Member functions see object fields like local variables
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18. Template Stack Class template <class T> class Stack { T s[SIZE]; int sp; public: Stack() { sp = 0; } void push(T v) { if (sp == SIZE) error(“overflow”); s[sp++] = v; } T pop() { if (sp == 0) error(“underflow”); return s[--sp]; } }; T is a type argument Used like a type within the body
  • 19. Using a template Stack<char> cs; // Instantiates the specialized code cs.push(‘a’); char c = cs.pop(); Stack<double *> dps; double d; dps.push(&d);
  • 20.
  • 21.
  • 22. Inheritance class Shape { double x, y; // Base coordinates of shape public: void translate(double dx, double dy) { x += dx; y += dy; } }; class Line : public Shape { }; Line l; l.translate(1,3); // Invoke Shape::translate() Line inherits both the representation and member functions of the Shape class
  • 23.
  • 24. Virtual Functions class Shape { virtual void draw(); }; class Line : public Shape { void draw(); }; class Arc : public Shape { void draw(); }; Shape *dl[10]; dl[0] = new Line; dl[1] = new Arc; dl[0]->draw(); // invoke Line::draw() dl[1]->draw(); // invoke Arc::draw() draw() is a virtual function invoked based on the actual type of the object, not the type of the pointer New classes can be added without having to change “draw everything” code
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49. Other Containers Insert/Delete from front mid. end random access vector O(n) O(n) O(1) O(1) list O(1) O(1) O(1) O(n) deque O(1) O(n) O(1) O(n)
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.