SlideShare a Scribd company logo
1
Getting Started with
C++
Trenton Computer Festival
March 18, 2017
Michael P. Redlich
@mpredli
about.me/mpredli/
Who’s Mike?
• BS in CS from
• “Petrochemical Research Organization”
• Java Queue News Editor, InfoQ
• Ai-Logix, Inc. (now AudioCodes)
• Amateur Computer Group of New Jersey
2
Objectives (1)
• What is C++?
• Evolution of C++
• Features of C++
• Review of Object-Oriented Programming
(OOP)
3
Objectives (2)
• Getting Started with C++
• introduction to the C++ class mechanism
• how to implement C++ classes
• Live Demos (yea!)
• C++ Resources
4
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
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
Evolution of C++ (2)
• 1989 - further extensions added
• templates and exception handling
• 1998 - C++ standardized
7
Features of C++
• Object-Oriented
Programming (OOP)
Language
• Pass-by-Reference
• Operator Overloading
• Generic Programming
• Exception Handling
• Namespaces
• Default Arguments
8
OOP Review (1)
• Programming Paradigm
• Four (4) Main Attributes
• data encapsulation
• data abstraction
• inheritance
• polymorphism
9
OOP Review (2)
• Abstract Data Type (ADT)
• user-defined data type
• use of objects through functions (methods)
without knowing the internal representation
10
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
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
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
Some C++ Keywords
• class
• new, delete
• private,
protected, public
• try, throw, catch
• friend
• explicit
• virtual
• bool
• inline
14
Classes (1)
• A user-defined abstract data type
• Extension of C structs
• Contain:
• constructor
• destructor
• data members and member functions (methods)
15
Classes (2)
• Static/Dynamic object instantiation
• Multiple Constructors:
• Sports(void);
• Sports(char *,int,int);
• Sports(float,char *,int);
16
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
Abstract Classes
• Pure virtual member function (C++)
• virtual void draw() = 0;
• Abstract method (Java)
• public abstract void draw();
18
Class Inheritance
19
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;
}
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) {
}
Static Instantiation
• Object creation:
• Baseball mets(“Mets”,97,65);
• Access to public member functions:
• mets.getWin(); // returns 97
22
Dynamic Instantiation
• Object creation:
• Baseball *mets = new
Baseball(“Mets”,97,65);
• Access to public member functions:
• mets->getWin(); // returns 97
23
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
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
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
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
Operator delete (2)
int *var = new int;
delete var;
int *var = new int[10]
delete[] var;
28
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
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
Live Demo!
31
Popular C++
Compilers
32
• Embarcadero C++ Builder XE7
• embarcadero.com/products/cbuilder
• MicrosoftVisual C++
• microsoft.com
• Intel System Studio
• software.intel.com/en-us/c-
compilers
Popular C++
Compilers
33
• Open Watcom 1.9 (June 2010)
• openwatcom.org
Local C++ User
Groups
• ACGNJ C++ Users Group
• facilitated by Bruce Arnold
• acgnj.barnold.us
34
Further Reading (1)
35
• C & C++ Code Capsules
• Chuck Allison
• freshsources.com
• The C++ Programming Language
• Bjarne Stroustrup
• stroustrup.com/4th.html
Further Reading (2)
36
• 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
Upcoming Events
• ACGNJ Java Users Group
• Dr. Venkat Subramaniam
• Monday, March 19, 2018
• DorothyYoung Center for the Arts, Room 106
• Drew University
• 7:30-9:00pm
• “Twelve Ways to Make Code Suck Less”
37
38
Thanks!
mike@redlich.net
@mpredli
redlich.net
slideshare.net/mpredli01
github.com/mpredli01
Upcoming Events
• March 17-18, 2017
•tcf-nj.org
• April 18-19, 2017
•phillyemergingtech.com
39

More Related Content

PDF
Getting Started with C++
PDF
Getting Started with C++ (TCF 2014)
PPTX
Introduction to java
DOC
Fic (sendup dec17) cs lb
PDF
Introduction to Object Oriented Programming & Design Principles
PDF
Debugging Your Production JVM
PDF
Introduction to Object Oriented Programming & Design Principles
PPTX
Intro to kotlin 2018
Getting Started with C++
Getting Started with C++ (TCF 2014)
Introduction to java
Fic (sendup dec17) cs lb
Introduction to Object Oriented Programming & Design Principles
Debugging Your Production JVM
Introduction to Object Oriented Programming & Design Principles
Intro to kotlin 2018

What's hot (9)

PDF
Java Day-5
PDF
Java Day-4
PDF
Java Day-6
PPTX
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
PDF
TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...
PPTX
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)
PDF
Reducing Redundancies in Multi-Revision Code Analysis
PPTX
Data Type C# - Lec2 (Workshop on C# Programming: Learn to Build)
PDF
Integration with swift
Java Day-5
Java Day-4
Java Day-6
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...
Type Casting C# - Lec4 (Workshop on C# Programming: Learn to Build)
Reducing Redundancies in Multi-Revision Code Analysis
Data Type C# - Lec2 (Workshop on C# Programming: Learn to Build)
Integration with swift
Ad

Similar to Getting started with C++ (20)

PPT
lecture5-cpp.pptintroduccionaC++basicoye
PPT
Introduction to Inheritance in C plus plus
PPT
lecture02-cpp.ppt
PPT
UsingCPP_for_Artist.ppt
PPTX
lecture NOTES ON OOPS C++ ON CLASS AND OBJECTS
PPT
c++ ppt.ppt
PPT
lecture02-cpp.ppt
PPT
lecture02-cpp.ppt
PPT
lecture02-cpp.ppt
PPT
lecture02-cpp.ppt
PPT
C++ - A powerful and system level language
PPTX
C++ overview
PPTX
c++session 1.pptx
PPTX
Procedure Oriented programming Object Oriented programming Basic Concept of ...
PPTX
Interoduction to c++
PPTX
Object Oriented Programming Using C++.pptx
PDF
M.c.a (sem iii) paper - i - object oriented programming
PPTX
Object oriented programming. (1).pptx
PPTX
C++ with student management system project
lecture5-cpp.pptintroduccionaC++basicoye
Introduction to Inheritance in C plus plus
lecture02-cpp.ppt
UsingCPP_for_Artist.ppt
lecture NOTES ON OOPS C++ ON CLASS AND OBJECTS
c++ ppt.ppt
lecture02-cpp.ppt
lecture02-cpp.ppt
lecture02-cpp.ppt
lecture02-cpp.ppt
C++ - A powerful and system level language
C++ overview
c++session 1.pptx
Procedure Oriented programming Object Oriented programming Basic Concept of ...
Interoduction to c++
Object Oriented Programming Using C++.pptx
M.c.a (sem iii) paper - i - object oriented programming
Object oriented programming. (1).pptx
C++ with student management system project
Ad

More from Michael Redlich (18)

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
C++ Advanced Features
PDF
Java Advanced Features
PDF
Getting Started with Java
PDF
C++ Advanced Features
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
Java Advanced Features (TCF 2014)
PDF
Introduction to Object-Oriented Programming & Design Principles (TCF 2014)
PDF
Getting Started with Meteor (TCF ITPC 2014)
PDF
Getting Started with Java (TCF 2014)
PDF
C++ Advanced Features (TCF 2014)
PDF
Getting Started with MongoDB (TCF ITPC 2014)
PDF
Getting Started with MongoDB
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
C++ Advanced Features
Java Advanced Features
Getting Started with Java
C++ Advanced Features
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
Java Advanced Features (TCF 2014)
Introduction to Object-Oriented Programming & Design Principles (TCF 2014)
Getting Started with Meteor (TCF ITPC 2014)
Getting Started with Java (TCF 2014)
C++ Advanced Features (TCF 2014)
Getting Started with MongoDB (TCF ITPC 2014)
Getting Started with MongoDB
Getting Started with Meteor

Recently uploaded (20)

PPTX
Transform Your Business with a Software ERP System
PDF
Digital Strategies for Manufacturing Companies
PPT
Introduction Database Management System for Course Database
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
L1 - Introduction to python Backend.pptx
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Online Work Permit System for Fast Permit Processing
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
System and Network Administration Chapter 2
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
AI in Product Development-omnex systems
Transform Your Business with a Software ERP System
Digital Strategies for Manufacturing Companies
Introduction Database Management System for Course Database
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Wondershare Filmora 15 Crack With Activation Key [2025
L1 - Introduction to python Backend.pptx
VVF-Customer-Presentation2025-Ver1.9.pptx
Online Work Permit System for Fast Permit Processing
How to Migrate SBCGlobal Email to Yahoo Easily
How Creative Agencies Leverage Project Management Software.pdf
Upgrade and Innovation Strategies for SAP ERP Customers
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Odoo Companies in India – Driving Business Transformation.pdf
System and Network Administration Chapter 2
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Design an Analysis of Algorithms I-SECS-1021-03
AI in Product Development-omnex systems

Getting started with C++

  • 1. 1 Getting Started with C++ Trenton Computer Festival March 18, 2017 Michael P. Redlich @mpredli about.me/mpredli/
  • 2. Who’s Mike? • BS in CS from • “Petrochemical Research Organization” • Java Queue News Editor, InfoQ • Ai-Logix, Inc. (now AudioCodes) • Amateur Computer Group of New Jersey 2
  • 3. Objectives (1) • What is C++? • Evolution of C++ • Features of C++ • Review of Object-Oriented Programming (OOP) 3
  • 4. Objectives (2) • Getting Started with C++ • introduction to the C++ class mechanism • how to implement C++ classes • Live Demos (yea!) • C++ Resources 4
  • 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
  • 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
  • 7. Evolution of C++ (2) • 1989 - further extensions added • templates and exception handling • 1998 - C++ standardized 7
  • 8. Features of C++ • Object-Oriented Programming (OOP) Language • Pass-by-Reference • Operator Overloading • Generic Programming • Exception Handling • Namespaces • Default Arguments 8
  • 9. OOP Review (1) • Programming Paradigm • Four (4) Main Attributes • data encapsulation • data abstraction • inheritance • polymorphism 9
  • 10. OOP Review (2) • Abstract Data Type (ADT) • user-defined data type • use of objects through functions (methods) without knowing the internal representation 10
  • 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
  • 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
  • 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
  • 14. Some C++ Keywords • class • new, delete • private, protected, public • try, throw, catch • friend • explicit • virtual • bool • inline 14
  • 15. Classes (1) • A user-defined abstract data type • Extension of C structs • Contain: • constructor • destructor • data members and member functions (methods) 15
  • 16. Classes (2) • Static/Dynamic object instantiation • Multiple Constructors: • Sports(void); • Sports(char *,int,int); • Sports(float,char *,int); 16
  • 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
  • 18. Abstract Classes • Pure virtual member function (C++) • virtual void draw() = 0; • Abstract method (Java) • public abstract void draw(); 18
  • 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; }
  • 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) { }
  • 22. Static Instantiation • Object creation: • Baseball mets(“Mets”,97,65); • Access to public member functions: • mets.getWin(); // returns 97 22
  • 23. Dynamic Instantiation • Object creation: • Baseball *mets = new Baseball(“Mets”,97,65); • Access to public member functions: • mets->getWin(); // returns 97 23
  • 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
  • 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
  • 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
  • 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
  • 28. Operator delete (2) int *var = new int; delete var; int *var = new int[10] delete[] var; 28
  • 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
  • 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
  • 32. Popular C++ Compilers 32 • Embarcadero C++ Builder XE7 • embarcadero.com/products/cbuilder • MicrosoftVisual C++ • microsoft.com • Intel System Studio • software.intel.com/en-us/c- compilers
  • 33. Popular C++ Compilers 33 • Open Watcom 1.9 (June 2010) • openwatcom.org
  • 34. Local C++ User Groups • ACGNJ C++ Users Group • facilitated by Bruce Arnold • acgnj.barnold.us 34
  • 35. Further Reading (1) 35 • C & C++ Code Capsules • Chuck Allison • freshsources.com • The C++ Programming Language • Bjarne Stroustrup • stroustrup.com/4th.html
  • 36. Further Reading (2) 36 • 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
  • 37. Upcoming Events • ACGNJ Java Users Group • Dr. Venkat Subramaniam • Monday, March 19, 2018 • DorothyYoung Center for the Arts, Room 106 • Drew University • 7:30-9:00pm • “Twelve Ways to Make Code Suck Less” 37
  • 39. Upcoming Events • March 17-18, 2017 •tcf-nj.org • April 18-19, 2017 •phillyemergingtech.com 39