SlideShare a Scribd company logo
CSE201
Unit – II
Implementation of classes
25-03-2023 Ref. "Object-Oriented Programming in C++" by Robert Lafore
Object-Oriented Approach
25-03-2023 2
Ref. "Object-Oriented Programming in C++" by Robert Lafore
Data
Functions
that operate
on data
Object
Object-Oriented Approach
25-03-2023 3
Ref. "Object-Oriented Programming in C++" by Robert Lafore
Roll_no
M1,M2,M3
calTotal()
student
Object-Oriented Approach
25-03-2023 4
Ref. "Object-Oriented Programming in C++" by Robert Lafore
Data
Functions
that operate
on data
Object
An object’s functions, called member
functions in C++, typically provide the
only way to access its data
Object-Oriented Approach
25-03-2023 5
Ref. "Object-Oriented Programming in C++" by Robert Lafore
Data
Member
Functions
Object - 1
member functions or methods
Attributes or instance variables
Classes
• In OOP, Objects are instances of classes
25-03-2023 6
Ref. "Object-Oriented Programming in C++" by Robert Lafore
Class
Attributes
Member functions
Object-1
Attributes
Member functions
Object-2
Attributes
Member functions
Object-1 & 2 are of type
class
Implementation of classes
25-03-2023 7
Ref. "Object-Oriented Programming in C++" by Robert Lafore
class firstClass
{
int a,b;
int add(int x, int y)
{
a=x; b=y;
return (a+b);
}
};
Class
Attributes
Member functions
Object-Oriented Approach
25-03-2023 8
Ref. "Object-Oriented Programming in C++" by Robert Lafore
Data
Member
Functions
Object - 1
Data is
hidden So, its safe from accidental
alteration – DATA HIDING
Implementation of classes
25-03-2023 9
Ref. "Object-Oriented Programming in C++" by Robert Lafore
class firstClass
{
int a,b; // should be accessed by member function only
int add(int x, int y) // can be accessed by main ()
{
a=x; b=y;
return (a+b);
}
}; Set rights or give the access
specifications using “Access Specifier”
Implementation of classes
25-03-2023 10
Ref. "Object-Oriented Programming in C++" by Robert Lafore
class firstClass
{
private: // access specifier
int a,b;
public: // access specifier
int add(int x, int y)
{
a=x; b=y;
return (a+b);
}
};
Class is ready!!
Implementation of classes
25-03-2023 11
Ref. "Object-Oriented Programming in C++" by Robert Lafore
class firstClass
{
private: // access specifier
int a,b;
public: // access specifier
int add(int x, int y)
{
a=x; b=y;
return (a+b);
}
};
int main()
{
firstClass obj; //declaring an obj
int sum;
sum=obj.add(5,6); //msg passing
cout<<“Sum =”<<sum;
}
Implementation of classes
25-03-2023 12
Ref. "Object-Oriented Programming in C++" by Robert Lafore
class firstClass
{
private: // access specifier
int a,b;
public: // access specifier
int add(int x, int y)
{
a=x; b=y;
return (a+b);
}
};
int main()
{
firstClass obj; //declaring an obj
int x, y, sum;
cout<<“Enter values for x and y:”;
cin>>x>>y;
sum=obj.add(x,y); //msg passing
cout<<“Sum =”<<sum;
}
Classes
25-03-2023 13
Ref. "Object-Oriented Programming in C++" by Robert Lafore
• Class Data: The data items within a class are called data members (or
sometimes member data).
• Member Functions: Member functions are functions that are included
within a class.
• int add(int x, int y);
• Defining class: Defining objects in this way means creating them. This is
also called instantiating them.
• firstClass obj;
• The term instantiating arises because an instance of the class is created. An
object is an instance of a class.
• Objects are sometimes called instance variables.
Classes
25-03-2023 14
Ref. "Object-Oriented Programming in C++" by Robert Lafore
• Calling member function: The data items within a class are called
data members (or sometimes member data).
• obj.add(x, y); - The dot operator is also called the class member access
operator.)
Implementation of classes
25-03-2023 15
Ref. "Object-Oriented Programming in C++" by Robert Lafore
#include <iostream>
using namespace std;
class Distance
{
private:
int feet;
float inches;
public:
void setdist(int ft, float in)
{ feet = ft; inches = in; }
void getdist()
{
cout << “nEnter feet: “; cin >> feet;
cout << “Enter inches: “; cin >> inches;
}
void showdist() //display distance
{ cout << feet << “’-” << inches << ‘”’; }
};
int main()
{
Distance dist1, dist2;
dist1.setdist(11, 6.25);
dist2.getdist();
cout << “ndist1 = “; dist1.showdist();
cout << “ndist2 = “; dist2.showdist();
cout << endl;
return 0;
}
More On Classes and Objects
25-03-2023 16
Ref. "Object-Oriented Programming in C++" by Robert Lafore
17
Dr. J. Sangeetha/CSE/SRC/SASTRA
18
Dr. J. Sangeetha/CSE/SRC/SASTRA
19
Dr. J. Sangeetha/CSE/SRC/SASTRA
20
Dr. J. Sangeetha/CSE/SRC/SASTRA
Dr. J. Sangeetha/CSE/SRC/SASTRA 21
Dr. J. Sangeetha/CSE/SRC/SASTRA 22
23
Dr. J. Sangeetha/CSE/SRC/SASTRA
Method : 1 – Defining member function inside the class –
By default inline
Ex : 2
Dr. J. Sangeetha/CSE/SRC/SASTRA 24
Dr. J. Sangeetha/CSE/SRC/SASTRA 25
Ex : 3
Dr. J. Sangeetha/CSE/SRC/SASTRA 26
27
Dr. J. Sangeetha/CSE/SRC/SASTRA
Ex: 4
Dr. J. Sangeetha/CSE/SRC/SASTRA 28
Dr. J. Sangeetha/CSE/SRC/SASTRA 29
Method 2 : Member function definition outside the class
Dr. J. Sangeetha/CSE/SRC/SASTRA 30
Dr. J. Sangeetha/CSE/SRC/SASTRA 31
Difference between Classes and Structures
• In C++, a structure works the same way as a class, except for just two
small differences. The most important of them is hiding
implementation details.
• A structure will by default not hide its implementation details from
whoever uses it in code, while a class by default hides all its
implementation details and will therefore by default prevent the
programmer from accessing them.
• The following table summarizes all of the fundamental differences.
25-03-2023 32
Ref. "Object-Oriented Programming in C++" by Robert Lafore
25-03-2023 33
Ref. "Object-Oriented Programming in C++" by Robert Lafore
25-03-2023 34
Ref. "Object-Oriented Programming in C++" by Robert Lafore
Example – Employee details
25-03-2023 35
Ref. "Object-Oriented Programming in C++" by Robert Lafore
25-03-2023 36
Ref. "Object-Oriented Programming in C++" by Robert Lafore
25-03-2023 37
Ref. "Object-Oriented Programming in C++" by Robert Lafore
Example: Student details
25-03-2023 38
Ref. "Object-Oriented Programming in C++" by Robert Lafore
25-03-2023 39
Ref. "Object-Oriented Programming in C++" by Robert Lafore
Reference
• Robert Lafore. Object oriented programming in C++, Pearson
Education, Fourth Edition, 2012.
25-03-2023 40
Ad

More Related Content

Similar to 6. Implementation of classes_and_its_advantages.pdf (20)

chapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdfchapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdf
study material
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
Dennis Chang
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
Getachew Ganfur
 
OOP WITH C++-ppt Slide show unitwise NOTES
OOP WITH C++-ppt Slide show unitwise NOTESOOP WITH C++-ppt Slide show unitwise NOTES
OOP WITH C++-ppt Slide show unitwise NOTES
RAJESH456811
 
Evaluating Your Learning to Rank Model: Dos and Don’ts in Offline/Online Eval...
Evaluating Your Learning to Rank Model: Dos and Don’ts in Offline/Online Eval...Evaluating Your Learning to Rank Model: Dos and Don’ts in Offline/Online Eval...
Evaluating Your Learning to Rank Model: Dos and Don’ts in Offline/Online Eval...
Sease
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
Rounak Samdadia
 
C++ tutorial assignment - 23MTS5730.pptx
C++ tutorial assignment  - 23MTS5730.pptxC++ tutorial assignment  - 23MTS5730.pptx
C++ tutorial assignment - 23MTS5730.pptx
sp1312004
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
Envision Computer Training Institute
 
Intro-OOP-PPT- an introduction to the su
Intro-OOP-PPT- an introduction to the suIntro-OOP-PPT- an introduction to the su
Intro-OOP-PPT- an introduction to the su
ImranAliQureshi3
 
OOP PPT 1.pptx
OOP PPT 1.pptxOOP PPT 1.pptx
OOP PPT 1.pptx
lathass5
 
Chapter 2 OOP using C++ (Introduction).pptx
Chapter 2 OOP using C++ (Introduction).pptxChapter 2 OOP using C++ (Introduction).pptx
Chapter 2 OOP using C++ (Introduction).pptx
FiraolGadissa
 
Object & classes
Object & classes Object & classes
Object & classes
Paresh Parmar
 
C++ Interview Questions and Answers PDF By ScholarHat
C++ Interview Questions and Answers PDF By ScholarHatC++ Interview Questions and Answers PDF By ScholarHat
C++ Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Classes in C++ computer language presentation.ppt
Classes in C++ computer language presentation.pptClasses in C++ computer language presentation.ppt
Classes in C++ computer language presentation.ppt
AjayLobo1
 
Unit ii
Unit   iiUnit   ii
Unit ii
donny101
 
OOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming languageOOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming language
PreethaV16
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
Mayank Jain
 
Class and object
Class and objectClass and object
Class and object
Prof. Dr. K. Adisesha
 
C++ Classes Tutorials.ppt
C++ Classes Tutorials.pptC++ Classes Tutorials.ppt
C++ Classes Tutorials.ppt
aasuran
 
Class and object
Class and objectClass and object
Class and object
prabhat kumar
 
chapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdfchapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdf
study material
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
Dennis Chang
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
Getachew Ganfur
 
OOP WITH C++-ppt Slide show unitwise NOTES
OOP WITH C++-ppt Slide show unitwise NOTESOOP WITH C++-ppt Slide show unitwise NOTES
OOP WITH C++-ppt Slide show unitwise NOTES
RAJESH456811
 
Evaluating Your Learning to Rank Model: Dos and Don’ts in Offline/Online Eval...
Evaluating Your Learning to Rank Model: Dos and Don’ts in Offline/Online Eval...Evaluating Your Learning to Rank Model: Dos and Don’ts in Offline/Online Eval...
Evaluating Your Learning to Rank Model: Dos and Don’ts in Offline/Online Eval...
Sease
 
C++ tutorial assignment - 23MTS5730.pptx
C++ tutorial assignment  - 23MTS5730.pptxC++ tutorial assignment  - 23MTS5730.pptx
C++ tutorial assignment - 23MTS5730.pptx
sp1312004
 
Intro-OOP-PPT- an introduction to the su
Intro-OOP-PPT- an introduction to the suIntro-OOP-PPT- an introduction to the su
Intro-OOP-PPT- an introduction to the su
ImranAliQureshi3
 
OOP PPT 1.pptx
OOP PPT 1.pptxOOP PPT 1.pptx
OOP PPT 1.pptx
lathass5
 
Chapter 2 OOP using C++ (Introduction).pptx
Chapter 2 OOP using C++ (Introduction).pptxChapter 2 OOP using C++ (Introduction).pptx
Chapter 2 OOP using C++ (Introduction).pptx
FiraolGadissa
 
C++ Interview Questions and Answers PDF By ScholarHat
C++ Interview Questions and Answers PDF By ScholarHatC++ Interview Questions and Answers PDF By ScholarHat
C++ Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Classes in C++ computer language presentation.ppt
Classes in C++ computer language presentation.pptClasses in C++ computer language presentation.ppt
Classes in C++ computer language presentation.ppt
AjayLobo1
 
OOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming languageOOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming language
PreethaV16
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
Mayank Jain
 
C++ Classes Tutorials.ppt
C++ Classes Tutorials.pptC++ Classes Tutorials.ppt
C++ Classes Tutorials.ppt
aasuran
 

More from VGaneshKarthikeyan (20)

1.3 Basic coding skills_fundamentals .ppt
1.3 Basic coding skills_fundamentals .ppt1.3 Basic coding skills_fundamentals .ppt
1.3 Basic coding skills_fundamentals .ppt
VGaneshKarthikeyan
 
5_Model for Predictions_Machine_Learning.ppt
5_Model for Predictions_Machine_Learning.ppt5_Model for Predictions_Machine_Learning.ppt
5_Model for Predictions_Machine_Learning.ppt
VGaneshKarthikeyan
 
2_Errors in Experimental Observations_ML.ppt
2_Errors in Experimental Observations_ML.ppt2_Errors in Experimental Observations_ML.ppt
2_Errors in Experimental Observations_ML.ppt
VGaneshKarthikeyan
 
FINAL_DAY11_INTERFACES_Roles_and_Responsibility.pdf
FINAL_DAY11_INTERFACES_Roles_and_Responsibility.pdfFINAL_DAY11_INTERFACES_Roles_and_Responsibility.pdf
FINAL_DAY11_INTERFACES_Roles_and_Responsibility.pdf
VGaneshKarthikeyan
 
FINAL_DAY10_INTERFACES_roles and benefits.pptx
FINAL_DAY10_INTERFACES_roles and benefits.pptxFINAL_DAY10_INTERFACES_roles and benefits.pptx
FINAL_DAY10_INTERFACES_roles and benefits.pptx
VGaneshKarthikeyan
 
FINAL_DAY8_VISIBILITY_LABELS_Roles and.pptx
FINAL_DAY8_VISIBILITY_LABELS_Roles and.pptxFINAL_DAY8_VISIBILITY_LABELS_Roles and.pptx
FINAL_DAY8_VISIBILITY_LABELS_Roles and.pptx
VGaneshKarthikeyan
 
FINAL_DAY9_METHOD_OVERRIDING_Role and benefits .pptx
FINAL_DAY9_METHOD_OVERRIDING_Role and benefits .pptxFINAL_DAY9_METHOD_OVERRIDING_Role and benefits .pptx
FINAL_DAY9_METHOD_OVERRIDING_Role and benefits .pptx
VGaneshKarthikeyan
 
JAVA_BASICS_Data_abstraction_encapsulation.ppt
JAVA_BASICS_Data_abstraction_encapsulation.pptJAVA_BASICS_Data_abstraction_encapsulation.ppt
JAVA_BASICS_Data_abstraction_encapsulation.ppt
VGaneshKarthikeyan
 
Java ppt-class_Introduction_class_Objects.ppt
Java ppt-class_Introduction_class_Objects.pptJava ppt-class_Introduction_class_Objects.ppt
Java ppt-class_Introduction_class_Objects.ppt
VGaneshKarthikeyan
 
INT104 DBMS - Introduction_Atomicity.ppt
INT104 DBMS - Introduction_Atomicity.pptINT104 DBMS - Introduction_Atomicity.ppt
INT104 DBMS - Introduction_Atomicity.ppt
VGaneshKarthikeyan
 
Operators_in_C++_advantages_applications.ppt
Operators_in_C++_advantages_applications.pptOperators_in_C++_advantages_applications.ppt
Operators_in_C++_advantages_applications.ppt
VGaneshKarthikeyan
 
1_Standard error Experimental Data_ML.ppt
1_Standard error Experimental Data_ML.ppt1_Standard error Experimental Data_ML.ppt
1_Standard error Experimental Data_ML.ppt
VGaneshKarthikeyan
 
Unit III Part I_Opertaor_Overloading.pptx
Unit III Part I_Opertaor_Overloading.pptxUnit III Part I_Opertaor_Overloading.pptx
Unit III Part I_Opertaor_Overloading.pptx
VGaneshKarthikeyan
 
Linear_discriminat_analysis_in_Machine_Learning.pptx
Linear_discriminat_analysis_in_Machine_Learning.pptxLinear_discriminat_analysis_in_Machine_Learning.pptx
Linear_discriminat_analysis_in_Machine_Learning.pptx
VGaneshKarthikeyan
 
K-Mean clustering_Introduction_Applications.pptx
K-Mean clustering_Introduction_Applications.pptxK-Mean clustering_Introduction_Applications.pptx
K-Mean clustering_Introduction_Applications.pptx
VGaneshKarthikeyan
 
Numpy_defintion_description_usage_examples.pptx
Numpy_defintion_description_usage_examples.pptxNumpy_defintion_description_usage_examples.pptx
Numpy_defintion_description_usage_examples.pptx
VGaneshKarthikeyan
 
Refined_Lecture-14-Linear Algebra-Review.ppt
Refined_Lecture-14-Linear Algebra-Review.pptRefined_Lecture-14-Linear Algebra-Review.ppt
Refined_Lecture-14-Linear Algebra-Review.ppt
VGaneshKarthikeyan
 
randomwalks_states_figures_events_happenings.ppt
randomwalks_states_figures_events_happenings.pptrandomwalks_states_figures_events_happenings.ppt
randomwalks_states_figures_events_happenings.ppt
VGaneshKarthikeyan
 
stochasticmodellinganditsapplications.ppt
stochasticmodellinganditsapplications.pptstochasticmodellinganditsapplications.ppt
stochasticmodellinganditsapplications.ppt
VGaneshKarthikeyan
 
1.10 Tuples_sets_usage_applications_advantages.pptx
1.10 Tuples_sets_usage_applications_advantages.pptx1.10 Tuples_sets_usage_applications_advantages.pptx
1.10 Tuples_sets_usage_applications_advantages.pptx
VGaneshKarthikeyan
 
1.3 Basic coding skills_fundamentals .ppt
1.3 Basic coding skills_fundamentals .ppt1.3 Basic coding skills_fundamentals .ppt
1.3 Basic coding skills_fundamentals .ppt
VGaneshKarthikeyan
 
5_Model for Predictions_Machine_Learning.ppt
5_Model for Predictions_Machine_Learning.ppt5_Model for Predictions_Machine_Learning.ppt
5_Model for Predictions_Machine_Learning.ppt
VGaneshKarthikeyan
 
2_Errors in Experimental Observations_ML.ppt
2_Errors in Experimental Observations_ML.ppt2_Errors in Experimental Observations_ML.ppt
2_Errors in Experimental Observations_ML.ppt
VGaneshKarthikeyan
 
FINAL_DAY11_INTERFACES_Roles_and_Responsibility.pdf
FINAL_DAY11_INTERFACES_Roles_and_Responsibility.pdfFINAL_DAY11_INTERFACES_Roles_and_Responsibility.pdf
FINAL_DAY11_INTERFACES_Roles_and_Responsibility.pdf
VGaneshKarthikeyan
 
FINAL_DAY10_INTERFACES_roles and benefits.pptx
FINAL_DAY10_INTERFACES_roles and benefits.pptxFINAL_DAY10_INTERFACES_roles and benefits.pptx
FINAL_DAY10_INTERFACES_roles and benefits.pptx
VGaneshKarthikeyan
 
FINAL_DAY8_VISIBILITY_LABELS_Roles and.pptx
FINAL_DAY8_VISIBILITY_LABELS_Roles and.pptxFINAL_DAY8_VISIBILITY_LABELS_Roles and.pptx
FINAL_DAY8_VISIBILITY_LABELS_Roles and.pptx
VGaneshKarthikeyan
 
FINAL_DAY9_METHOD_OVERRIDING_Role and benefits .pptx
FINAL_DAY9_METHOD_OVERRIDING_Role and benefits .pptxFINAL_DAY9_METHOD_OVERRIDING_Role and benefits .pptx
FINAL_DAY9_METHOD_OVERRIDING_Role and benefits .pptx
VGaneshKarthikeyan
 
JAVA_BASICS_Data_abstraction_encapsulation.ppt
JAVA_BASICS_Data_abstraction_encapsulation.pptJAVA_BASICS_Data_abstraction_encapsulation.ppt
JAVA_BASICS_Data_abstraction_encapsulation.ppt
VGaneshKarthikeyan
 
Java ppt-class_Introduction_class_Objects.ppt
Java ppt-class_Introduction_class_Objects.pptJava ppt-class_Introduction_class_Objects.ppt
Java ppt-class_Introduction_class_Objects.ppt
VGaneshKarthikeyan
 
INT104 DBMS - Introduction_Atomicity.ppt
INT104 DBMS - Introduction_Atomicity.pptINT104 DBMS - Introduction_Atomicity.ppt
INT104 DBMS - Introduction_Atomicity.ppt
VGaneshKarthikeyan
 
Operators_in_C++_advantages_applications.ppt
Operators_in_C++_advantages_applications.pptOperators_in_C++_advantages_applications.ppt
Operators_in_C++_advantages_applications.ppt
VGaneshKarthikeyan
 
1_Standard error Experimental Data_ML.ppt
1_Standard error Experimental Data_ML.ppt1_Standard error Experimental Data_ML.ppt
1_Standard error Experimental Data_ML.ppt
VGaneshKarthikeyan
 
Unit III Part I_Opertaor_Overloading.pptx
Unit III Part I_Opertaor_Overloading.pptxUnit III Part I_Opertaor_Overloading.pptx
Unit III Part I_Opertaor_Overloading.pptx
VGaneshKarthikeyan
 
Linear_discriminat_analysis_in_Machine_Learning.pptx
Linear_discriminat_analysis_in_Machine_Learning.pptxLinear_discriminat_analysis_in_Machine_Learning.pptx
Linear_discriminat_analysis_in_Machine_Learning.pptx
VGaneshKarthikeyan
 
K-Mean clustering_Introduction_Applications.pptx
K-Mean clustering_Introduction_Applications.pptxK-Mean clustering_Introduction_Applications.pptx
K-Mean clustering_Introduction_Applications.pptx
VGaneshKarthikeyan
 
Numpy_defintion_description_usage_examples.pptx
Numpy_defintion_description_usage_examples.pptxNumpy_defintion_description_usage_examples.pptx
Numpy_defintion_description_usage_examples.pptx
VGaneshKarthikeyan
 
Refined_Lecture-14-Linear Algebra-Review.ppt
Refined_Lecture-14-Linear Algebra-Review.pptRefined_Lecture-14-Linear Algebra-Review.ppt
Refined_Lecture-14-Linear Algebra-Review.ppt
VGaneshKarthikeyan
 
randomwalks_states_figures_events_happenings.ppt
randomwalks_states_figures_events_happenings.pptrandomwalks_states_figures_events_happenings.ppt
randomwalks_states_figures_events_happenings.ppt
VGaneshKarthikeyan
 
stochasticmodellinganditsapplications.ppt
stochasticmodellinganditsapplications.pptstochasticmodellinganditsapplications.ppt
stochasticmodellinganditsapplications.ppt
VGaneshKarthikeyan
 
1.10 Tuples_sets_usage_applications_advantages.pptx
1.10 Tuples_sets_usage_applications_advantages.pptx1.10 Tuples_sets_usage_applications_advantages.pptx
1.10 Tuples_sets_usage_applications_advantages.pptx
VGaneshKarthikeyan
 
Ad

Recently uploaded (20)

DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)
rccbatchplant
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.
anuragmk56
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)
samueljackson3773
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Journal of Soft Computing in Civil Engineering
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)
rccbatchplant
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.
anuragmk56
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)
samueljackson3773
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Ad

6. Implementation of classes_and_its_advantages.pdf

  • 1. CSE201 Unit – II Implementation of classes 25-03-2023 Ref. "Object-Oriented Programming in C++" by Robert Lafore
  • 2. Object-Oriented Approach 25-03-2023 2 Ref. "Object-Oriented Programming in C++" by Robert Lafore Data Functions that operate on data Object
  • 3. Object-Oriented Approach 25-03-2023 3 Ref. "Object-Oriented Programming in C++" by Robert Lafore Roll_no M1,M2,M3 calTotal() student
  • 4. Object-Oriented Approach 25-03-2023 4 Ref. "Object-Oriented Programming in C++" by Robert Lafore Data Functions that operate on data Object An object’s functions, called member functions in C++, typically provide the only way to access its data
  • 5. Object-Oriented Approach 25-03-2023 5 Ref. "Object-Oriented Programming in C++" by Robert Lafore Data Member Functions Object - 1 member functions or methods Attributes or instance variables
  • 6. Classes • In OOP, Objects are instances of classes 25-03-2023 6 Ref. "Object-Oriented Programming in C++" by Robert Lafore Class Attributes Member functions Object-1 Attributes Member functions Object-2 Attributes Member functions Object-1 & 2 are of type class
  • 7. Implementation of classes 25-03-2023 7 Ref. "Object-Oriented Programming in C++" by Robert Lafore class firstClass { int a,b; int add(int x, int y) { a=x; b=y; return (a+b); } }; Class Attributes Member functions
  • 8. Object-Oriented Approach 25-03-2023 8 Ref. "Object-Oriented Programming in C++" by Robert Lafore Data Member Functions Object - 1 Data is hidden So, its safe from accidental alteration – DATA HIDING
  • 9. Implementation of classes 25-03-2023 9 Ref. "Object-Oriented Programming in C++" by Robert Lafore class firstClass { int a,b; // should be accessed by member function only int add(int x, int y) // can be accessed by main () { a=x; b=y; return (a+b); } }; Set rights or give the access specifications using “Access Specifier”
  • 10. Implementation of classes 25-03-2023 10 Ref. "Object-Oriented Programming in C++" by Robert Lafore class firstClass { private: // access specifier int a,b; public: // access specifier int add(int x, int y) { a=x; b=y; return (a+b); } }; Class is ready!!
  • 11. Implementation of classes 25-03-2023 11 Ref. "Object-Oriented Programming in C++" by Robert Lafore class firstClass { private: // access specifier int a,b; public: // access specifier int add(int x, int y) { a=x; b=y; return (a+b); } }; int main() { firstClass obj; //declaring an obj int sum; sum=obj.add(5,6); //msg passing cout<<“Sum =”<<sum; }
  • 12. Implementation of classes 25-03-2023 12 Ref. "Object-Oriented Programming in C++" by Robert Lafore class firstClass { private: // access specifier int a,b; public: // access specifier int add(int x, int y) { a=x; b=y; return (a+b); } }; int main() { firstClass obj; //declaring an obj int x, y, sum; cout<<“Enter values for x and y:”; cin>>x>>y; sum=obj.add(x,y); //msg passing cout<<“Sum =”<<sum; }
  • 13. Classes 25-03-2023 13 Ref. "Object-Oriented Programming in C++" by Robert Lafore • Class Data: The data items within a class are called data members (or sometimes member data). • Member Functions: Member functions are functions that are included within a class. • int add(int x, int y); • Defining class: Defining objects in this way means creating them. This is also called instantiating them. • firstClass obj; • The term instantiating arises because an instance of the class is created. An object is an instance of a class. • Objects are sometimes called instance variables.
  • 14. Classes 25-03-2023 14 Ref. "Object-Oriented Programming in C++" by Robert Lafore • Calling member function: The data items within a class are called data members (or sometimes member data). • obj.add(x, y); - The dot operator is also called the class member access operator.)
  • 15. Implementation of classes 25-03-2023 15 Ref. "Object-Oriented Programming in C++" by Robert Lafore #include <iostream> using namespace std; class Distance { private: int feet; float inches; public: void setdist(int ft, float in) { feet = ft; inches = in; } void getdist() { cout << “nEnter feet: “; cin >> feet; cout << “Enter inches: “; cin >> inches; } void showdist() //display distance { cout << feet << “’-” << inches << ‘”’; } }; int main() { Distance dist1, dist2; dist1.setdist(11, 6.25); dist2.getdist(); cout << “ndist1 = “; dist1.showdist(); cout << “ndist2 = “; dist2.showdist(); cout << endl; return 0; }
  • 16. More On Classes and Objects 25-03-2023 16 Ref. "Object-Oriented Programming in C++" by Robert Lafore
  • 23. 23 Dr. J. Sangeetha/CSE/SRC/SASTRA Method : 1 – Defining member function inside the class – By default inline
  • 24. Ex : 2 Dr. J. Sangeetha/CSE/SRC/SASTRA 24
  • 26. Ex : 3 Dr. J. Sangeetha/CSE/SRC/SASTRA 26
  • 28. Ex: 4 Dr. J. Sangeetha/CSE/SRC/SASTRA 28
  • 30. Method 2 : Member function definition outside the class Dr. J. Sangeetha/CSE/SRC/SASTRA 30
  • 32. Difference between Classes and Structures • In C++, a structure works the same way as a class, except for just two small differences. The most important of them is hiding implementation details. • A structure will by default not hide its implementation details from whoever uses it in code, while a class by default hides all its implementation details and will therefore by default prevent the programmer from accessing them. • The following table summarizes all of the fundamental differences. 25-03-2023 32 Ref. "Object-Oriented Programming in C++" by Robert Lafore
  • 33. 25-03-2023 33 Ref. "Object-Oriented Programming in C++" by Robert Lafore
  • 34. 25-03-2023 34 Ref. "Object-Oriented Programming in C++" by Robert Lafore
  • 35. Example – Employee details 25-03-2023 35 Ref. "Object-Oriented Programming in C++" by Robert Lafore
  • 36. 25-03-2023 36 Ref. "Object-Oriented Programming in C++" by Robert Lafore
  • 37. 25-03-2023 37 Ref. "Object-Oriented Programming in C++" by Robert Lafore
  • 38. Example: Student details 25-03-2023 38 Ref. "Object-Oriented Programming in C++" by Robert Lafore
  • 39. 25-03-2023 39 Ref. "Object-Oriented Programming in C++" by Robert Lafore
  • 40. Reference • Robert Lafore. Object oriented programming in C++, Pearson Education, Fourth Edition, 2012. 25-03-2023 40