Download presentation
Presentation is loading. Please wait.
Published byMarjorie Ramsey Modified over 9 years ago
1
http://cs.mst.edu Multiple Files
2
http://cs.mst.edu Monolithic vs Modular one file before system includes main driver function prototypes function definitions multiple files now main driver file prototypes header file(s) functions definition implementation source file(s)
3
http://cs.mst.edu #include using namespace std; int main() { greetings(); return 0; } void greetings() { cout << "Hello world!" << endl; return; } #ifndef GREET_H #define GREET_H #include using namespace std; #endif greet.h main.cpp void greetings();
4
http://cs.mst.edu #include #include “greet.h” using namespace std; int main() { greetings(); return 0; } #ifndef GREET_H #define GREET_H #include using namespace std; void greetings(); #endif greet.h main.cpp #include "greet.h" greet.cpp void greetings() { cout << "Hello world!" << endl; return; }
5
http://cs.mst.edu #include #include “greet.h” using namespace std; int main() { greetings(); return 0; } #ifndef GREET_H #define GREET_H #include using namespace std; void greetings(); #endif greet.h main.cpp #include "greet.h" void greetings() { cout << "Hello world!" << endl; return; } greet.cpp
6
http://cs.mst.edu Main File comment header system and user includes namespace declaration main function // Author: Clayton Price // File: main.cpp // This file drives the greet // function. #include "greet.h" #include using namespace std; int main() { greetings(); cout << “Good bye” << endl; return 0; } main.cpp
7
http://cs.mst.edu Main File comment header system and user includes namespace declaration main function // Author: Clayton Price // File: main.cpp // This file drives the greet // function. #include "greet.h" #include using namespace std; int main() { greetings(); cout << “Good bye” << endl; return 0; } main.cpp
8
http://cs.mst.edu Main File comment header system and user includes namespace declaration main function // Author: Clayton Price // File: main.cpp // This file drives the greet // function. #include "greet.h" #include using namespace std; int main() { greetings(); cout << “Good bye” << endl; return 0; } main.cpp
9
http://cs.mst.edu Main File comment header system and user includes namespace declaration main function // Author: Clayton Price // File: main.cpp // This file drives the greet // function. #include "greet.h" #include using namespace std; int main() { greetings(); cout << “Good bye” << endl; return 0; } main.cpp
10
http://cs.mst.edu Main File comment header system and user includes namespace declaration main function // Author: Clayton Price // File: main.cpp // This file drives the greet // function. #include "greet.h" #include using namespace std; int main() { greetings(); cout << “Good bye” << endl; return 0; } main.cpp
11
http://cs.mst.edu Implementation File comment header user include function definitions // Author: Clayton Price // File: greet.cpp // This file provides the // greetings functionality #include "greet.h" void greetings() { cout << "Hello world!" << endl; return; } greet.cpp
12
http://cs.mst.edu Implementation File comment header user include function definitions // Author: Clayton Price // File: greet.cpp // This file provides the // greetings functionality #include "greet.h" void greetings() { cout << "Hello world!" << endl; return; } greet.cpp
13
http://cs.mst.edu Implementation File comment header user include function definitions // Author: Clayton Price // File: greet.cpp // This file provides the // greetings functionality #include "greet.h" void greetings() { cout << "Hello world!" << endl; return; } greet.cpp
14
http://cs.mst.edu Implementation File comment header user include function definitions // Author: Clayton Price // File: greet.cpp // This file provides the // greetings functionality #include "greet.h" void greetings() { cout << "Hello world!" << endl; return; } greet.cpp
15
http://cs.mst.edu Header File comment header preprocessor directives system and user includes namespace declaration function prototypes // Author: Clayton Price // File: greet.h // This file contains prototype // info for the greet program. // // Function: void greetings(); // This function sends a hello // message to the user through // standard output #ifndef GREET_H #define GREET_H #include using namespace std; void greetings(); #endif greet.h
16
http://cs.mst.edu Header File comment header preprocessor directives system and user includes namespace declaration function prototypes // Author: Clayton Price // File: greet.h // This file contains prototype // info for the greet program. // // Function: void greetings(); // This function sends a hello // message to the user through // standard output #ifndef GREET_H #define GREET_H #include using namespace std; void greetings(); #endif greet.h
17
http://cs.mst.edu Header File comment header preprocessor directives system and user includes namespace declaration function prototypes // Author: Clayton Price // File: greet.h // This file contains prototype // info for the greet program. // // Function: void greetings(); // This function sends a hello // message to the user through // standard output #ifndef GREET_H #define GREET_H #include using namespace std; void greetings(); #endif greet.h
18
http://cs.mst.edu Header File comment header preprocessor directives system and user includes namespace declaration function prototypes // Author: Clayton Price // File: greet.h // This file contains prototype // info for the greet program. // // Function: void greetings(); // This function sends a hello // message to the user through // standard output #ifndef GREET_H #define GREET_H #include using namespace std; void greetings(); #endif greet.h
19
http://cs.mst.edu Header File comment header preprocessor directives system and user includes namespace declaration function prototypes // Author: Clayton Price // File: greet.h // This file contains prototype // info for the greet program. // // Function: void greetings(); // This function sends a hello // message to the user through // standard output #ifndef GREET_H #define GREET_H #include using namespace std; void greetings(); #endif greet.h
20
http://cs.mst.edu Header File comment header preprocessor directives system and user includes namespace declaration function prototypes // Author: Clayton Price // File: greet.h // This file contains prototype // info for the greet program. // // Function: void greetings(); // This function sends a hello // message to the user through // standard output #ifndef GREET_H #define GREET_H #include using namespace std; void greetings(); #endif greet.h
21
http://cs.mst.edu Header File comment header preprocessor directives system and user includes namespace declaration function prototypes do not do this! // Author: Clayton Price // File: greet.h // This file contains prototype // info for the greet program. // // Function: void greetings(); // This function sends a hello // message to the user through // standard output #ifndef GREET_H #define GREET_H #include using namespace std; #include “greet.cpp” void greetings(); #endif greet.h
22
http://cs.mst.edu Compiling Single File g++ -W –Wall –s –pedantic-errors prog.cpp –o my_prog Multiple Files by Name g++ -W –Wall –s –pedantic-errors treeFarm.cpp treeFarmFunctions.cpp –o trees Multiple Files by Wildcard g++ -W –Wall –s –pedantic-errors *.cpp –o trees
23
http://cs.mst.edu Motivation Security Portability Versitiliy Extendability #ifndef GREET_H #define GREET_H #include using namespace std; void greetings(); #endif greet.h 00101010100110101001010010101 01001101010010100101010100110 10100101001010101001101010010 10010101010011010100101001010 10100110101001010010101010011 01010010100101010100110101001 01001010101001101010010100101 01010011010100101001010101001 10101001010010101010011010100 Compiled greet.cpp
24
http://cs.mst.edu End of Session
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.