Download presentation
Presentation is loading. Please wait.
1
CS 202 Computer Science II Lab Fall 2009 September 17
2
Today Topics Basic makefile ACM Problem
3
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);
4
.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.}
5
..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.}
6
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
7
…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
8
Basic makefile main main.obasicMath.o main.cppbasicMath.h basicMath.cpp
9
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
10
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
11
Basic makefile make –f main.make
12
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
13
Questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.