Top Banner
http://cs.mst.edu Multiple Files
24

Http://cs.mst.edu Multiple Files. Monolithic vs Modular one file before system includes main driver function prototypes function.

Jan 03, 2016

Download

Documents

Marjorie Ramsey
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

http://cs.mst.edu

Multiple Files

Page 2: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

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)

Page 3: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

http://cs.mst.edu

#include <iostream>using namespace std;

int main(){    greetings();     return 0;}

void greetings() {    cout << "Hello world!" << endl;    return;}

#ifndef GREET_H#define GREET_H

#include <iostream>using namespace std;

#endif

greet.h

main.cpp

void greetings();

Page 4: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

http://cs.mst.edu

#include <iostream>#include “greet.h”using namespace std;

int main(){    greetings();     return 0;}

#ifndef GREET_H#define GREET_H

#include <iostream>using namespace std;

void greetings();

#endif

greet.h

main.cpp

#include "greet.h"

greet.cpp

void greetings() {    cout << "Hello world!" << endl;    return;}

Page 5: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

http://cs.mst.edu

#include <iostream>#include “greet.h”using namespace std;

int main(){    greetings();     return 0;}

#ifndef GREET_H#define GREET_H

#include <iostream>using namespace std;

void greetings();

#endif

greet.h

main.cpp

#include "greet.h"

void greetings() {    cout << "Hello world!" << endl;    return;}

greet.cpp

Page 6: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

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 <iostream>

using namespace std;

int main(){    greetings(); cout << “Good bye” << endl;    return 0;}

main.cpp

Page 7: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

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 <iostream>

using namespace std;

int main(){    greetings(); cout << “Good bye” << endl;    return 0;}

main.cpp

Page 8: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

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 <iostream>

using namespace std;

int main(){    greetings(); cout << “Good bye” << endl;    return 0;}

main.cpp

Page 9: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

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 <iostream>

using namespace std;

int main(){    greetings(); cout << “Good bye” << endl;    return 0;}

main.cpp

Page 10: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

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 <iostream>

using namespace std;

int main(){    greetings(); cout << “Good bye” << endl;    return 0;}

main.cpp

Page 11: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

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

Page 12: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

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

Page 13: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

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

Page 14: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

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

Page 15: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

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 <iostream>using namespace std;

void greetings();

#endif

greet.h

Page 16: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

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 <iostream>using namespace std;

void greetings();

#endif

greet.h

Page 17: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

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 <iostream>using namespace std;

void greetings();

#endif

greet.h

Page 18: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

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 <iostream>using namespace std;

void greetings();

#endif

greet.h

Page 19: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

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 <iostream>using namespace std;

void greetings();

#endif

greet.h

Page 20: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

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 <iostream>using namespace std;

void greetings();

#endif

greet.h

Page 21: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

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 <iostream>using namespace std;

#include “greet.cpp”

void greetings();

#endif

greet.h

Page 22: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

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

Page 23: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

http://cs.mst.edu

Motivation Security Portability Versitiliy Extendability

#ifndef GREET_H#define GREET_H

#include <iostream>using namespace std;

void greetings();

#endif

greet.h

001010101001101010010100101010100110101001010010101010011010100101001010101001101010010100101010100110101001010010101010011010100101001010101001101010010100101010100110101001010010101010011010100101001010101001101010010100101010100110101001010010101010011010100

Compiled greet.cpp

Page 24: Http://cs.mst.edu Multiple Files.  Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.

http://cs.mst.edu

End of Session