알고리즘 라이브세션, c++문법 1-5강 복습
==========
의사 코드 - 코드와 의사 사이에 있는 무언가 /주석 뒤에 오는 말과 유사하다.
//표현을 일관되게 . 문제를 해결할 때는 분할을 잘해야 한다.
심부름 예시 / 실습을 많이 하는 것이 중요하다.
자료구조는 요리 도구에 가깝다.
알고리즘에서 정답은 여러가지가 될 수 있다.
char c = 'c';
string s = " Hello, World!"; - 선언도 ' ' " " 를 써야한다.
=====
#include <iostream>
using namespace std;
int main() {
int a = 5;
int x = 5;
for (int i = 0; i<4; i++){
a = a*x;
}
cout << a << endl;
return 0;
}
=====
#include <cmath> // pow 함수를 사용하기 위한 헤더
pow(base, exponent); -base를 exponent 만큼 제곱
===
#include <iostream>
int main() {
double d = 2346.7;
===
round - 반올림 - 마찬가지로 cmath를 포함해야 함
double d = 2346.7
double rounded = round(d);
===
#include <iostream>
int main() {
int a = 5;
if (a >0 ) {
cout << "동작 중" << endl;
} else
cout << " 정지" << endl;
return 0;
}
===
#include <iostream>
int main() {
int a = 0;
int b = 10;
while (a>=b) {
cout << "a = " << a <<endl;
a += 1
}
return 0;
}
===
do-while - 아무튼 한번 실행하고 조건에 따라 while처럼 행동
greet


================================
class 개념
자동차 예시.
손잡이만 공개하고 내부 구조는 숨기는 것.
===
class 이름 {
멤버(변수, 함수)
} ;
===
==========
#include <iostream>
#include <algorithm> //max 함수 사용
#include <string>
using namespace std;
class Student {
//동작 정의(이를 멤버함수라고 합니다)
double getAvg() {
return (kor + eng + math ) / 3.0;
}
int getMax() {
return max(max(kor, eng), math);
}
//데이터 정의(이를 멤버변수라고 합니다.)
int kor;
int eng;
int math;
};
==========
#include <iostream>
#include <algorithm> //max 함수 사용
#include <string>
using namespace std;
class Student
{
//동작 정의(이를 멤버함수라고 합니다)
double getAvg();
int getMaxNum();
//데이터 정의(이를 멤버변수라고 합니다.)
int kor;
int eng;
int math;
};
double Student::getAvg() {
return (kor + eng + math) / 3.0;
}
int Student::getMaxNum() {
return max(max(kor, eng), math);
// 다른 방법 return max({ kor, eng, math });
}
==========
클래스는 헤더파일로 외부 구동은 소스 파일로 제작된다.
주로 헤더는 목차 소스는 내용으로 쓰여진다.
public - :: 으로 접근 가능 // pirvate - ::으로 접근 불가능 (기본값)
멤버 함수는 public 멤버 변수는 private를 일반적으로 지정한다.
this -> math
===
cpp.sh에서 대소문자 구분이 되어있다. (대문자를 썼을 때 그것에 맞춰줘야 올바르게 동작한다.)
==========
복습 세션
&&, || - and, or
nullptr - 포인터 초기화
const - 뒤를 상수로 취급하겠다.
배열 포인터는 한번 더 확인해 봐야겠다.
#ifndef - #define //endif
#pragma once -위와 유사하게 사용되고 언리얼에서 지원된다.
=====
#include <iostream>
using namespace std;
class Person {
public:
string name;
int age;
void temp() {}
Person(string n, int a) {}
};
int main() {
Person p("a", 30);
Person p2;
p.temp();
p2.temp();
return 0;
}
=====
#include <iostream>
using namespace std;
class Player {
public:
Player(Hp, Mp);
private:
int Hp;
int Mp;
}
=====
#include <iostream>
using namespace std;
int main() {
int A;
cout << "press number : " << endl;
cin << A;
if (A == 0 ) {
cout << " it's zero" << endl;
} else if (A%2 == 0) {
cout << "it's even" << endl;
} else
cout << "it's odd" << endl;
return 0;
}
=====



.
'TIL' 카테고리의 다른 글
| 25.12.15일자 - TIL (0) | 2025.12.15 |
|---|---|
| 25.12.12일자 - TIL (0) | 2025.12.12 |
| 25.12.10일자 - TIL (0) | 2025.12.10 |
| 25.12.09일자 -TIL (0) | 2025.12.09 |
| 25.12.08일자 - TIL (0) | 2025.12.08 |