SlideShare uma empresa Scribd logo
1 de 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]

Mais conteúdo relacionado

Mais procurados

Mais procurados (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’
 

Destaque

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
 

Destaque (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)
 

Semelhante a 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
 

Semelhante a 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
 

Mais de Vidyacenter

Mais de 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
 

Último

BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLBAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLkapoorjyoti4444
 
Organizational Transformation Lead with Culture
Organizational Transformation Lead with CultureOrganizational Transformation Lead with Culture
Organizational Transformation Lead with CultureSeta Wicaksana
 
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesMysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesDipal Arora
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdfRenandantas16
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangaloreamitlee9823
 
John Halpern sued for sexual assault.pdf
John Halpern sued for sexual assault.pdfJohn Halpern sued for sexual assault.pdf
John Halpern sued for sexual assault.pdfAmzadHosen3
 
Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1kcpayne
 
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756dollysharma2066
 
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
 
It will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayIt will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayNZSG
 
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...daisycvs
 
Falcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to ProsperityFalcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to Prosperityhemanthkumar470700
 
Business Model Canvas (BMC)- A new venture concept
Business Model Canvas (BMC)-  A new venture conceptBusiness Model Canvas (BMC)-  A new venture concept
Business Model Canvas (BMC)- A new venture conceptP&CO
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityEric T. Tung
 
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
 
Famous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st CenturyFamous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st Centuryrwgiffor
 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentationuneakwhite
 

Último (20)

VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
 
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLBAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
 
Organizational Transformation Lead with Culture
Organizational Transformation Lead with CultureOrganizational Transformation Lead with Culture
Organizational Transformation Lead with Culture
 
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesMysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
 
Falcon Invoice Discounting platform in india
Falcon Invoice Discounting platform in indiaFalcon Invoice Discounting platform in india
Falcon Invoice Discounting platform in india
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
John Halpern sued for sexual assault.pdf
John Halpern sued for sexual assault.pdfJohn Halpern sued for sexual assault.pdf
John Halpern sued for sexual assault.pdf
 
Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1
 
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
 
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...
 
It will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayIt will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 May
 
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
 
Falcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to ProsperityFalcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to Prosperity
 
Business Model Canvas (BMC)- A new venture concept
Business Model Canvas (BMC)-  A new venture conceptBusiness Model Canvas (BMC)-  A new venture concept
Business Model Canvas (BMC)- A new venture concept
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League City
 
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabiunwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
 
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
 
Famous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st CenturyFamous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st Century
 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentation
 

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.