CS 202 Computer Science II Lab Fall 2009 September 17
Today Topics Basic makefile ACM Problem
Header file example… Create headerExample directory – *do not delete files Create basicMath.h file : 1./* basicMath.h */ 2. 3.int add (int a, int b); 4.int mul (int a, int b);
.Header file example.. Create basicMath.cpp file : 1./* basicMath.cpp */ 2.int add (int a, int b) { 3. return a+b; 4.} 5.int mul (int a, int b) { 6. return a*b; 7.}
..Header file example. Create main.cpp file : 1.#include 2.#include "basicMath.h" 3.using namespace std; 4.int main(int argc, char ** argv) { 5.int a, b; 6.cout << " Name: Your-Name " << endl; 7.cout << " Section: Your-Section-No " << endl; 8.if (argc > 2) { 9.a = atoi(argv[1]); 10.b = atoi(argv[2]); 11.} else { 12.a = 1; 13. b = 2; 14.} 15.cout << a << " + "<< b << " = " << add(a, b) << endl; 16.cout << a << " * "<< b << " = " << mul(a, b) << endl; 17.return 0; 18.}
Basic makefile Help to manage a project which might have multiple files associated with. Help programmers to compile source codes faster with shorter command line during development process
…Header file example – g++ -c main.cpp – g++ -c basicMath.cpp – Or: – g++ -c *.cpp – g++ -o main main.o basicMath.o –./main 12 5 > output.out
Basic makefile main main.obasicMath.o main.cppbasicMath.h basicMath.cpp
Basic makefile “makefile” is a series of rules which is invoked by “make” program make [-f makefile] – Preferred extension:.make – Default file: “makefile” targetList: dependencyList commandList
main.make main: main.o basicMath.o g++ -o main main.o basicMath.o main.o: main.cpp basicMath.h g++ -c main.cpp basicMath.o: basicMath.cpp basicMath.h g++ -c basicMath.cpp
Basic makefile make –f main.make
ACM ACM International Collegiate Programming Contest is an annual competition among the universities of the world. The contest is sponsored by IBM. (Wikipedia) ACM problem
Questions?