SlideShare a Scribd company logo
Variables and
Selection Statement
Presented by Junyoung Jung
Club MARO
Dept. of Electronic and Radio Engineering
Kyung Hee Univ.
ch2.
Content
1.
Variables and Types
2.
Operators
3.
Selection statement
4.
Practice
5.
Assignments
0.
Last class Review
Content
3
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
. . .
Computer
Content
4
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
// iostream 이라는 header 파일(;cpp파일 앞에 위치)을 포함
#include <iostream>
// sdt 라는 namespace(; 소속, ‘준영이의’ 외모, ‘동재의’ 외모) 사용
using namespace std;
int main()
{
// Hello World 문자열 모니터에 출력
cout << “Hello World” << endl;
return 0;
}
Content
5
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
변수란 무엇인가?
먼저 컴퓨터 구조를 알아보자
Content
6
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
CPU Memory
I/O I/O
. . .
0
4
8
100
104
108
Processing
Content
7
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
데이터가 저장될 임의의 공간
메모리에 변수가
저장될 공간을 할당하는 것
# 변수
# 변수 선언
Content
8
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
- true, new, int 등 미리 지정되어 있는 키워드 불가
- 변수 이름 첫 글자는 숫자 불가
- 변수 이름에 특수문자 포함 불가
- 변수 이름 사이의 공백 불가
# 변수 선언 주의사항
…
int main() {
int powerButton, keyButton;
double m_value;
char in_signature;
…
return 0;
}
Content
9
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
가독성이 좋은 이름을 사용하자!!
…
int main() {
int num;
// num이 어떤 값을 가지는지 알지 못하기 때문에 error
cout << num << endl;
return 0;
}
Content
10
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
변수의 초기화를 잊지 말자!!
Content
11
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
int 정수형 변수 4byte
double 실수형 변수 8byte
char 문자형 변수 1byte
# 주요 변수
Content
12
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
#include <iostream>
using namespace std;
int main() {
// 정수형 변수 a선언, a에 100 할당
int a;
a = 100;
cout << a << endl;
return 0;
}
Content
13
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
변수가 있다면
상수도 있을까?
Content
14
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
#include <iostream>
using namespace std;
const double pi = 3.141592;
int main() {
…
const int a = 100;
return 0;
}
Content
15
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
지역변수(local value),
전역변수(global value)
차이 조사하기!!!
Assignment 1)
Content
16
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
연산자(Operator)?
data를 information으로
사용할 수 있게끔 해주는 역할
- 준영 생각
Content
17
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
# 산술 연산자
# 대입 연산자
# 논리 연산자
+, -, *, /, %
a = a+1;
a += 1;
a++;
a && b;
a || b;
# 관계 연산자 a == b;
a != b;
Content
18
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
#include <iostream>
using namespace std;
int main() {
/*
1. 정수형 변수 num과 실수형 변수 result을 선언
2. result 을 10이라 할당
3. num 을 키보드 입력
4. num과 result의 합, 차, 곱,
나눗셈의 몫과 나머지를 모니터 출력
*/
}
#Practice 산술 연산자
Content
19
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
…
int main() {
int a = 100;
a++;
cout << “a++결과 : ” << a << endl;
a -= 21;
cout << “a -= 21 결과 : ” << a << endl;
a = a*2;
cout << “a= a*2 결과 : ” << a << endl;
return 0;
}
#Practice 대입 연산자
Content
20
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
조건문(Selection statement)?
특정조건을 만족할 때,
해당 문장을 수행
- if-else 문
- switch 문
Content
21
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
if-else ①
if(조건문) {
조건문 만족시 실행할 문장
}
Content
22
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
if-else ②
if(조건문) {
조건문 만족시 실행할 문장
}
else {
조건문에 해당하지 않는 사항
}
Content
23
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
if-else ③
if(조건1) {
조건문 만족시 실행할 문장
}
else if (조건2) {
조건문에 해당하지 않는 사항
}
else if (조건3) {
}
…
else {
}
Content
24
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
…
int main() {
int a, b;
cin >> a >> b;
if(a == b) {
cout << a << “와 ” << b << “가 같습니다.” << endl;
}
else if(a > b) {
cout << a << “가 ” << b << “보다 큽니다.” << endl;
}
else {
cout << a << “가 ” << b << “보다 작습니다.” << endl;
}
return 0;
}
#Practice if-else
Content
25
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
Assignment 2 를
같이 만들어 보아요 !!
Content
26
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
지역변수(local value),
전역변수(global value)
차이 조사하기!!!
Assignment 1)
Content
27
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes 1. 정수형 변수 선언
2. cin을 통해 두 변수에 값 할당
3. if-else문을 이용하여
사칙연산 프로그램 만들기
Assignment 2)
Pracctice 를 본인의 스타일로 다시 해보기
Content
28
0.
Last classReview
2.
Operators
3.
Selectionstatement
4.
Practice
5.
Assignments
1.
VariablesandTypes
Assignment 2의
내용을 설계하기
Assignment 3)
Thank you

More Related Content

PDF
W14 chap13
PPTX
NDC 2011, 네트워크 비동기 통신, 합의점의 길목에서
PDF
6 function
PDF
Javascript - Function
PDF
6 swift 고급함수
PDF
[C++ Korea 2nd Seminar] C++17 Key Features Summary
PDF
코딩인카페 C&JAVA 기초과정 C프로그래밍(2)
PPTX
PPL: Composing Tasks
W14 chap13
NDC 2011, 네트워크 비동기 통신, 합의점의 길목에서
6 function
Javascript - Function
6 swift 고급함수
[C++ Korea 2nd Seminar] C++17 Key Features Summary
코딩인카페 C&JAVA 기초과정 C프로그래밍(2)
PPL: Composing Tasks

What's hot (20)

PDF
2013 C++ Study For Students #1
PDF
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
PDF
C++ Concurrency in Action 9-2 Interrupting threads
PDF
5 swift 기초함수
PPTX
포트폴리오에서 사용한 모던 C++
PPT
Refactoring - Chapter 8.2
PDF
C++17 Key Features Summary - Ver 2
PDF
코딩인카페 C&JAVA 기초과정 C프로그래밍(1)
PDF
코딩인카페 C&JAVA 기초과정 C프로그래밍(3)
PDF
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...
PDF
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준
PPTX
[devil's camp] - 알고리즘 대회와 STL (박인서)
PDF
C++20 Key Features Summary
PPTX
자바스크립트 함수
PDF
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...
KEY
Cleancode ch14-successive refinement
PDF
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
PPTX
[C++ Korea 2nd Seminar] Ranges for The Cpp Standard Library
PDF
[Swift] Generics
PPTX
Java8 람다
2013 C++ Study For Students #1
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
C++ Concurrency in Action 9-2 Interrupting threads
5 swift 기초함수
포트폴리오에서 사용한 모던 C++
Refactoring - Chapter 8.2
C++17 Key Features Summary - Ver 2
코딩인카페 C&JAVA 기초과정 C프로그래밍(1)
코딩인카페 C&JAVA 기초과정 C프로그래밍(3)
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준
[devil's camp] - 알고리즘 대회와 STL (박인서)
C++20 Key Features Summary
자바스크립트 함수
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...
Cleancode ch14-successive refinement
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
[C++ Korea 2nd Seminar] Ranges for The Cpp Standard Library
[Swift] Generics
Java8 람다
Ad

Viewers also liked (9)

PDF
[C++]6 function2
PDF
[C++]1 ready tobeprogrammer
PDF
[C++]4 review
PDF
[2016 K-global 스마트디바이스톤] inSpot
PDF
[대학생 연합 해커톤 UNITHON 3RD] Mingginyu_ppt
PDF
[C++]5 function
PDF
[Maybee] inSpot
PDF
[C++]3 loop statement
PDF
16 학술제 마무리 자료
[C++]6 function2
[C++]1 ready tobeprogrammer
[C++]4 review
[2016 K-global 스마트디바이스톤] inSpot
[대학생 연합 해커톤 UNITHON 3RD] Mingginyu_ppt
[C++]5 function
[Maybee] inSpot
[C++]3 loop statement
16 학술제 마무리 자료
Ad

Similar to [C++]2 variables andselectionstatement (20)

PPTX
C review
PDF
게임프로그래밍입문 3주차
PDF
02장 자료형과 연산자
PDF
HI-ARC PS 101
PDF
03장 조건문반복문네임스페이스
PPTX
[170327 1주차]C언어 A반
PDF
3주차 스터디
PPT
C수업자료
PPT
C수업자료
PPTX
Basic study 4회차
PDF
2015 Kitel C 언어 강좌3
PDF
7 mid term summary
PPTX
03장 조건문, 반복문, 네임스페이스
PDF
3 2. if statement
PPTX
파이썬 기초
PDF
2015 Kitel C 언어 강좌1
PPTX
컴퓨터개론05
PDF
2주차 스터디
PDF
C언어 연산자에 대해 간과한 것
PDF
C 언어 스터디 02 - 제어문, 반복문, 함수
C review
게임프로그래밍입문 3주차
02장 자료형과 연산자
HI-ARC PS 101
03장 조건문반복문네임스페이스
[170327 1주차]C언어 A반
3주차 스터디
C수업자료
C수업자료
Basic study 4회차
2015 Kitel C 언어 강좌3
7 mid term summary
03장 조건문, 반복문, 네임스페이스
3 2. if statement
파이썬 기초
2015 Kitel C 언어 강좌1
컴퓨터개론05
2주차 스터디
C언어 연산자에 대해 간과한 것
C 언어 스터디 02 - 제어문, 반복문, 함수

More from Junyoung Jung (16)

PDF
[KCC oral] 정준영
PDF
전자석을 이용한 타자 연습기
PDF
[2018 평창올림픽 기념 SW 공모전] Nolza 보고서
PDF
[2018 평창올림픽 기념 SW 공모전] Nolza - Activity curation service
PDF
SCC (Security Control Center)
PDF
Google File System
PDF
sauber92's Potfolio (ver.2012~2017)
PDF
Electron을 사용해서 Arduino 제어하기
PDF
[UNITHON 5TH] KOK - 프로귀찮러를 위한 지출관리 서비스
PDF
[우아주, Etc] 정준영 - 페이시스템
PDF
[우아주, 7월] 정준영
PDF
[team608] 전자석을 이용한 타자연습기
PDF
[Kcc poster] 정준영
PDF
[Graduation Project] 전자석을 이용한 타자 연습기
PDF
[KCC poster]정준영
PDF
[2015전자과공모전] ppt
[KCC oral] 정준영
전자석을 이용한 타자 연습기
[2018 평창올림픽 기념 SW 공모전] Nolza 보고서
[2018 평창올림픽 기념 SW 공모전] Nolza - Activity curation service
SCC (Security Control Center)
Google File System
sauber92's Potfolio (ver.2012~2017)
Electron을 사용해서 Arduino 제어하기
[UNITHON 5TH] KOK - 프로귀찮러를 위한 지출관리 서비스
[우아주, Etc] 정준영 - 페이시스템
[우아주, 7월] 정준영
[team608] 전자석을 이용한 타자연습기
[Kcc poster] 정준영
[Graduation Project] 전자석을 이용한 타자 연습기
[KCC poster]정준영
[2015전자과공모전] ppt

[C++]2 variables andselectionstatement