SlideShare a Scribd company logo
  By Wayne Cheng
 Introduction
 Five Tenets
 Terminology
 The foundation of C++: Classes
 It is the name given to a specific paradigm in the field of
programming.
 With objects we are creating pieces of code that can stand
alone.
 You know the box has inputs and outputs but you don’t know
what is inside it.
 Encapsulation
 Data Abstraction
 Information Hiding
 Inheritance
 Polymorphism
 The goal is to bind data and the functions that operate on that
data together in one “object”.
 The functions will be our interface while the data will be
hidden in the black box.
 Classes in C++ bind data and functions together in objects.
 The goal is to force users to interface with the object’s
functions rather than accessing data directly.
 Data is in the box.
 The user can not access the data, he/she must use the defined
interface functions to manipulate the data.
 Public: elements of class are accessible from outside of class.
 Private: restricts access to these functions and data members to
this class alone. (as default)
 Protected: restricts access to these functions and data member
to this class and its children. (Children are classes derived
from the current class)
 The goal is to prevent the user from seeing how our functions
are implemented and exactly what they do.
 All the user will see are function prototypes, but no actual
implementation.
 Multiple file projects: by storing each class implementation in
its own file, we can compile and distribute them without
allowing users to see the internals of functions.
The syntax for a class definition is
o class Class_Name
{
public:
Member_Specification 1
Member_Specification 2
…
Member_Specification 3
private:
Member_Specification_n+1
Member_Specification_n+2
…
};
 It is a mechanism that allows us to include “Parent” class into
a “Child” class.
 It just another name for the topic of derived classes.
 The goal is code reusability and extensibility.
 With it we can reuse code without having to cut and paste it
out of our old programs.
 It is a major stepping stone on the path to polymorphism.
 The goal is to write generic code that can handle multiple
objects in the same way.
 In code, we can pass multiple objects all as the same base
object.
 It is refers to the ability to associate multiple meaning to one
function name by means of a special mechanism known as
“Late Binding”.
 We use class hierarchies to allow us to treat child classes as
their parent class or grandparent, etc.
 Object – A collection of related data and functions bound together.
 Method – A function of an object.
 Message – A call to an object method. The term “message passing”
in reference to OOP you are dealing with method calls.
 Member – A method or variable that is part of an object (or class).
 Association – an object using another object that exists outside of
the first. (Must pass by address or reference)
 Aggregation – An object that contains another object.
 Generalization – An object that publicly inherits its parent.
(Inheritance)
 Instance – variable of data type (class or struct).
 The class is how we are able to implement OOP concepts in
C++.
 The class by itself gives us three of our five tenets OOP such
are Encapsulation, Data Abstraction and Information Hiding.
 It is a technique used in binding functions to the data that they
manipulate. (Encapsulation)
 It allows us to protect the data from the users direct
manipulation. (Data Abstraction)
 It allows us to hide the implementation of functions from the
user. (Information Hiding)
 It defines all its members to be private by default.
 A class is a data type whose variables are objects
 The definition of a class includes
- Description of the kinds of values of the member variables
- Description of the member functions
 A class description is somewhat like a structure definition plus
the member variables
 Examine a stack class: two functions and two pieces of data.
Class: stack
Functions
1. “Push”: it will have one parameter and will return a Boolean value indicating
success or failure. The data passed in will be placed at the into the stack
at the top.
2. “Pop”: it will have one parameter, a reference, and will return a
Boolean value indicating success or failure. The value of the reference
will be set to the value at the top of the stack.
Data:
1. The first element of data will be the stack itself.
2. The second element of data will be called top and will mark the current
position in the stack.
/////////////////////////////////////////////////////
//File IntStack.h
// This is an integer stack class.
/////////////////////////////////////////////////////
class IntStack
{ public:
IntStack(); //the class constructors
int push(int); //the push function prototype
int pop(int&); //the pop function prototype
private:
int stack[10], top; //the definition of calss variables
}
///////////////////////////////////////////////
//File: IntStack.cpp
///////////////////////////////////////////////
#include “IntStack.h” //Import class specification
IntStack::IntStack() //The constructor
{ top = -1; }
int IntStack::push(int x) //The push function implementation
{ if(top == 9) return 0;
top++;
stack[top] = x;
return 1; }
int IntStack::pop(int & x) //The pop function implementation
{ if(top == -1) return 0;
x = stack[top];
top--;
return 1; }
/////////////////////////////////////////////
//pgm.cpp
/////////////////////////////////////////////
#include “IntStack.h”
#include <iostream.h>
void main ( )
{ IntStack stack;
int back;
for (int x = 0; x < 12; x++)
{ cout << “Pushing “ << x << “…”;
cout << (stack.push(x)?”Success” : ”Fail”) << endl; }
for (x = 0; x < 12; x++)
{ cout << “Poping…”;
(stack.pop(back)? (cout << back) : (cout << “Fail”)) << endl; }
}
Use Classes with Object-Oriented Programming in C++.ppt

More Related Content

PPTX
Lecture 4. mte 407
rumanatasnim415
 
PDF
Class and object
Prof. Dr. K. Adisesha
 
PPTX
C++ & Data Structure - Unit - first.pptx
KONGUNADU COLLEGE OF ENGINEERING AND TECHNOLOGY
 
PPTX
Classes and objects
Shailendra Veeru
 
PPT
c++ introduction
sai kumar
 
PPT
c++ lecture 1
sai kumar
 
Lecture 4. mte 407
rumanatasnim415
 
Class and object
Prof. Dr. K. Adisesha
 
C++ & Data Structure - Unit - first.pptx
KONGUNADU COLLEGE OF ENGINEERING AND TECHNOLOGY
 
Classes and objects
Shailendra Veeru
 
c++ introduction
sai kumar
 
c++ lecture 1
sai kumar
 

Similar to Use Classes with Object-Oriented Programming in C++.ppt (20)

PPT
c++ lecture 1
sai kumar
 
PPT
While writing program in any language, you need to use various variables to s...
bhargavi804095
 
PPT
11-Classes.ppt
basavaraj852759
 
PPT
Unit 5.ppt
JITTAYASHWANTHREDDY
 
PPT
Major terminologies in oop (Lect 2).ppt. Object oriented programming
nungogerald
 
DOC
My c++
snathick
 
PPTX
C++ programming introduction
sandeep54552
 
PPTX
Presentation on class and object in Object Oriented programming.
Enam Khan
 
PPTX
object oriented programming language in c++
Ravikant517175
 
PPTX
Object oriented design
lykado0dles
 
PPTX
C++ theory
Shyam Khant
 
PPTX
oopusingc.pptx
MohammedAlobaidy16
 
PPTX
OOC MODULE1.pptx
1HK19CS090MOHAMMEDSA
 
PDF
Implementation of oop concept in c++
Swarup Boro
 
PPTX
ccc
Zainab Irshad
 
PPT
Object and class presentation
nafisa rahman
 
PPTX
Concept of Object-Oriented in C++
Abdullah Jan
 
PPT
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 
PDF
Implementation of oop concept in c++
Swarup Kumar Boro
 
PPTX
C++ presentation
SudhanshuVijay3
 
c++ lecture 1
sai kumar
 
While writing program in any language, you need to use various variables to s...
bhargavi804095
 
11-Classes.ppt
basavaraj852759
 
Major terminologies in oop (Lect 2).ppt. Object oriented programming
nungogerald
 
My c++
snathick
 
C++ programming introduction
sandeep54552
 
Presentation on class and object in Object Oriented programming.
Enam Khan
 
object oriented programming language in c++
Ravikant517175
 
Object oriented design
lykado0dles
 
C++ theory
Shyam Khant
 
oopusingc.pptx
MohammedAlobaidy16
 
OOC MODULE1.pptx
1HK19CS090MOHAMMEDSA
 
Implementation of oop concept in c++
Swarup Boro
 
Object and class presentation
nafisa rahman
 
Concept of Object-Oriented in C++
Abdullah Jan
 
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 
Implementation of oop concept in c++
Swarup Kumar Boro
 
C++ presentation
SudhanshuVijay3
 
Ad

Recently uploaded (20)

PPTX
Presentation of Computer CLASS 2 .pptx
darshilchaudhary558
 
PPTX
AZ900_SLA_Pricing_2025_LondonIT (1).pptx
chumairabdullahph
 
PPTX
Audio Editing and it's techniques in computer graphics.pptx
fosterbayirinia3
 
PDF
The Role of Automation and AI in EHS Management for Data Centers.pdf
TECH EHS Solution
 
PDF
Emergency Mustering solutions – A Brief overview
Personnel Tracking
 
PPTX
AIRLINE PRICE API | FLIGHT API COST |
philipnathen82
 
PDF
Rise With SAP partner in Mumbai.........
pts464036
 
PDF
Become an Agentblazer Champion Challenge
Dele Amefo
 
PDF
Build Multi-agent using Agent Development Kit
FadyIbrahim23
 
PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
PPTX
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PPTX
10 Hidden App Development Costs That Can Sink Your Startup.pptx
Lunar Web Solution
 
DOCX
The Five Best AI Cover Tools in 2025.docx
aivoicelabofficial
 
PPTX
Why Use Open Source Reporting Tools for Business Intelligence.pptx
Varsha Nayak
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PDF
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
PDF
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
PDF
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
NSIQINFOTECH
 
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
PPTX
Materi-Enum-and-Record-Data-Type (1).pptx
RanuFajar1
 
Presentation of Computer CLASS 2 .pptx
darshilchaudhary558
 
AZ900_SLA_Pricing_2025_LondonIT (1).pptx
chumairabdullahph
 
Audio Editing and it's techniques in computer graphics.pptx
fosterbayirinia3
 
The Role of Automation and AI in EHS Management for Data Centers.pdf
TECH EHS Solution
 
Emergency Mustering solutions – A Brief overview
Personnel Tracking
 
AIRLINE PRICE API | FLIGHT API COST |
philipnathen82
 
Rise With SAP partner in Mumbai.........
pts464036
 
Become an Agentblazer Champion Challenge
Dele Amefo
 
Build Multi-agent using Agent Development Kit
FadyIbrahim23
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
10 Hidden App Development Costs That Can Sink Your Startup.pptx
Lunar Web Solution
 
The Five Best AI Cover Tools in 2025.docx
aivoicelabofficial
 
Why Use Open Source Reporting Tools for Business Intelligence.pptx
Varsha Nayak
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
NSIQINFOTECH
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
Materi-Enum-and-Record-Data-Type (1).pptx
RanuFajar1
 
Ad

Use Classes with Object-Oriented Programming in C++.ppt

  • 1.   By Wayne Cheng
  • 2.  Introduction  Five Tenets  Terminology  The foundation of C++: Classes
  • 3.  It is the name given to a specific paradigm in the field of programming.  With objects we are creating pieces of code that can stand alone.  You know the box has inputs and outputs but you don’t know what is inside it.
  • 4.  Encapsulation  Data Abstraction  Information Hiding  Inheritance  Polymorphism
  • 5.  The goal is to bind data and the functions that operate on that data together in one “object”.  The functions will be our interface while the data will be hidden in the black box.  Classes in C++ bind data and functions together in objects.
  • 6.  The goal is to force users to interface with the object’s functions rather than accessing data directly.  Data is in the box.  The user can not access the data, he/she must use the defined interface functions to manipulate the data.  Public: elements of class are accessible from outside of class.  Private: restricts access to these functions and data members to this class alone. (as default)  Protected: restricts access to these functions and data member to this class and its children. (Children are classes derived from the current class)
  • 7.  The goal is to prevent the user from seeing how our functions are implemented and exactly what they do.  All the user will see are function prototypes, but no actual implementation.  Multiple file projects: by storing each class implementation in its own file, we can compile and distribute them without allowing users to see the internals of functions.
  • 8. The syntax for a class definition is o class Class_Name { public: Member_Specification 1 Member_Specification 2 … Member_Specification 3 private: Member_Specification_n+1 Member_Specification_n+2 … };
  • 9.  It is a mechanism that allows us to include “Parent” class into a “Child” class.  It just another name for the topic of derived classes.  The goal is code reusability and extensibility.  With it we can reuse code without having to cut and paste it out of our old programs.  It is a major stepping stone on the path to polymorphism.
  • 10.  The goal is to write generic code that can handle multiple objects in the same way.  In code, we can pass multiple objects all as the same base object.  It is refers to the ability to associate multiple meaning to one function name by means of a special mechanism known as “Late Binding”.  We use class hierarchies to allow us to treat child classes as their parent class or grandparent, etc.
  • 11.  Object – A collection of related data and functions bound together.  Method – A function of an object.  Message – A call to an object method. The term “message passing” in reference to OOP you are dealing with method calls.  Member – A method or variable that is part of an object (or class).  Association – an object using another object that exists outside of the first. (Must pass by address or reference)  Aggregation – An object that contains another object.  Generalization – An object that publicly inherits its parent. (Inheritance)  Instance – variable of data type (class or struct).
  • 12.  The class is how we are able to implement OOP concepts in C++.  The class by itself gives us three of our five tenets OOP such are Encapsulation, Data Abstraction and Information Hiding.  It is a technique used in binding functions to the data that they manipulate. (Encapsulation)  It allows us to protect the data from the users direct manipulation. (Data Abstraction)  It allows us to hide the implementation of functions from the user. (Information Hiding)  It defines all its members to be private by default.
  • 13.  A class is a data type whose variables are objects  The definition of a class includes - Description of the kinds of values of the member variables - Description of the member functions  A class description is somewhat like a structure definition plus the member variables
  • 14.  Examine a stack class: two functions and two pieces of data. Class: stack Functions 1. “Push”: it will have one parameter and will return a Boolean value indicating success or failure. The data passed in will be placed at the into the stack at the top. 2. “Pop”: it will have one parameter, a reference, and will return a Boolean value indicating success or failure. The value of the reference will be set to the value at the top of the stack. Data: 1. The first element of data will be the stack itself. 2. The second element of data will be called top and will mark the current position in the stack.
  • 15. ///////////////////////////////////////////////////// //File IntStack.h // This is an integer stack class. ///////////////////////////////////////////////////// class IntStack { public: IntStack(); //the class constructors int push(int); //the push function prototype int pop(int&); //the pop function prototype private: int stack[10], top; //the definition of calss variables }
  • 16. /////////////////////////////////////////////// //File: IntStack.cpp /////////////////////////////////////////////// #include “IntStack.h” //Import class specification IntStack::IntStack() //The constructor { top = -1; } int IntStack::push(int x) //The push function implementation { if(top == 9) return 0; top++; stack[top] = x; return 1; } int IntStack::pop(int & x) //The pop function implementation { if(top == -1) return 0; x = stack[top]; top--; return 1; }
  • 17. ///////////////////////////////////////////// //pgm.cpp ///////////////////////////////////////////// #include “IntStack.h” #include <iostream.h> void main ( ) { IntStack stack; int back; for (int x = 0; x < 12; x++) { cout << “Pushing “ << x << “…”; cout << (stack.push(x)?”Success” : ”Fail”) << endl; } for (x = 0; x < 12; x++) { cout << “Poping…”; (stack.pop(back)? (cout << back) : (cout << “Fail”)) << endl; } }