차이
문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판 이전 판 | |||
| activity:public:2021:cpp:210506 [2021/05/10 12:26:26] – Youtube 링크 추가 david | activity:public:2021:cpp:210506 [2021/05/20 21:45:59] (현재) – 시간/장소/참가자 틀 서식 통일 david | ||
|---|---|---|---|
| 줄 1: | 줄 1: | ||
| + | ======C++ 스터디 #4: Phase 1 복습 및 심화내용====== | ||
| + | |||
| + | | 시간 | 2021년 5월 6일 목요일 20:30 ~ 22:10 | | ||
| + | | 장소 | Google Meet | | ||
| + | | 참가자 | - | | ||
| + | |||
| + | {{youtube> | ||
| + | |||
| + | 출처: https:// | ||
| + | |||
| + | =====1. Phase 1 복습===== | ||
| + | |||
| + | =====2. switch문===== | ||
| + | switch 표현식이 값을 평가하고, | ||
| + | |||
| + | ====2.1. switch문 예시==== | ||
| + | |||
| + | <sxh cpp> | ||
| + | #include < | ||
| + | using namespace std; | ||
| + | |||
| + | int main() | ||
| + | { | ||
| + | int num; | ||
| + | cin >> num; | ||
| + | |||
| + | switch(num) | ||
| + | { | ||
| + | case 1: | ||
| + | cout << " | ||
| + | break; | ||
| + | case 2: | ||
| + | cout << " | ||
| + | break; | ||
| + | default: | ||
| + | cout << " | ||
| + | break; | ||
| + | } | ||
| + | |||
| + | return 0; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | \\ | ||
| + | |||
| + | =====3. 예제===== | ||
| + | |||
| + | ====3.1. switch문 예제==== | ||
| + | |||
| + | \\ | ||
| + | |||
| + | <fs large> | ||
| + | |||
| + | 표준 입력으로 문자 ' | ||
| + | |||
| + | |||
| + | \\ | ||
| + | |||
| + | <fs large> | ||
| + | |||
| + | <sxh; gutter: false> | ||
| + | f | ||
| + | 환타 | ||
| + | </ | ||
| + | |||
| + | \\ | ||
| + | |||
| + | <fs large> | ||
| + | |||
| + | <sxh cpp> | ||
| + | #include < | ||
| + | using namespace std; | ||
| + | |||
| + | int main() | ||
| + | { | ||
| + | char menu; | ||
| + | cin >> menu; | ||
| + | |||
| + | switch (menu) | ||
| + | { | ||
| + | case ' | ||
| + | cout << " | ||
| + | break; | ||
| + | case ' | ||
| + | cout << " | ||
| + | break; | ||
| + | case ' | ||
| + | cout << " | ||
| + | break; | ||
| + | default: | ||
| + | cout << " | ||
| + | break; | ||
| + | } | ||
| + | |||
| + | return 0; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | \\ | ||
| + | |||
| + | ====3.2. 별 기호(*)로 가로 5 세로 4 직사각형 그리기==== | ||
| + | |||
| + | \\ | ||
| + | |||
| + | <fs large> | ||
| + | |||
| + | <sxh; gutter: false> | ||
| + | ***** | ||
| + | ***** | ||
| + | ***** | ||
| + | ***** | ||
| + | </ | ||
| + | |||
| + | \\ | ||
| + | |||
| + | <fs large> | ||
| + | |||
| + | <sxh cpp> | ||
| + | #include < | ||
| + | using namespace std; | ||
| + | |||
| + | int main() | ||
| + | { | ||
| + | for (int i = 1; i <= 4; i++) | ||
| + | { | ||
| + | for (int j = 1; j <= 5; j++) | ||
| + | { | ||
| + | cout << " | ||
| + | } | ||
| + | |||
| + | cout << endl; | ||
| + | } | ||
| + | |||
| + | return 0; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | \\ | ||
| + | ====3.3. 별 기호(*)로 5층 계단 그리기 ==== | ||
| + | |||
| + | \\ | ||
| + | |||
| + | <fs large> | ||
| + | |||
| + | <sxh; gutter: false> | ||
| + | * | ||
| + | ** | ||
| + | *** | ||
| + | **** | ||
| + | ***** | ||
| + | </ | ||
| + | |||
| + | \\ | ||
| + | |||
| + | <fs large> | ||
| + | |||
| + | <sxh cpp> | ||
| + | #include < | ||
| + | using namespace std; | ||
| + | |||
| + | int main() | ||
| + | { | ||
| + | for (int i = 1; i <= 5; i++) | ||
| + | { | ||
| + | for (int j = 1; j <= i; j++) | ||
| + | { | ||
| + | cout << " | ||
| + | } | ||
| + | |||
| + | cout << endl; | ||
| + | } | ||
| + | |||
| + | return 0; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | \\ | ||
| + | ====3.4. 별 기호(*)로 5층 역삼각형 그리기==== | ||
| + | |||
| + | \\ | ||
| + | |||
| + | <fs large> | ||
| + | |||
| + | <sxh; gutter: false> | ||
| + | ***** | ||
| + | **** | ||
| + | *** | ||
| + | ** | ||
| + | * | ||
| + | </ | ||
| + | |||
| + | \\ | ||
| + | |||
| + | <fs large> | ||
| + | |||
| + | <sxh cpp> | ||
| + | #include < | ||
| + | using namespace std; | ||
| + | |||
| + | int main() | ||
| + | { | ||
| + | for (int i = 1; i <= 5; i++) | ||
| + | { | ||
| + | for (int j = 1; j <= 5; j++) | ||
| + | { | ||
| + | if (j < i) | ||
| + | cout << " "; | ||
| + | else | ||
| + | cout << " | ||
| + | } | ||
| + | |||
| + | cout << endl; | ||
| + | } | ||
| + | |||
| + | return 0; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | \\ | ||
| + | ====3.5. 별 기호(*)로 5층 산 모양 그리기==== | ||
| + | |||
| + | \\ | ||
| + | |||
| + | <fs large> | ||
| + | |||
| + | <sxh; gutter: false> | ||
| + | * | ||
| + | *** | ||
| + | ***** | ||
| + | | ||
| + | ********* | ||
| + | </ | ||
| + | |||
| + | \\ | ||
| + | |||
| + | <fs large> | ||
| + | |||
| + | <sxh cpp> | ||
| + | #include < | ||
| + | using namespace std; | ||
| + | |||
| + | int main() | ||
| + | { | ||
| + | for (int i = 1; i <= 5; i++) | ||
| + | { | ||
| + | for (int j = 1; j <= 9; j++) | ||
| + | { | ||
| + | if (j > 5 - i && j < 5 + i) | ||
| + | cout << " | ||
| + | else | ||
| + | cout << " "; | ||
| + | } | ||
| + | |||
| + | cout << endl; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | \\ | ||
| + | ====3.6. FizzBuzz==== | ||
| + | |||
| + | \\ | ||
| + | |||
| + | <fs large> | ||
| + | |||
| + | 1부터 100까지 자연수를 차례대로 출력하는데, | ||
| + | |||
| + | \\ | ||
| + | |||
| + | <fs large> | ||
| + | |||
| + | <sxh; gutter: false> | ||
| + | 1 | ||
| + | 2 | ||
| + | Fizz | ||
| + | 4 | ||
| + | |||
| + | . | ||
| + | . | ||
| + | . | ||
| + | |||
| + | 98 | ||
| + | Fizz | ||
| + | Buzz | ||
| + | </ | ||
| + | |||
| + | \\ | ||
| + | |||
| + | <fs large> | ||
| + | |||
| + | <sxh cpp> | ||
| + | #include < | ||
| + | using namespace std; | ||
| + | |||
| + | int main() | ||
| + | { | ||
| + | for (int i = 1; i <= 100; i++) | ||
| + | { | ||
| + | if (i % 3 == 0 && i % 5 == 0) | ||
| + | cout << " | ||
| + | else if (i % 3 == 0) | ||
| + | cout << " | ||
| + | else if (i % 5 == 0) | ||
| + | cout << " | ||
| + | else | ||
| + | cout << i << endl; | ||
| + | } | ||
| + | |||
| + | return 0; | ||
| + | } | ||
| + | </ | ||
| + | 아래와 같이 '' | ||
| + | <sxh cpp> | ||
| + | #include < | ||
| + | using namespace std; | ||
| + | |||
| + | int main(){ | ||
| + | for (int i = 1; i <= 100; i++) { | ||
| + | bool nothing = true; | ||
| + | |||
| + | if (i % 3 == 0){ // | ||
| + | cout << " | ||
| + | nothing = false; | ||
| + | } | ||
| + | |||
| + | if (i % 5 == 0){ // | ||
| + | cout << " | ||
| + | nothing = false; | ||
| + | } | ||
| + | |||
| + | if(nothing){ | ||
| + | cout << i; | ||
| + | } | ||
| + | |||
| + | cout << endl; | ||
| + | } | ||
| + | return 0; | ||
| + | } | ||
| + | </ | ||
| + | \\ | ||
| + | |||
| + | |||
| + | |||
| + | |||