1 / 24

Multiple Files

Multiple Files. Monolithic vs Modular. multiple files now main driver file prototypes header file(s) functions definition implementation source file(s). one file before system includes main driver function prototypes function definitions . greet.h. # ifndef GREET_H #define GREET_H

sveta
Download Presentation

Multiple Files

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Multiple Files

  2. Monolithic vs Modular • multiple files now • main driver file • prototypes header file(s) • functions definition implementation source file(s) • one file before • system includes • main driver function • prototypes • function definitions

  3. greet.h #ifndef GREET_H #define GREET_H #include <iostream>using namespace std; #endif main.cpp #include <iostream>using namespace std; int main(){    greetings();     return 0;}void greetings() {cout << "Hello world!" << endl;    return;} void greetings();

  4. greet.h #ifndef GREET_H #define GREET_H #include <iostream>using namespace std;void greetings(); #endif main.cpp #include <iostream> #include “greet.h”using namespace std; int main(){    greetings();     return 0;} greet.cpp #include "greet.h" void greetings() {cout << "Hello world!" << endl;    return;}

  5. greet.h #ifndef GREET_H #define GREET_H #include <iostream>using namespace std;void greetings(); #endif main.cpp #include <iostream> #include “greet.h”using namespace std; int main(){    greetings();     return 0;} greet.cpp #include "greet.h" void greetings() {cout << "Hello world!" << endl;    return;}

  6. Main File main.cpp // Author: Clayton Price // File: main.cpp // This file drives the greet // function. #include "greet.h" #include <iostream> using namespace std; int main(){    greetings(); cout << “Good bye” << endl;    return 0;} comment header system and user includes namespace declaration main function

  7. Main File main.cpp // Author: Clayton Price // File: main.cpp // This file drives the greet // function. #include "greet.h" #include <iostream> using namespace std; int main(){    greetings(); cout << “Good bye” << endl;    return 0;} comment header system and user includes namespace declaration main function

  8. Main File main.cpp // Author: Clayton Price // File: main.cpp // This file drives the greet // function. #include "greet.h" #include <iostream> using namespace std; int main(){    greetings(); cout << “Good bye” << endl;    return 0;} comment header system and user includes namespace declaration main function

  9. Main File main.cpp // Author: Clayton Price // File: main.cpp // This file drives the greet // function. #include "greet.h" #include <iostream> using namespace std; int main(){    greetings(); cout << “Good bye” << endl;    return 0;} comment header system and user includes namespace declaration main function

  10. Main File main.cpp // Author: Clayton Price // File: main.cpp // This file drives the greet // function. #include "greet.h" #include <iostream> using namespace std; int main(){    greetings(); cout << “Good bye” << endl;    return 0;} comment header system and user includes namespace declaration main function

  11. Implementation File greet.cpp // Author: Clayton Price // File: greet.cpp // This file provides the // greetings functionality #include "greet.h" void greetings() {cout << "Hello world!" << endl;     return;} comment header user include function definitions

  12. Implementation File greet.cpp // Author: Clayton Price // File: greet.cpp // This file provides the // greetings functionality #include "greet.h" void greetings() {cout << "Hello world!" << endl;     return;} comment header user include function definitions

  13. Implementation File greet.cpp // Author: Clayton Price // File: greet.cpp // This file provides the // greetings functionality #include "greet.h" void greetings() {cout << "Hello world!" << endl;     return;} comment header user include function definitions

  14. Implementation File greet.cpp // Author: Clayton Price // File: greet.cpp // This file provides the // greetings functionality #include "greet.h" void greetings() {cout << "Hello world!" << endl;     return;} comment header user include function definitions

  15. Header File greet.h // 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 <iostream>using namespace std;void greetings(); #endif comment header preprocessor directives system and user includes namespace declaration function prototypes

  16. Header File greet.h // 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 <iostream>using namespace std;void greetings(); #endif comment header preprocessor directives system and user includes namespace declaration function prototypes

  17. Header File greet.h // 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 <iostream>using namespace std;void greetings(); #endif comment header preprocessor directives system and user includes namespace declaration function prototypes

  18. Header File greet.h // 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 <iostream>using namespace std;void greetings(); #endif comment header preprocessor directives system and user includes namespace declaration function prototypes

  19. Header File greet.h // 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 <iostream>using namespace std;void greetings(); #endif comment header preprocessor directives system and user includes namespace declaration function prototypes

  20. Header File greet.h // 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 <iostream>using namespace std;void greetings(); #endif comment header preprocessor directives system and user includes namespace declaration function prototypes

  21. Header File greet.h // 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 <iostream>using namespace std; #include “greet.cpp”void greetings(); #endif comment header preprocessor directives system and user includes namespace declaration function prototypes do not do this!

  22. 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. Motivation greet.h Compiled greet.cpp #ifndef GREET_H #define GREET_H #include <iostream>using namespace std;void greetings(); #endif 001010101001101010010100101010100110101001010010101010011010100101001010101001101010010100101010100110101001010010101010011010100101001010101001101010010100101010100110101001010010101010011010100101001010101001101010010100101010100110101001010010101010011010100 Security Portability Versitiliy Extendability

  24. End of Session

More Related