시험공부

(2025-2) Introduction to programming (2) 1. Introcudtion

norepinephrine 2025. 12. 18. 14:42

🎯 수업 목표

C++ 프로그래밍의 기초 구조와 사고방식 이해하기

  • 프로그래밍의 개념
  • 컴퓨터와 프로그램의 관계
  • C++ 언어의 특징
  • 컴파일과 실행 과정
  • 첫 번째 프로그램 (Hello, World)
  • 기본 입출력 구조 (cin, cout)
  • 에러와 디버깅
  • 문제 해결(problem solving) 사고 익히기

🧩 1. 프로그래밍이란?

“A program is a set of instructions that tells the computer what to do.”

  • 프로그램: 컴퓨터에게 무엇을 어떻게 할지 명령하는 지시문 집합
  • 프로그래밍: 인간의 논리를 컴퓨터가 이해할 수 있는 명령어로 바꾸는 과정

💡 비유

사람에게 “라면 끓여” → 가능

컴퓨터에 “라면 끓여” → 불가능

→ “냄비에 물 500ml 넣고 끓여라 → 스프 넣어라 → 면 넣고 4분간 끓여라”

→ 세세한 절차(algorithm)가 필요함

💻 2. 컴퓨터와 프로그램의 관계

  • 컴퓨터 구성요소
    • CPU: 명령어를 실행하는 두뇌
    • 메모리(RAM): 실행 중 임시로 저장
    • 저장장치(SSD/HDD): 프로그램·데이터 보관
    • 입출력장치: 키보드, 모니터, 프린터 등

📈 프로그램 실행 과정

소스코드(.cpp)

↓ 컴파일(Compile)

목적코드(.obj)

↓ 링크(Link)

실행파일(.exe)

↓ 실행(Run)

결과 출력(Output)

💡 3. C++ 언어의 개요

항목 내용

역사 1980년대 초, Bjarne Stroustrup이 C언어를 확장하여 개발
기원 “C with Classes” → 현재의 C++
특징 빠름, 객체지향, 범용성, 이식성, 강력한 표준 라이브러리
사용분야 시스템 프로그래밍, 게임, 금융, 인공지능, 임베디드 등

💬 “C++ is both a high-level and low-level language.”

⚙️ 4. 소스코드 → 실행 파일

단계 설명

Compile 문법 검사 후 기계어로 변환
Link 여러 목적 파일과 라이브러리를 연결
Run 완성된 실행 파일을 운영체제가 실행

📘 txt 인용

“The compiler translates source code into object code.”

“The linker combines object code files into an executable.”

👋 5. 첫 번째 프로그램 – Hello, World!

#include <iostream>  // 입출력 기능 포함

using namespace std;

int main() {

cout << "Hello, World!" << endl;

return 0;

}

🔍 코드 해설

코드 설명

#include <iostream> 입출력 기능 사용 선언
using namespace std; std::cout → cout로 단축
int main() 프로그램의 시작점
cout << ... 화면에 데이터 출력
endl 줄바꿈(newline)
return 0; 프로그램 정상 종료 표시

💡 Every C++ program must have a function named main.

🧮 6. 입력과 출력

▶ 출력 (cout)

cout << "Result: " << x << endl;

  • << : 삽입 연산자 (데이터를 출력 스트림에 보냄)
  • endl : 개행 문자, 출력 버퍼 비움(flush)

▶ 입력 (cin)

int num;

cin >> num;

  • : 추출 연산자

  • cin : 표준 입력(키보드)

📘 txt 인용

“C++ uses streams to perform input and output operations.”

🧠 7. 오류와 디버깅(Debugging)

종류 설명 예시

Syntax Error 문법 오류 (컴파일 안 됨) 세미콜론 빠짐
Runtime Error 실행 중 문제 발생 0으로 나누기
Logic Error 결과는 나오지만 틀림 평균 계산식 잘못됨

“Debugging is the process of finding and fixing errors in a program.”

🧩 8. 프로그래밍 사고(Problem Solving)

📘 txt 인용

“Programming is problem solving.”

“We analyze the problem, design a solution, implement it in code, and test it.”

단계 설명

Problem Analysis 문제를 정확히 이해하고 입력/출력 정의
Design 해결 절차(알고리즘) 설계
Implementation 설계된 절차를 C++ 코드로 작성
Testing & Debugging 실행 결과 검증 및 오류 수정

💬 “Step-by-step thinking” → 논리적 사고와 절차적 접근이 핵심

🧠 9. 종합 요약

구분 핵심 키워드 설명

프로그래밍 명령어 집합 컴퓨터에게 일을 시키는 방법
컴퓨터 구성 CPU, 메모리, I/O 프로그램은 이 자원 위에서 실행
C++ 특징 객체지향, 효율적, 빠름 다양한 분야에서 사용
컴파일 과정 compile → link → run 소스 → 실행파일
기본 코드 Hello, World main()은 시작점
입출력 cin, cout stream 기반
오류 syntax / runtime / logic 디버깅으로 해결
사고방식 problem solving 분석 → 설계 → 구현 → 테스트

💬 10. 실습 예제

#include <iostream>

using namespace std;

int main() {

int a, b;

cout << "Enter two numbers: ";

cin >> a >> b;

cout << "Sum = " << a + b << endl;

return 0;

}

🧾 실행 예시

Enter two numbers: 3 5

Sum = 8

🧩 11. 마무리 문장

“C++ programs are built step by step — from simple statements to complex systems.”

💬 이번 주차의 목표

C++ 프로그램의 기본 구조를 이해하고, 간단한 코드를 직접 실행해 보는 것.