SlideShare a Scribd company logo
1 of 2
i
Encapsulation} ra te compilation is to achieve encapsulation. How to separate files? Give two An
important objective advantages of doing so o.
Solution
Separate Files in C++:
1. Place prototypes and definitions in a module.h file
2. Place the actual code in module.cpp
3. #include "module.h" in the program(separate file) that uses the module
4. Make all files part of a project
5. Include the module
Convention:
.h file contains class header
.cpp file contains member function definitions
Separate Compilation Example 1
1. factorial.h:
– Contains the line int factorial( int num );
2. factorial.cpp:
– Contains the function definition:
int factorial( int num ) { … }
3. someapplication.cpp:
– Contains the line #include "factorial.h"
– Contains the main() function that invokes the factorial function
Advantage:
1. A minor change requires recompilation of the entire program.
2. Reusing part of the program, a class for example, in another program requires a risky copy and
paste operation.
The class declaration, all member function implementations, and all other dependencies must be
located, copied (don't press the cut button!), and pasted into another file.
3. Several programmers can't work on the program simultaneously.

More Related Content

Similar to i Encapsulation} ra te compilation is to achieve encapsulation- How to.docx

Introduction to Computer and Programing - Lab2
Introduction to Computer and Programing - Lab2Introduction to Computer and Programing - Lab2
Introduction to Computer and Programing - Lab2
hassaanciit
 

Similar to i Encapsulation} ra te compilation is to achieve encapsulation- How to.docx (20)

Presentation1.pptx
Presentation1.pptxPresentation1.pptx
Presentation1.pptx
 
CHAPTER 3
CHAPTER 3CHAPTER 3
CHAPTER 3
 
Workshop1
Workshop1Workshop1
Workshop1
 
Functions_in_Python.pptx
Functions_in_Python.pptxFunctions_in_Python.pptx
Functions_in_Python.pptx
 
6 preprocessor macro header
6 preprocessor macro header6 preprocessor macro header
6 preprocessor macro header
 
Introduction to Computer and Programing - Lab2
Introduction to Computer and Programing - Lab2Introduction to Computer and Programing - Lab2
Introduction to Computer and Programing - Lab2
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptx
 
Using Python Libraries.pdf
Using Python Libraries.pdfUsing Python Libraries.pdf
Using Python Libraries.pdf
 
Chtp415
Chtp415Chtp415
Chtp415
 
Introduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to itIntroduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to it
 
Vc++
Vc++Vc++
Vc++
 
Chapter - 4.pptx
Chapter - 4.pptxChapter - 4.pptx
Chapter - 4.pptx
 
Python Programming - Functions and Modules
Python Programming - Functions and ModulesPython Programming - Functions and Modules
Python Programming - Functions and Modules
 
Unit 2 l1
Unit 2 l1Unit 2 l1
Unit 2 l1
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptx
 
C++Basics2022.pptx
C++Basics2022.pptxC++Basics2022.pptx
C++Basics2022.pptx
 
C PROGRAMMING p-2.pdf
C PROGRAMMING p-2.pdfC PROGRAMMING p-2.pdf
C PROGRAMMING p-2.pdf
 
Data structure week 1
Data structure week 1Data structure week 1
Data structure week 1
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Python Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptxPython Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptx
 

More from cwayne3

How would you describe the macroeconomic --worldview-- of David Ricard.docx
How would you describe the macroeconomic --worldview-- of David Ricard.docxHow would you describe the macroeconomic --worldview-- of David Ricard.docx
How would you describe the macroeconomic --worldview-- of David Ricard.docx
cwayne3
 
10) Which species acts as the nucleophile in the reaction of 1-butene.docx
10) Which species acts as the nucleophile in the reaction of 1-butene.docx10) Which species acts as the nucleophile in the reaction of 1-butene.docx
10) Which species acts as the nucleophile in the reaction of 1-butene.docx
cwayne3
 
1-) What are the tax concepts involved in completing the Form 1040- Ex.docx
1-) What are the tax concepts involved in completing the Form 1040- Ex.docx1-) What are the tax concepts involved in completing the Form 1040- Ex.docx
1-) What are the tax concepts involved in completing the Form 1040- Ex.docx
cwayne3
 
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx
cwayne3
 

More from cwayne3 (15)

I am trying to create a code that will show an error if someone puts a.docx
I am trying to create a code that will show an error if someone puts a.docxI am trying to create a code that will show an error if someone puts a.docx
I am trying to create a code that will show an error if someone puts a.docx
 
I need a short code that is ritten in Visual basic that explains that.docx
I need a short code that is ritten in Visual basic that explains that.docxI need a short code that is ritten in Visual basic that explains that.docx
I need a short code that is ritten in Visual basic that explains that.docx
 
How would you characterize Web 2-0- Describe the set of technologies t.docx
How would you characterize Web 2-0- Describe the set of technologies t.docxHow would you characterize Web 2-0- Describe the set of technologies t.docx
How would you characterize Web 2-0- Describe the set of technologies t.docx
 
How would you describe the macroeconomic --worldview-- of David Ricard.docx
How would you describe the macroeconomic --worldview-- of David Ricard.docxHow would you describe the macroeconomic --worldview-- of David Ricard.docx
How would you describe the macroeconomic --worldview-- of David Ricard.docx
 
1-Put the ionic compounds in order of smallest to largest lattice ener.docx
1-Put the ionic compounds in order of smallest to largest lattice ener.docx1-Put the ionic compounds in order of smallest to largest lattice ener.docx
1-Put the ionic compounds in order of smallest to largest lattice ener.docx
 
10- which of the following should be the first step in reviewing he fi.docx
10- which of the following should be the first step in reviewing he fi.docx10- which of the following should be the first step in reviewing he fi.docx
10- which of the following should be the first step in reviewing he fi.docx
 
1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docx
1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docx1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docx
1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docx
 
10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docx
10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docx10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docx
10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docx
 
10) Which species acts as the nucleophile in the reaction of 1-butene.docx
10) Which species acts as the nucleophile in the reaction of 1-butene.docx10) Which species acts as the nucleophile in the reaction of 1-butene.docx
10) Which species acts as the nucleophile in the reaction of 1-butene.docx
 
1-) What are the tax concepts involved in completing the Form 1040- Ex.docx
1-) What are the tax concepts involved in completing the Form 1040- Ex.docx1-) What are the tax concepts involved in completing the Form 1040- Ex.docx
1-) What are the tax concepts involved in completing the Form 1040- Ex.docx
 
1-) Which of the following accounting concepts do accountants and audi.docx
1-) Which of the following accounting concepts do accountants and audi.docx1-) Which of the following accounting concepts do accountants and audi.docx
1-) Which of the following accounting concepts do accountants and audi.docx
 
1- Why does the initially formed copper hydroxide precipitate dissolve.docx
1- Why does the initially formed copper hydroxide precipitate dissolve.docx1- Why does the initially formed copper hydroxide precipitate dissolve.docx
1- Why does the initially formed copper hydroxide precipitate dissolve.docx
 
1- Which substance CANNOT have dipole-dipole forces between its molecu.docx
1- Which substance CANNOT have dipole-dipole forces between its molecu.docx1- Which substance CANNOT have dipole-dipole forces between its molecu.docx
1- Which substance CANNOT have dipole-dipole forces between its molecu.docx
 
1-Write an algebraic expression to represent each verbal expression-.docx
1-Write an algebraic expression to represent each verbal expression-.docx1-Write an algebraic expression to represent each verbal expression-.docx
1-Write an algebraic expression to represent each verbal expression-.docx
 
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Recently uploaded (20)

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 

i Encapsulation} ra te compilation is to achieve encapsulation- How to.docx

  • 1. i Encapsulation} ra te compilation is to achieve encapsulation. How to separate files? Give two An important objective advantages of doing so o. Solution Separate Files in C++: 1. Place prototypes and definitions in a module.h file 2. Place the actual code in module.cpp 3. #include "module.h" in the program(separate file) that uses the module 4. Make all files part of a project 5. Include the module Convention: .h file contains class header .cpp file contains member function definitions Separate Compilation Example 1 1. factorial.h: – Contains the line int factorial( int num ); 2. factorial.cpp: – Contains the function definition: int factorial( int num ) { … } 3. someapplication.cpp: – Contains the line #include "factorial.h" – Contains the main() function that invokes the factorial function Advantage: 1. A minor change requires recompilation of the entire program. 2. Reusing part of the program, a class for example, in another program requires a risky copy and paste operation. The class declaration, all member function implementations, and all other dependencies must be
  • 2. located, copied (don't press the cut button!), and pasted into another file. 3. Several programmers can't work on the program simultaneously.