[c++]3 loop statement

22
Loop Statement Presented by Junyoung Jung Club MARO Dept. of Electronic and Radio Engineering Kyung Hee Univ. ch 3.

Upload: junyoung-jung

Post on 15-Apr-2017

57 views

Category:

Software


0 download

TRANSCRIPT

Page 1: [C++]3 loop statement

Loop Statement

Presented by Junyoung Jung

Club MARODept. of Electronic and Radio Engineering

Kyung Hee Univ.

ch3.

Page 2: [C++]3 loop statement

Content

1.switch selection

2.while loop

3.for loop

4.Practice

5.Assignments

0.Last class Review

Page 3: [C++]3 loop statement

Content

3

int 정수형 변수 4byte

double 실수형 변수 8byte

char 문자형 변수 1byte

# 변수

변수 선언 시 가독성, 초기화 생각하기

0.Last class Review

2.while loop

3.for loop

4.Practice

5.Assignments

1.switch selection

Page 4: [C++]3 loop statement

Content

4

지역 변수 vs 전역변수

0.Last class Review

2.while loop

3.for loop

4.Practice

5.Assignments

1.switch selection

hole-in-scope ???

# Assignment 1

Page 5: [C++]3 loop statement

Content

5

# Assignment 3: 설계

0.Last class Review

2.while loop

3.for loop

4.Practice

5.Assignments

1.switch selection

Page 6: [C++]3 loop statement

Content

6

int main() {

int num1, num2, select;cout << “두정수를입력하시오 : ” << endl;cin >> num1 >> num2;

cout << “사용할연산을고르시오(1: +, 2: -, …) ” << endl;cin >> select;

if(select == 1) {cout<< num1 <<“ + “ << num2 << “ = “ << num1 + num2 << endl;

}else if(select == 2) {

cout<< num1 <<“ -“ << num2 << “ = “ << num1 -num2 << endl;}…

return 0;}

# Assignment 2 다시 보기

0.Last class Review

2.while loop

3.for loop

4.Practice

5.Assignments

1.switch selection

Page 7: [C++]3 loop statement

Content

7

0.Last class Review

2.while loop

3.for loop

4.Practice

5.Assignments

1.switch selection

조건문(Selection statement)?

특정조건을 만족할 때,해당 문장을 수행

- if-else 문- switch 문

Page 8: [C++]3 loop statement

Content

8

0.Last class Review

2.while loop

3.for loop

4.Practice

5.Assignments

1.switch selection

switchswitch(정수) {

case (상수1):실행문;break;

case (상수2):실행문;break;

case (상수3):실행문;break;

default:실행문;break;

…}

Page 9: [C++]3 loop statement

Content

9

0.Last class Review

2.while loop

3.for loop

4.Practice

5.Assignments

1.switch selection

…int main() {

int num1, num2, select;cout << “두정수를입력하시오 : ” << endl;cin >> num1 >> num2;

cout << “사용할연산을고르시오(1: +, 2: -, …) ” << endl;cin >> select;

switch(select) {case 1:

cout<< num1 << “ + ” << num2 << “ = “ << num1 + num2 << endl;break;

case 2:cout<< num1 << “ -” << num2 << “ = “ << num1 -num2 << endl;break;

…default:

cout << “error” << endl;}

return 0;}

# Practicce switch

Page 10: [C++]3 loop statement

Content

10

0.Last class Review

2.while loop

3.for loop

4.Practice

5.Assignments

1.switch selection 반복 조건이 성립할 때,

반복 영역을 반복 수행

- while 문- for 문

반복문(loop statement)?

Page 11: [C++]3 loop statement

Content

11

0.Last class Review

2.while loop

3.for loop

4.Practice

5.Assignments

1.switch selection

while

while (반복 조건) {

반복 영역;

}

Page 12: [C++]3 loop statement

Content

12

0.Last class Review

2.while loop

3.for loop

4.Practice

5.Assignments

1.switch selection

int main() {

int a = 100;int count = 0;

while (a < 119) {cout << “반복횟수 : ” << count << endl;cout << a << endl;count++;a++;

}

return 0;}

#Practice while

Page 13: [C++]3 loop statement

Content

13

0.Last class Review

2.while loop

3.for loop

4.Practice

5.Assignments

1.switch selection

for

for(시작조건; 종결조건; 조건변화식){

반복 영역;

}

Page 14: [C++]3 loop statement

Content

14

0.Last class Review

2.while loop

3.for loop

4.Practice

5.Assignments

1.switch selection

int main() {

int a = 100;

for(int i = 0; i < 19; i++) {cout << “반복횟수 : ” << i << endl;cout << a << endl;a++;

}

return 0;}

#Practice for

Page 15: [C++]3 loop statement

Content

15

0.Last class Review

2.while loop

3.for loop

4.Practice

5.Assignments

1.switch selection *

***************

#계단 모양 만들기

계단 층 입력 : 4

************************************

계단 층 입력 : 7

Page 16: [C++]3 loop statement

Content

16

0.Last class Review

2.while loop

3.for loop

4.Practice

5.Assignments

1.switch selection

#계단 모양 만들기 설계

Hint !! 반복문 두 번 쓰기

- 반복 1 : 층 결정

- 반복 2 : 한 층씩 * 출력

Page 17: [C++]3 loop statement

Content

17

0.Last class Review

2.while loop

3.for loop

4.Practice

5.Assignments

1.switch selection

#계단 모양 만들기 코딩…

int main() {

int a = line;cin >> line;

for (int i = 0; i < 조건; i++) {

for (int j = 0; j < 조건; j++) {…

} …

}return 0;

}

Page 18: [C++]3 loop statement

Content

18

역 계단 설계 !!!

Assignment 1)0.Last class Review

2.while loop

3.for loop

4.Practice

5.Assignments

1.switch selection

****************

Page 19: [C++]3 loop statement

Content

19

Assignment 2)0.Last class Review

2.while loop

3.for loop

4.Practice

5.Assignments

1.switch selection

역 계단 코딩 !!!****************

Page 20: [C++]3 loop statement

Content

20

http://play-entry.org/codingparty/2015#!/

Assignment 3)0.Last class Review

2.while loop

3.for loop

4.Practice

5.Assignments

1.switch selection 다음 사이트 들어가서

“초등 고학년1” 까지 완료하기

Page 21: [C++]3 loop statement

Content

21

Assignment 뽀너쓰)0.Last class Review

2.while loop

3.for loop

4.Practice

5.Assignments

1.switch selection

*************************

다음 모양 설계 &코딩 !!!

Page 22: [C++]3 loop statement

Thank you