SlideShare a Scribd company logo
Tutorial 5
Classes and Objects
Self Review Questions
1. What are classes? How does it help in data hiding?
2. How structures in c are different from structures in C++?
3. What do you mean by visibility labels?
4. Differentiate between
a. Classes and Structures
b. Class and Object
c. Member Function and Non Member Function
d. Member function and Friend function
5. How memory is allocated to Objects and static data members?
6. Give an example to illustrate the use array of objects.
7. Illustrate the use of scope resolution operator as class scope operator.
Programming Questions
1. Write a class to represent a vector (a series of float values). Include member functions
to perform the following tasks:
(a) To create the vector
(b) To modify the value of a given element
(c) To multiply by a scalar value
(d) To display the vector in the form (10, 20, 30.....)
Write a program to test your class.
2. Create two classes DM and DB which store the value of distances. DM stores distances in
metres and centimetres and DB in feet and inches. Write a program that can read values
for the class objects and add one object of DM with another object of DB.
Use a friend function to carry out the addition operation. The object that stores the results
may be a DM object or DB object, depending on the units in which the results are
required. The display should be in the format of feet and inches or metres and centimetres
depending on the object on display.

More Related Content

Viewers also liked

Walking Crew Poster(1)
Walking Crew Poster(1)Walking Crew Poster(1)
Walking Crew Poster(1)
Danita S. Mason, MBA
 
Dr. Russell A. Barkley - Dedicated to Education and Research on ADHD
Dr. Russell A. Barkley - Dedicated to Education and Research on ADHDDr. Russell A. Barkley - Dedicated to Education and Research on ADHD
Dr. Russell A. Barkley - Dedicated to Education and Research on ADHD
jollymedal7131
 
Current RESUME
Current RESUMECurrent RESUME
Current RESUME
Paula Burton
 
Health is Wealth
Health is WealthHealth is Wealth
Health is Wealth
Christopher Blueman
 
인천휴게텔≪다솜넷≫수원오피≪수유건마,천안오피방
인천휴게텔≪다솜넷≫수원오피≪수유건마,천안오피방인천휴게텔≪다솜넷≫수원오피≪수유건마,천안오피방
인천휴게텔≪다솜넷≫수원오피≪수유건마,천안오피방
dasom49
 
Plantilla doris y monik modificada
Plantilla doris y monik modificadaPlantilla doris y monik modificada
Plantilla doris y monik modificada
lina vanessa nunez
 

Viewers also liked (8)

Walking Crew Poster(1)
Walking Crew Poster(1)Walking Crew Poster(1)
Walking Crew Poster(1)
 
Dr. Russell A. Barkley - Dedicated to Education and Research on ADHD
Dr. Russell A. Barkley - Dedicated to Education and Research on ADHDDr. Russell A. Barkley - Dedicated to Education and Research on ADHD
Dr. Russell A. Barkley - Dedicated to Education and Research on ADHD
 
Current RESUME
Current RESUMECurrent RESUME
Current RESUME
 
Die schiesstrainerin folder-web
Die schiesstrainerin folder-webDie schiesstrainerin folder-web
Die schiesstrainerin folder-web
 
Health is Wealth
Health is WealthHealth is Wealth
Health is Wealth
 
인천휴게텔≪다솜넷≫수원오피≪수유건마,천안오피방
인천휴게텔≪다솜넷≫수원오피≪수유건마,천안오피방인천휴게텔≪다솜넷≫수원오피≪수유건마,천안오피방
인천휴게텔≪다솜넷≫수원오피≪수유건마,천안오피방
 
Plantilla doris y monik modificada
Plantilla doris y monik modificadaPlantilla doris y monik modificada
Plantilla doris y monik modificada
 
Letter
LetterLetter
Letter
 

Similar to Tutorial 5 classes 1

Ooad quiz
Ooad quizOoad quiz
cprogramming questions for practice end term
cprogramming questions for practice end termcprogramming questions for practice end term
cprogramming questions for practice end term
Sheelendra3
 
Oops 2018
Oops 2018Oops 2018
OOM MCQ 2018
OOM  MCQ 2018OOM  MCQ 2018
OOM MCQ 2018
lochan100
 
Oop suplemnertary september 2019
Oop suplemnertary september  2019Oop suplemnertary september  2019
Oop suplemnertary september 2019
ktuonlinenotes
 
S2 DATA PROCESSING FIRST TERM C.A 2
S2 DATA PROCESSING FIRST TERM C.A 2S2 DATA PROCESSING FIRST TERM C.A 2
S2 DATA PROCESSING FIRST TERM C.A 2
Ejiro Ndifereke
 
C++ Unit_01
C++ Unit_01C++ Unit_01
Oop r&s may 2019
Oop r&s may 2019Oop r&s may 2019
Oop r&s may 2019
ktuonlinenotes
 
Mit4021–%20 c# and .net
Mit4021–%20 c# and .netMit4021–%20 c# and .net
Mit4021–%20 c# and .net
smumbahelp
 
Oop r&s may 2019 (2)
Oop r&s may 2019 (2)Oop r&s may 2019 (2)
Oop r&s may 2019 (2)
ktuonlinenotes
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
sandeep54552
 
COMP111-Week-1_138439.pptx
COMP111-Week-1_138439.pptxCOMP111-Week-1_138439.pptx
COMP111-Week-1_138439.pptx
FarooqTariq8
 
Bca winter 2013 2nd sem
Bca winter 2013 2nd semBca winter 2013 2nd sem
Bca winter 2013 2nd sem
smumbahelp
 
oop lecture 3
oop lecture 3oop lecture 3
oop lecture 3
Atif Khan
 
CS8592 Object Oriented Analysis & Design - UNIT II
CS8592 Object Oriented Analysis & Design - UNIT IICS8592 Object Oriented Analysis & Design - UNIT II
CS8592 Object Oriented Analysis & Design - UNIT II
pkaviya
 
Class diagram
Class diagramClass diagram
2009 Punjab Technical University B.C.A Object Oriented Proagramming Language ...
2009 Punjab Technical University B.C.A Object Oriented Proagramming Language ...2009 Punjab Technical University B.C.A Object Oriented Proagramming Language ...
2009 Punjab Technical University B.C.A Object Oriented Proagramming Language ...
Monica Sabharwal
 
Unit 5.ppt
Unit 5.pptUnit 5.ppt
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented Design
Sudarsun Santhiappan
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented Design
Aravinth NSP
 

Similar to Tutorial 5 classes 1 (20)

Ooad quiz
Ooad quizOoad quiz
Ooad quiz
 
cprogramming questions for practice end term
cprogramming questions for practice end termcprogramming questions for practice end term
cprogramming questions for practice end term
 
Oops 2018
Oops 2018Oops 2018
Oops 2018
 
OOM MCQ 2018
OOM  MCQ 2018OOM  MCQ 2018
OOM MCQ 2018
 
Oop suplemnertary september 2019
Oop suplemnertary september  2019Oop suplemnertary september  2019
Oop suplemnertary september 2019
 
S2 DATA PROCESSING FIRST TERM C.A 2
S2 DATA PROCESSING FIRST TERM C.A 2S2 DATA PROCESSING FIRST TERM C.A 2
S2 DATA PROCESSING FIRST TERM C.A 2
 
C++ Unit_01
C++ Unit_01C++ Unit_01
C++ Unit_01
 
Oop r&s may 2019
Oop r&s may 2019Oop r&s may 2019
Oop r&s may 2019
 
Mit4021–%20 c# and .net
Mit4021–%20 c# and .netMit4021–%20 c# and .net
Mit4021–%20 c# and .net
 
Oop r&s may 2019 (2)
Oop r&s may 2019 (2)Oop r&s may 2019 (2)
Oop r&s may 2019 (2)
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
 
COMP111-Week-1_138439.pptx
COMP111-Week-1_138439.pptxCOMP111-Week-1_138439.pptx
COMP111-Week-1_138439.pptx
 
Bca winter 2013 2nd sem
Bca winter 2013 2nd semBca winter 2013 2nd sem
Bca winter 2013 2nd sem
 
oop lecture 3
oop lecture 3oop lecture 3
oop lecture 3
 
CS8592 Object Oriented Analysis & Design - UNIT II
CS8592 Object Oriented Analysis & Design - UNIT IICS8592 Object Oriented Analysis & Design - UNIT II
CS8592 Object Oriented Analysis & Design - UNIT II
 
Class diagram
Class diagramClass diagram
Class diagram
 
2009 Punjab Technical University B.C.A Object Oriented Proagramming Language ...
2009 Punjab Technical University B.C.A Object Oriented Proagramming Language ...2009 Punjab Technical University B.C.A Object Oriented Proagramming Language ...
2009 Punjab Technical University B.C.A Object Oriented Proagramming Language ...
 
Unit 5.ppt
Unit 5.pptUnit 5.ppt
Unit 5.ppt
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented Design
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented Design
 

Recently uploaded

CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
PKavitha10
 
Welding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdfWelding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdf
AjmalKhan50578
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
Mahmoud Morsy
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
21UME003TUSHARDEB
 
Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...
bijceesjournal
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
Nada Hikmah
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
shadow0702a
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
GauravCar
 
People as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimalaPeople as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimala
riddhimaagrawal986
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
gowrishankartb2005
 
Seminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptxSeminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptx
Madan Karki
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
UReason
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURSCompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
RamonNovais6
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
Divyanshu
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
ElakkiaU
 

Recently uploaded (20)

CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
 
Welding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdfWelding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdf
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
 
Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
 
People as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimalaPeople as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimala
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
 
Seminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptxSeminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptx
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURSCompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
 

Tutorial 5 classes 1

  • 1. Tutorial 5 Classes and Objects Self Review Questions 1. What are classes? How does it help in data hiding? 2. How structures in c are different from structures in C++? 3. What do you mean by visibility labels? 4. Differentiate between a. Classes and Structures b. Class and Object c. Member Function and Non Member Function d. Member function and Friend function 5. How memory is allocated to Objects and static data members? 6. Give an example to illustrate the use array of objects. 7. Illustrate the use of scope resolution operator as class scope operator. Programming Questions 1. Write a class to represent a vector (a series of float values). Include member functions to perform the following tasks: (a) To create the vector (b) To modify the value of a given element (c) To multiply by a scalar value (d) To display the vector in the form (10, 20, 30.....) Write a program to test your class. 2. Create two classes DM and DB which store the value of distances. DM stores distances in metres and centimetres and DB in feet and inches. Write a program that can read values for the class objects and add one object of DM with another object of DB. Use a friend function to carry out the addition operation. The object that stores the results may be a DM object or DB object, depending on the units in which the results are required. The display should be in the format of feet and inches or metres and centimetres depending on the object on display.