전체 글(289)
-
[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++] 29. 문자열: string이란?
프로그래밍에서, 스트링(string)이란 문자열이나 비트열과 같이 기호나 값들이 연속되는 것을 말한다. 문자열의 경우에는 그 값들이 따옴표 내에 들어 있는 경우가 많다. 예를 들어, HELLO이라고 되어 있으면 대개 변수명을 가리키지만, "HELLO"과 같이 표현되어 있으면 문자열을 나타내는 것이다. #include #include using namespace std; // 문자열인 스트링(string)을 쓰는 이유 // 다양한 기능을 가졌기 때문이다(기능을 가진 함수의 클래스) // textRPG를 만들때 유용하다 void main() { char charText[] = "Hello World";// 문자 string stringText = "Hello World";// 문자열 cout
2022.06.14 -
[C++] 가상함수를 써서 플레이어를 생성하는 함수를 호출해보자
#include #include using namespace std; struct Class { void virtual Attack() { cout
2022.06.13 -
[C++] 구조체/생성자와 소멸자/동적할당/동적배열/상속/가상함수
/* 학습목차 1. 구조체 2. 생성자와 소멸자 3. 동적할당 4. 동적배열 5. 상속 6. 가상함수 */ #include #include using namespace std; // 구조체 // 직접 만드는 쓰는 서로다른 데이터타입의 집합체 // 기능(멤버함수)과 속성(멤버변수)을 지닌 사용자 정의의 데이터타입 struct Monster { string name; int hp; int atk; void SetInfo(string _name, int _hp, int _atk) { name = _name; hp = _hp; atk = _atk; } void ShowInfo() { 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