코딩 1막 <C++개념편>/코딩 1막 <C++응용편>(34)
-
[C++] 랜덤한 확률이 조정된 강화를 하는 아이템 생성하기
C 언어의 랜덤함수를 공부해보신 분은 아시겠지만 컴퓨터라는 기계는 완전한 랜덤을 구현하기 힘듭니다. 랜덤함수는 보통 현재 시간으로부터 Seed 값을 받아와서 불규칙하지만 같은 값이 반복되어 나오지는 않는 (적어도 주어진 값 범위 내에서는 모든 수를 중복되지 않게 출력하기 전까지는 다시 같은 수가 안나오게) 수열을 생성해서 결과값을 가지기 때문입니다. 1. 첫번째방법_ 스트링(문자열)의 기능을 써서 강화함수만들기 #include #include using namespace std; void main() { string text = "단검+0"; int count = 0; int input = 0; while (true) { cout input; if (input == 3) { count = stoi(tex..
2022.06.14 -
[C++] 생성한 문자열 공백없애는 함수 만들기
*문자열 string #include #include using namespace std; string GetStringRemoveSpace(string targetText, string target) { string result; while (targetText.find(target) != string::npos) { result += targetText.substr(0, targetText.find(target)); targetText = targetText.substr(targetText.find(target) + target.length()); } result += targetText; return result; } void main() { string targetText = "Hello Hell..
2022.06.14 -
[C++] 가상함수를 써서 플레이어를 생성하는 함수를 호출해보자
#include #include using namespace std; struct Class { void virtual Attack() { cout
2022.06.13 -
[C++] 구조체 만들고, 상속해보고, 오버로딩, 오버라이딩 및 가상함수 구현해보기
#include #include using namespace std; // 1. 부모구조체 : Family / 자식구조체 : Parents, Child 만들고 상속 struct Family { string name; int age; Family() { } Family(string _name, int _age) { name = _name; age = _age; } void SetInfo(string _name, int _age) { name = _name; age = _age; } // 6. 부모의 멤버함수에 virtual 키워드를 붙여 가상함수로 만든 뒤 다시 호출 void virtual ShowInfo() { cout
2022.06.10 -
[C++] 상속 : 부모 몬스터 <--- 자식 드래곤
#include #include using namespace std; struct Monster { string name; int hp; int atk; int isChase; Monster(string _name, int _hp, int _atk, bool _isChase) { name = _name; hp = _hp; atk = _atk; isChase = _isChase; } void Attack() { cout
2022.06.10 -
[C++] 동적할당을 써서 별찍기, 배수의 배열 그리고 배열범위 넓히기★
1. #include using namespace std; void main() { int input; cout input; int* arr = new int[input]; for (int j = 1; j
2022.06.07