include 1 n include iostream include cmath using

  • Slides: 28
Download presentation

#include 지시문(1) n 하나의 소스 파일로 된 예제 소스 코드 #include <iostream> #include <cmath>

#include 지시문(1) n 하나의 소스 파일로 된 예제 소스 코드 #include <iostream> #include <cmath> using namespace std; struct Point { int x, y; }; double Distance(Point p 1, Point p 2); int main() { // 생략 double dist_a_b = Distance(a, b); // 생략 } double Distance(Point p 1, Point p 2) { // 생략 }

#include 지시문(2) n #include 지시문을 사용해서 두 개의 소스 파일로 나누어 보자. // Example.

#include 지시문(2) n #include 지시문을 사용해서 두 개의 소스 파일로 나누어 보자. // Example. h struct Point { int x, y; }; double Distance(Point p 1, Point p 2); // Example. cpp #include <iostream> #include <cmath> using namespace std; #include “Example. h” int main() { // 생략 double dist_a_b = Distance(a, b); // 생략 } double Distance(Point p 1, Point p 2) { // 생략 }

실전 테스트 (3) n 앞에서 배운 규칙대로 한 결과 // A. h void A

실전 테스트 (3) n 앞에서 배운 규칙대로 한 결과 // A. h void A 1(); void A 2(); // B. h void B 1(); void B 2(); // B. cpp #include “B. h” void B 1() { } void B 2() { } // A. cpp #include “A. h” #include “B. h” void A 1() { A 2(); } void A 2() { B 1(); B 2(); } // Example. cpp #include “A. h” #include “B. h” int main() { A 1(); B 1(); return 0; }

다른 파일에 있는 구조체 사용하기 (1) n 하나의 소스 파일로 된 예제 소스 코드

다른 파일에 있는 구조체 사용하기 (1) n 하나의 소스 파일로 된 예제 소스 코드 struct Point { int x, y; }; double Distance(const Point& pt 1, const Point& pt 2) { // 이 함수의 내용은 생략한다. return 0. 0 f; } int main() { // 두 점을 만든다. Point a = {100, 100}; Point b = {200, 200}; // 함수를 호출한다. double dist; dist = Distance(a, b); return 0; }

다른 파일에 있는 구조체 사용하기 (2) n 여러 개의 파일로 나누어 보자. // Point.

다른 파일에 있는 구조체 사용하기 (2) n 여러 개의 파일로 나누어 보자. // Point. h struct Point { int x, y; }; // Example 1. cpp #include “Point. h” #include “Exaple 2. h” int main() { // 두 점을 만든다. Point a = {100, 100}; Point b = {200, 200}; // 함수를 호출한다. double dist; dist = Distance(a, b); return 0; } // Example 2. h double Distance(const Point& pt 1, const Point& pt 2); // Example 2. cpp #include “Point. h” #include “Example 2. h” double Distance(const Point& pt 1, const Point& pt 2) { // 이 함수의 내용은 생략한다. return 0. 0 f; }