[pl in c++] 6. battle ship 3

27
PL in C++ 2014.7.23 박박박 BattleShip #3

Upload: mingeun-park

Post on 20-Jun-2015

304 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: [Pl in c++] 6. battle ship 3

PL in C++

2014.7.23박민근

BattleShip #3

Page 2: [Pl in c++] 6. battle ship 3

수업전 질문

http://agebreak.clbnow.com

Page 3: [Pl in c++] 6. battle ship 3

QA

Page 4: [Pl in c++] 6. battle ship 3

구조체

• 여러가지 다른 타입의 데이터의 묶음• 관련된 다양한 데이터를 하나의 묶음 데이터로 처리할 수 있다 .• 예 ) 배의 위치 : x 좌표 , y 좌표

Page 5: [Pl in c++] 6. battle ship 3

QA

Page 6: [Pl in c++] 6. battle ship 3

짝 만들기

Page 7: [Pl in c++] 6. battle ship 3

Battleship클래스 구현 실습

Page 8: [Pl in c++] 6. battle ship 3

배 (Ship) 클래스

Page 9: [Pl in c++] 6. battle ship 3

CShip ( 부모 클래스 )

Page 10: [Pl in c++] 6. battle ship 3

CShip 부모 클래스 생성자 함수- 멤버 변수 초기화

각 클래스의 상속

자식 클래스의 생성자 ( 초기화 )

Page 11: [Pl in c++] 6. battle ship 3

멤버 변수의 출력

현재 변수는 protected 이기 때문에 외부에서 사용하지 못한다 .

멤버 변수는 protected/private 로 선언하고 , 접근자 함수를 만드는 것이 좋다 .

예상치 못한 외부에서의 값 변경을 방지할 수 있다 . ( 은닉성 )

Page 12: [Pl in c++] 6. battle ship 3

이름 , HP, 타입을 출력 ( 실습 )

Page 13: [Pl in c++] 6. battle ship 3

이름 , HP, 타입을 출력 ( 실습 )Aircraft is HP : 5, TYPE : 0Battleship is HP : 4, TYPE : 1Cruiser is HP : 3, TYPE : 2Destroyer is HP : 2, TYPE : 3Submarine is HP : 1, TYPE : 4

Page 14: [Pl in c++] 6. battle ship 3

접근자 함수• 멤버 변수를 직접 노출하지 않고 , 특정 함수를 통해서만 접근하게 한다 .

• 일반적으로 Get/Set 형태로 구현 한다 .

Page 15: [Pl in c++] 6. battle ship 3

멤버 변수의 출력

Page 16: [Pl in c++] 6. battle ship 3

멤버 함수의 구현

Page 17: [Pl in c++] 6. battle ship 3

CShip::AddPosition() 구현 (P)

• 배가 위치할 좌표를 입력 받는다• 내부 위치 배열에 순차적으로 채워 넣는다 .• HP 보다 많이 들어오는 것들은 무시 한다 .

Page 18: [Pl in c++] 6. battle ship 3

배의 위치 정보를 출력 구현 (P)

Page 19: [Pl in c++] 6. battle ship 3

CShip::AddPosition()

Page 20: [Pl in c++] 6. battle ship 3

CShip::AddPosition()

Page 21: [Pl in c++] 6. battle ship 3

Cship::PrintPosition() 구현

Page 22: [Pl in c++] 6. battle ship 3

CShip::HitCheck() 구현 ( 실습 )

Page 23: [Pl in c++] 6. battle ship 3

CShip::HitCheck() 구현

Page 24: [Pl in c++] 6. battle ship 3

CShip::HitCheck() 구현

Page 25: [Pl in c++] 6. battle ship 3

배열의 개수 계산

Int array[5];Int size = sizeof(array) / sizeof(array[0]);

배열의 총 길이 (바이트 )

배열 원소 하나의 길이( 바이트 )

Page 26: [Pl in c++] 6. battle ship 3

삼항 연산자

조건식 TRUE일때 값

FALSE일때 값

bool pass = (point > 60) ? true : false;std::string gender = (name == “ 문익” ) ? “MAN” : “WOMAN”;

Page 27: [Pl in c++] 6. battle ship 3

수업후 질문

http://agebreak.clbnow.com