본문 바로가기

Programming/C++15

[C++] 15. STL과 람다식 15.1 이번 장에서 만들어 볼 프로그램 15.2 표준 템플릿 라이브러리(STL: Standard Templete Library) : 프로그래머들이 공통적으로 사용하는 자료구조와 알고리즘을 구현한 클래스 컨테이너: 자료를 저장하는 창고와 같은 역할을 하는 구조 - 배열, 연결리스트, 벡터, 집합, 사전, 트리 등 반복자(iterator): 컨테이너의 요소를 가리키는 데 사용된다. 알고리즘 탐색(find): 컨테이너 안에서 특정한 자료를 찾는다. 정렬(sort): 자료들을 크기순으로 정렬한다. 반전(reverse): 자료들의 순서를 역순으로 한다. 삭제(remove): 조건이 만족되는 자료를 삭제한다. 변환(transform): 컨테이너의 요소들을 사용자가 제공하는 변환 함수에 따라서 변환한다. 15.3 .. 2024. 2. 17.
[어서와 C++는 처음이지!] CH8 Exercise 1 #include using namespace std; int main() { int n; cout > n; int* p; // 포인터 선언 p = new int[n]; // 동적 메모리 할당 for (int i = 0; i p[i]; // 동적 메모리에 정수 저장 } cout 2024. 2. 12.
[C++] 8. 포인터와 동적객체 생성 8.1 이번 장에서 만들어 볼 프로그램 8.2 포인터란? int n = 10; // 변수 정의 int *p; // 포인터 선언 p = &n; // 변수 n의 주소를 포인터 p에 저장 #include using namespace std; int main() { int n = 10; int* p = &n; // 포인터 p에 변수 n의 주소 저장 cout 2024. 2. 12.
[어서와 C++는 처음이지!] CH6 Exercise 1 벡터 크기 설정 #include #include using namespace std; int main() { int n; cout > n; vector v(n); for (auto& e : v) { cout > e; } int max = v[0]; int min = v[0]; for (auto& e : v) { if (e > max) max = e; if (e < min) min = e; } cout 2024. 1. 30.
[C++] 6. 객체 배열과 벡터 6.1 이번 장에서 만들어 볼 프로그램 6.2 객체 배열 : 객체들이 모여 있는 컨테이너 #include #include using namespace std; class Circle { public: int x, y; int radius; Circle() { x = 0; y = 0; radius = 0; } Circle(int _x, int _y, int r) { x = _x; y = _y; radius = r; } void print() { cout 2024. 1. 30.
[어서와 C++는 처음이지!] CH5 Exercise 1 #include using namespace std; class Book { public: string title; string author; // 생성자 Book(string t, string a) { title = t; author = a; } }; int main() { Book myBook("Great C++", "Bob"); cout 2024. 1. 29.
[C++] 5. 생성자와 접근제어 5.1 이번 장에서 만들어 볼 프로그램 5.2 생성자(constructor) : 초기화를 담당하는 함수 --> 객체를 생성할 때 객체를 초기화하는 함수가 자동으로 호출되도록 한다. class Time { public: int hour, minute; // 생성자 Time(int h, int m) { hour = h; minute = m; } void print() { cout 2024. 1. 29.
[어서와 C++는 처음이지!] CH4 Exercise 1 #include #include #include using namespace std; class Person { public: string name; int age; void setPerson(string n, int a) { name = n; age = a; } void print() { cout 2024. 1. 29.
[C++] 4. 클래스와 객체 4.1 이번 장에서 만들어 볼 프로그램 4.2 객체 지향이란? 절차 지향 프로그래밍(procedure programming): 프로시저(procedure)를 기반으로 하는 프로그래밍 방법 객체 지향 프로그래밍: 데이터와 함수를 하나의 객체로 묶는 것 - 캡슐화(encapsulation) 4.3 객체는 무엇으로 구성되는가? 멤버 변수(member variable) 멤버 함수(member function) 4.4 클래스는 객체의 설계도 #include using namespace std; // Circle 클래스 class Circle { public: int r; string color; double area() { return 3.14 * r * r; } }; int main() { Circle obj;.. 2024. 1. 29.