SlideShare a Scribd company logo
1
Getting Started with
C++
Trenton Computer Festival
March 15, 2014
Michael P. Redlich
@mpredli
about.me/mpredli/
Sunday, March 16, 14
Who’s Mike?
• BS in CS from
• “Petrochemical Research Organization”
• Ai-Logix, Inc. (now AudioCodes)
• Amateur Computer Group of New Jersey
• Publications
• Presentations
2
Sunday, March 16, 14
Objectives (1)
• What is C++?
• Evolution of C++
• Features of C++
• Review of Object-Oriented Programming
(OOP)
3
Sunday, March 16, 14
Objectives (2)
• Getting Started with C++
• introduction to the C++ class mechanism
• how to implement C++ classes
• Live Demos (yea!)
• C++ Resources
4
Sunday, March 16, 14
What is C++?
• “...a general purpose programming language
with a bias towards systems programming that
• is a better C,
• supports data abstraction,
• supports object-oriented programming,
• supports generic programming.”
Bjarne Stroustrup Web Site, http://www.stroustrup.com/C++.html
5
Sunday, March 16, 14
Evolution of C++ (1)
• Created by Bjarne Stroustrup
• AT&T Labs
• 1980 - originally named “C with
Classes”
• 1983 - redesigned and renamed to C++
• 1985 - available to the public
6
Sunday, March 16, 14
Evolution of C++ (2)
• 1989 - further extensions added
• templates and exception handling
• 1998 - C++ standardized
7
Sunday, March 16, 14
Features of C++
• Object-Oriented
Programming (OOP)
Language
• Pass-by-Reference
• Operator Overloading
• Generic Programming
• Exception Handling
• Namespaces
• Default Arguments
8
Sunday, March 16, 14
OOP Review (1)
• Programming Paradigm
• Four (4) Main Attributes
• data encapsulation
• data abstraction
• inheritance
• polymorphism
9
Sunday, March 16, 14
OOP Review (2)
• Abstract Data Type (ADT)
• user-defined data type
• use of objects through functions (methods)
without knowing the internal representation
10
Sunday, March 16, 14
OOP Review (3)
• Interface
• functions (methods) provided in the ADT that
allow access to data
• Implementation
• underlying data structure(s) and business logic
within the ADT
11
Sunday, March 16, 14
OOP Review (4)
• Class
• Defines a model
• Declares attributes
• Declares behavior
• Is an ADT
• Object
• Is an instance of a class
• Has state
• Has behavior
• May have many unique
objects of the same class
12
Sunday, March 16, 14
Advantages of OOP
• Interface can (and should) remain
unchanged when improving implementation
• Encourages modularity in application
development
• Better maintainability of code
• Code reuse
• Emphasis on what, not how
13
Sunday, March 16, 14
Some C++ Keywords
• class
• new, delete
• private,
protected, public
• try, throw, catch
• friend
• explicit
• virtual
• bool
• inline
14
Sunday, March 16, 14
Classes (1)
• A user-defined abstract data type
• Extension of C structs
• Contain:
• constructor
• destructor
• data members and member functions (methods)
15
Sunday, March 16, 14
Classes (2)
• Static/Dynamic object instantiation
• Multiple Constructors:
• Sports(void);
• Sports(char *,int,int);
• Sports(float,char *,int);
16
Sunday, March 16, 14
Classes (3)
• Class scope:
• scope resolution operator(::)
• Abstract Classes
• contain at least one pure virtual member
function (C++)
• contain at least one abstract method (Java)
17
Sunday, March 16, 14
Abstract Classes
• Pure virtual member function (C++)
• virtual void draw() = 0;
• Abstract method (Java)
• public abstract void draw();
18
Sunday, March 16, 14
Class Inheritance
19
Sunday, March 16, 14
20
// Sports class (partial listing)
class Sports {
private:
char *team;
int win;
public:
Sports(void);
Sports(char const *,int,int);
~Sports(void); // destructor
int getWin() const;
};
Sports::Sports(void) {
// define default constructor here...
}
Sports::Sports(const char *team,int win,int loss) {
// define primary constructor here...
}
int Sports::getWin() const {
return win;
}
Sunday, March 16, 14
21
// Baseball class (partial listing)
class Baseball : public Sports {
public:
Baseball(void);
Baseball(char const *,int,int);
~Baseball(void);
};
Baseball::Baseball(void) : Sports() {
}
Baseball::Baseball(const char *team,int win,int loss) :
Sports(team,win,loss) {
}
inline Baseball::~Baseball(void) {
}
Sunday, March 16, 14
Static Instantiation
• Object creation:
• Baseball mets(“Mets”,97,65);
• Access to public member functions:
• mets.getWin(); // returns 97
22
Sunday, March 16, 14
Dynamic Instantiation
• Object creation:
• Baseball *mets = new
Baseball(“Mets”,97,65);
• Access to public member functions:
• mets->getWin(); // returns 97
23
Sunday, March 16, 14
Deleting Objects
Baseball mets(“Mets”,97,65);
// object deleted when out of scope
Baseball *mets = new
Baseball(“Mets”,97,65);
delete mets; // required call
24
Sunday, March 16, 14
Operator new (1)
• Allocates memory on the free store (heap)
• Memory size is calculated by the compiler
• No more casting
• Automatic call to the constructor
• Used for built-in and user-defined data
types
25
Sunday, March 16, 14
Operator new (2)
int *var = new int; // int();
Sports *sports = new Sports();
// initializes an array of pointers
to type int
int *var = new int[10]
26
Sunday, March 16, 14
Operator delete (1)
• Deallocates memory on the free store
(heap)
• Automatic call to the destructor
• Must be used according to how operator
new was used
27
Sunday, March 16, 14
Operator delete (2)
int *var = new int;
delete var;
int *var = new int[10]
delete[] var;
28
Sunday, March 16, 14
Inline Member
Functions (1)
• Used for short functions (≤ 5 statements)
• Purpose:
• speed
• Good candidates for inline member
functions are those that access data
members
29
Sunday, March 16, 14
Inline Member
Functions (2)
• Explicit Use:
• use keyword inline in the definition of
member function
• Implicit Use:
• define the member function within its
declaration without using the keyword inline
30
Sunday, March 16, 14
Live Demo!
31
Sunday, March 16, 14
Popular C++
Compilers
32
• Embarcadero C++ Builder XE5
• embarcadero.com/products/
cbuilder
• MicrosoftVisual C++
• microsoft.com
• Open Watcom 1.9
• openwatcom.org
Sunday, March 16, 14
Local C++ User
Groups
• ACGNJ C++ Users Group
• facilitated by Bruce Arnold
• acgnj.barnold.us
33
Sunday, March 16, 14
Further Reading (1)
34
• C & C++ Code Capsules
• Chuck Allison
• freshsources.com
• The C++ Programming Language
• Bjarne Stroustrup
• stroustrup.com/4th.html
Sunday, March 16, 14
Further Reading (2)
35
• The Annotated C++ Reference Manual
• Margaret Ellis and Bjarne Stroustrup
• stroustrup.com/arm.html
• 1997 C++ Public Review Document
• C++ ISO JTC1/SC22/WG21 Committee
• open-std.org/jtc1/sc22/open/
n2356
Sunday, March 16, 14
Upcoming Events (1)
• Trenton Computer Festival
• March 14-15, 2014
• tcf-nj.org
• Emerging Technologies for the Enterprise
• April 22-23, 2014
• phillyemergingtech.com
36
Sunday, March 16, 14
37
Upcoming Events (2)
Sunday, March 16, 14
38
Thanks!
mike@redlich.net
@mpredli
javasig.org
Sunday, March 16, 14

More Related Content

PPTX
Flow control, variable types
ODP
My first FOSDEM experience
PPT
linked list in c++
RTF
PPTX
Session 14 - Object Class
PDF
DATA STRUCTURE
PPTX
Session 16 - Collections - Sorting, Comparing Basics
PPTX
52 weeks of prayer
Flow control, variable types
My first FOSDEM experience
linked list in c++
Session 14 - Object Class
DATA STRUCTURE
Session 16 - Collections - Sorting, Comparing Basics
52 weeks of prayer

Viewers also liked (20)

PPTX
Literacy Assessment and the importance
PPTX
Myself
PPTX
Reducing traffic congestion
PPTX
Diapositivas de informatica
PPTX
Walk to school
PPTX
Design Portfolio - Link Version
PPSX
Rethink lockers
PPTX
Economic Analysis of a Jatropha Biodiesel-fired Power Plant in Nigeria
PPTX
Presentation
PPTX
Slideshow test
PPTX
Photo project in class samples
PPTX
NZCETA. Preparing for a New Entrepreneurial Economy
PPTX
Review of Related Literature
PDF
Svetska banka e.e.zgrada
PPT
Two choices in life
PPT
Визитка гвардейского увк 3
PPTX
Life Cycle Assessment of the use of Jatropha Biodiesel for Power Generation i...
PDF
Dasrareports tribal-education
PPTX
Aves gilang
PPTX
Kontrasepsi
Literacy Assessment and the importance
Myself
Reducing traffic congestion
Diapositivas de informatica
Walk to school
Design Portfolio - Link Version
Rethink lockers
Economic Analysis of a Jatropha Biodiesel-fired Power Plant in Nigeria
Presentation
Slideshow test
Photo project in class samples
NZCETA. Preparing for a New Entrepreneurial Economy
Review of Related Literature
Svetska banka e.e.zgrada
Two choices in life
Визитка гвардейского увк 3
Life Cycle Assessment of the use of Jatropha Biodiesel for Power Generation i...
Dasrareports tribal-education
Aves gilang
Kontrasepsi
Ad

Similar to Getting Started with C++ (TCF 2014) (20)

PDF
Getting started with C++
PDF
Getting Started with C++
PDF
C++ Advanced Features (TCF 2014)
PDF
Introduction to Object-Oriented Programming & Design Principles (TCF 2014)
PDF
Getting Started with Java (TCF 2014)
PDF
Getting Started with MongoDB (TCF ITPC 2014)
PPT
C++ - A powerful and system level language
PDF
C++ Advanced Features
PDF
Getting Started with Meteor (TCF ITPC 2014)
PDF
Intro to JavaScript Testing
PDF
C++ Advanced Features
PPT
lecture02-cpp.ppt
PDF
Getting Started with MongoDB
PPT
c++ ppt.ppt
PPTX
lecture NOTES ON OOPS C++ ON CLASS AND OBJECTS
PPT
lecture02-cpp.ppt
PPT
lecture02-cpp.ppt
PPT
lecture02-cpp.ppt
PPT
lecture02-cpp.ppt
PDF
Java Advanced Features (TCF 2014)
Getting started with C++
Getting Started with C++
C++ Advanced Features (TCF 2014)
Introduction to Object-Oriented Programming & Design Principles (TCF 2014)
Getting Started with Java (TCF 2014)
Getting Started with MongoDB (TCF ITPC 2014)
C++ - A powerful and system level language
C++ Advanced Features
Getting Started with Meteor (TCF ITPC 2014)
Intro to JavaScript Testing
C++ Advanced Features
lecture02-cpp.ppt
Getting Started with MongoDB
c++ ppt.ppt
lecture NOTES ON OOPS C++ ON CLASS AND OBJECTS
lecture02-cpp.ppt
lecture02-cpp.ppt
lecture02-cpp.ppt
lecture02-cpp.ppt
Java Advanced Features (TCF 2014)
Ad

More from Michael Redlich (11)

PDF
Getting Started with GitHub
PDF
Building Microservices with Micronaut: A Full-Stack JVM-Based Framework
PDF
Building Microservices with Helidon: Oracle's New Java Microservices Framework
PDF
Introduction to Object Oriented Programming & Design Principles
PDF
Java Advanced Features
PDF
Introduction to Object Oriented Programming & Design Principles
PDF
Getting Started with Java
PDF
Building Realtime Access to Data Apps with jOOQ
PDF
Building Realtime Access Data Apps with Speedment (TCF ITPC 2017)
PDF
Building Realtime Web Apps with Angular and Meteor
PDF
Getting Started with Meteor
Getting Started with GitHub
Building Microservices with Micronaut: A Full-Stack JVM-Based Framework
Building Microservices with Helidon: Oracle's New Java Microservices Framework
Introduction to Object Oriented Programming & Design Principles
Java Advanced Features
Introduction to Object Oriented Programming & Design Principles
Getting Started with Java
Building Realtime Access to Data Apps with jOOQ
Building Realtime Access Data Apps with Speedment (TCF ITPC 2017)
Building Realtime Web Apps with Angular and Meteor
Getting Started with Meteor

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Modernizing your data center with Dell and AMD
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Encapsulation theory and applications.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Approach and Philosophy of On baking technology
cuic standard and advanced reporting.pdf
Review of recent advances in non-invasive hemoglobin estimation
Modernizing your data center with Dell and AMD
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Building Integrated photovoltaic BIPV_UPV.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Network Security Unit 5.pdf for BCA BBA.
Encapsulation theory and applications.pdf
Electronic commerce courselecture one. Pdf
NewMind AI Monthly Chronicles - July 2025
Mobile App Security Testing_ A Comprehensive Guide.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Empathic Computing: Creating Shared Understanding
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Understanding_Digital_Forensics_Presentation.pptx
Approach and Philosophy of On baking technology

Getting Started with C++ (TCF 2014)

  • 1. 1 Getting Started with C++ Trenton Computer Festival March 15, 2014 Michael P. Redlich @mpredli about.me/mpredli/ Sunday, March 16, 14
  • 2. Who’s Mike? • BS in CS from • “Petrochemical Research Organization” • Ai-Logix, Inc. (now AudioCodes) • Amateur Computer Group of New Jersey • Publications • Presentations 2 Sunday, March 16, 14
  • 3. Objectives (1) • What is C++? • Evolution of C++ • Features of C++ • Review of Object-Oriented Programming (OOP) 3 Sunday, March 16, 14
  • 4. Objectives (2) • Getting Started with C++ • introduction to the C++ class mechanism • how to implement C++ classes • Live Demos (yea!) • C++ Resources 4 Sunday, March 16, 14
  • 5. What is C++? • “...a general purpose programming language with a bias towards systems programming that • is a better C, • supports data abstraction, • supports object-oriented programming, • supports generic programming.” Bjarne Stroustrup Web Site, http://www.stroustrup.com/C++.html 5 Sunday, March 16, 14
  • 6. Evolution of C++ (1) • Created by Bjarne Stroustrup • AT&T Labs • 1980 - originally named “C with Classes” • 1983 - redesigned and renamed to C++ • 1985 - available to the public 6 Sunday, March 16, 14
  • 7. Evolution of C++ (2) • 1989 - further extensions added • templates and exception handling • 1998 - C++ standardized 7 Sunday, March 16, 14
  • 8. Features of C++ • Object-Oriented Programming (OOP) Language • Pass-by-Reference • Operator Overloading • Generic Programming • Exception Handling • Namespaces • Default Arguments 8 Sunday, March 16, 14
  • 9. OOP Review (1) • Programming Paradigm • Four (4) Main Attributes • data encapsulation • data abstraction • inheritance • polymorphism 9 Sunday, March 16, 14
  • 10. OOP Review (2) • Abstract Data Type (ADT) • user-defined data type • use of objects through functions (methods) without knowing the internal representation 10 Sunday, March 16, 14
  • 11. OOP Review (3) • Interface • functions (methods) provided in the ADT that allow access to data • Implementation • underlying data structure(s) and business logic within the ADT 11 Sunday, March 16, 14
  • 12. OOP Review (4) • Class • Defines a model • Declares attributes • Declares behavior • Is an ADT • Object • Is an instance of a class • Has state • Has behavior • May have many unique objects of the same class 12 Sunday, March 16, 14
  • 13. Advantages of OOP • Interface can (and should) remain unchanged when improving implementation • Encourages modularity in application development • Better maintainability of code • Code reuse • Emphasis on what, not how 13 Sunday, March 16, 14
  • 14. Some C++ Keywords • class • new, delete • private, protected, public • try, throw, catch • friend • explicit • virtual • bool • inline 14 Sunday, March 16, 14
  • 15. Classes (1) • A user-defined abstract data type • Extension of C structs • Contain: • constructor • destructor • data members and member functions (methods) 15 Sunday, March 16, 14
  • 16. Classes (2) • Static/Dynamic object instantiation • Multiple Constructors: • Sports(void); • Sports(char *,int,int); • Sports(float,char *,int); 16 Sunday, March 16, 14
  • 17. Classes (3) • Class scope: • scope resolution operator(::) • Abstract Classes • contain at least one pure virtual member function (C++) • contain at least one abstract method (Java) 17 Sunday, March 16, 14
  • 18. Abstract Classes • Pure virtual member function (C++) • virtual void draw() = 0; • Abstract method (Java) • public abstract void draw(); 18 Sunday, March 16, 14
  • 20. 20 // Sports class (partial listing) class Sports { private: char *team; int win; public: Sports(void); Sports(char const *,int,int); ~Sports(void); // destructor int getWin() const; }; Sports::Sports(void) { // define default constructor here... } Sports::Sports(const char *team,int win,int loss) { // define primary constructor here... } int Sports::getWin() const { return win; } Sunday, March 16, 14
  • 21. 21 // Baseball class (partial listing) class Baseball : public Sports { public: Baseball(void); Baseball(char const *,int,int); ~Baseball(void); }; Baseball::Baseball(void) : Sports() { } Baseball::Baseball(const char *team,int win,int loss) : Sports(team,win,loss) { } inline Baseball::~Baseball(void) { } Sunday, March 16, 14
  • 22. Static Instantiation • Object creation: • Baseball mets(“Mets”,97,65); • Access to public member functions: • mets.getWin(); // returns 97 22 Sunday, March 16, 14
  • 23. Dynamic Instantiation • Object creation: • Baseball *mets = new Baseball(“Mets”,97,65); • Access to public member functions: • mets->getWin(); // returns 97 23 Sunday, March 16, 14
  • 24. Deleting Objects Baseball mets(“Mets”,97,65); // object deleted when out of scope Baseball *mets = new Baseball(“Mets”,97,65); delete mets; // required call 24 Sunday, March 16, 14
  • 25. Operator new (1) • Allocates memory on the free store (heap) • Memory size is calculated by the compiler • No more casting • Automatic call to the constructor • Used for built-in and user-defined data types 25 Sunday, March 16, 14
  • 26. Operator new (2) int *var = new int; // int(); Sports *sports = new Sports(); // initializes an array of pointers to type int int *var = new int[10] 26 Sunday, March 16, 14
  • 27. Operator delete (1) • Deallocates memory on the free store (heap) • Automatic call to the destructor • Must be used according to how operator new was used 27 Sunday, March 16, 14
  • 28. Operator delete (2) int *var = new int; delete var; int *var = new int[10] delete[] var; 28 Sunday, March 16, 14
  • 29. Inline Member Functions (1) • Used for short functions (≤ 5 statements) • Purpose: • speed • Good candidates for inline member functions are those that access data members 29 Sunday, March 16, 14
  • 30. Inline Member Functions (2) • Explicit Use: • use keyword inline in the definition of member function • Implicit Use: • define the member function within its declaration without using the keyword inline 30 Sunday, March 16, 14
  • 32. Popular C++ Compilers 32 • Embarcadero C++ Builder XE5 • embarcadero.com/products/ cbuilder • MicrosoftVisual C++ • microsoft.com • Open Watcom 1.9 • openwatcom.org Sunday, March 16, 14
  • 33. Local C++ User Groups • ACGNJ C++ Users Group • facilitated by Bruce Arnold • acgnj.barnold.us 33 Sunday, March 16, 14
  • 34. Further Reading (1) 34 • C & C++ Code Capsules • Chuck Allison • freshsources.com • The C++ Programming Language • Bjarne Stroustrup • stroustrup.com/4th.html Sunday, March 16, 14
  • 35. Further Reading (2) 35 • The Annotated C++ Reference Manual • Margaret Ellis and Bjarne Stroustrup • stroustrup.com/arm.html • 1997 C++ Public Review Document • C++ ISO JTC1/SC22/WG21 Committee • open-std.org/jtc1/sc22/open/ n2356 Sunday, March 16, 14
  • 36. Upcoming Events (1) • Trenton Computer Festival • March 14-15, 2014 • tcf-nj.org • Emerging Technologies for the Enterprise • April 22-23, 2014 • phillyemergingtech.com 36 Sunday, March 16, 14