c++(72)
-
[C++] 함수의 매개변수로 구조체를 넣어보고 할당과 해제 순서 테스트하기
#include using namespace std; struct Monster { string name; float hp; float damage; // 기본 생성자 만들기 Monster() { cout
2022.06.07 -
[C++] 22. 생성자와 소멸자
#include using namespace std; // 구조체의 생성자와 소멸자 // 생성자 : 메모리에 할당될 때 호출되는 함수 // 생성자는 초기화할때 쓰임 // 소멸자 : 메모리에서 해제될 때 호출되는 함수 struct Monster { // 필드(구조체의 속성) string name; float hp; float damage; // 기본생성자의 형태 // 구조체이름() { } Monster() { cout
2022.06.07 -
[C++] 내가 만든 TextRPG 게임
*목표 : 몬스터와 플레이어들 간의 상호작용을 통하여 한쪽이 죽으면 끝나는 게임을 만들고자 했다. *구현 순서 1. 몬스터 구조체와 플레이어 구조체를 만든다 2. 각각 속성과 기능에 무엇이 필요한지 고민 후 만든다 3. 몬스터와 플레이어가 싸우려면 외부함수를 두어 상호작용할수있게 만들어본다 #include #include using namespace std; struct Monster { string name; int hp; int atk; bool isDie; void Hit(float damage) { cout
2022.06.03 -
[C++] 배열/2차원배열/구조체/멤버함수/입력/랜덤
/* 학습목차 1. 배열 2. 2차원배열 3. 구조체 4. 멤버함수 5. 입력 6. 랜덤(난수생성) */ #include #include //srand , rand #include //time using namespace std; // 배열의 정의 // 같은 데이터타입의 집합 // 크기와 주소를 같은 메모리상에서 연속적으로 배치를 시켜줌 // 배열의 시작주소를 알면 데이터타입의 크기를 통해 다른 원소들의 주소와 크기를 명확히 알수있음 void main() { int scoreA; int scoreB; int scoreC; cout
2022.06.03 -
[C++] 숫자야구 게임
#include #include #include #include using namespace std; void main() { srand(time(NULL)); int randomNumber1 = rand() % 10; int randomNumber2 = rand() % 10; int randomNumber3 = rand() % 10; while (randomNumber1 == randomNumber2 || randomNumber2 == randomNumber3 || randomNumber1 == randomNumber3) { int randomNumber1 = rand() % 10; int randomNumber2 = rand() % 10; int randomNumber3 = rand() % 10; }..
2022.06.03 -
[C++] 가위바위보 게임
1. #include #include #include #include using namespace std; // 0 ~ 100 중 난수 10번 출력 void main() { srand(time(NULL)); for (int i = 0; i < 11; i++) { cout
2022.06.02