Upload
marjorie-ramsey
View
213
Download
0
Embed Size (px)
Citation preview
http://cs.mst.edu
Multiple Files
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)
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();
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;}
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
http://cs.mst.edu
End of Session