목록Develop/C++ (80)
오븐 노트
#include using namespace std; enum playerType { PT_Knight = 1, PT_Archer = 2, PT_Mage = 3, }; enum MonsterType { MT_Slime = 1, MT_Orc = 2, MT_Skeleton = 3, }; struct ObjectInfo { int type; int hp; int attack; int defence; }; // 구조체 멤버의 타입이 각기 다른 경우 padding 값이 할당되어 정렬됨 ObjectInfo playerInfo; ObjectInfo monsterInfo; void EnterLobby(); void SelectPlayer(); void EnterField(); void CreateRandomMonste..
#include using namespace std; enum playerType { PT_Knight = 1, PT_Archer = 2, PT_Mage = 3, }; enum MonsterType { MT_Slime = 1, MT_Orc = 2, MT_Skeleton = 3, }; int playerType; int hp; int attack; int defance; int monsterType; int monsterHp; int monsterAttack; int monsterDefence; void EnterLobby(); void SelectPlayer(); void EnterField(); void CreateRandomMonster(); int main() { // 랜덤 시드 설정 srand(t..
오버로딩 (중복 정의 : 함수명 재사용) 호출 시 같은 이름의 함수더라도 매개변수로 인해 구분이 가능할 경우 같은 이름이어도 사용이 가능하다. - 매개변수의 개수가 다를 경우 (기본 인자값 주의) - 매개변수의 타입이 다를 경우 (순서 포함) - 반환 형식은 해당되지 않음 #include using namespace std; int Add(int a, int b) { return a + b; } int Add(int a) { return a + 1; } float Add(float a, float b) { return a + b; } int main() { int result = Add(1, 2); cout
#include using namespace std; void PrintValue(int result) { cout
#include using namespace std; // 값 지정 필수인 상수 const int SCISSORS = 1; const int ROCK = 2; const int PAPER = 3; // 비슷한 용도끼리 묶은 열거형 // 값 지정은 선택 사항 // 값 지정 하지 않을 경우 첫번째 요소의 값은 0 // 값 지정 하지 않을 시 초기값부터 자동으로 +1 // 사용하는 습관 들이기 enum ENUM_SRP { ENUM_SCISSORS = 1, ENUM_ROCK, ENUM_PAPAER }; // # -> 전처리 지시문 // 지시 된 사항을 연산조차 하지 않고 그대로 복붙하는 매크로 // 1) 전처리 2) 컴파일 3) 링크 // 최대한 지양 #define DEFINE_TEST 1 + 2 #define..
#include using namespace std; int main() { // 가위 바위 보 srand(time(0)); // 시드 설정 const int SCISSORS = 1; const int ROCK = 2; const int PAPER = 3; int win = 0; int all = 0; while (true) { cout input; if (input == SCISSORS) { switch (computerValue) { case SCISSORS: cout
1. 별 찍기 (1) #include using namespace std; int main() { // 별 찍기 N * N int input; cin >> input; for (int i = 0; i i; j--) { cout