c++(72)
-
[C++] 벡터를 사용해서 출석부만들기
#include #include #include using namespace std; struct SchoolMember { string name; int id; SchoolMember() { } SchoolMember(string _name, int _id) { name = _name; id = _id; } //virtual 가상함수 //자식에서 재정의 된 함수가 있다면 자식의 함수를 실행 void virtual ShowInfo() { cout
2022.06.14 -
[C++] 벡터의 기능을 이용해보자
#include #include #include using namespace std; void main() { // 1. int를 원소로 담는 동적배열 벡터 만들기 vector intVec; int input; // 2. cin으로 입력을 하나 받아 입력한 값만큼 5의 배수를 담으시오(push_back) cout > input; for (int i = 0; i < input; i++) { intVec.push_back(5 * (i + 1)); } // 3. 시작위치에 -1을 추가해보시오 intVec.insert(intVec.begin() + 0, -1); // 4. 요소들을 전부 출력해보시오 for (int i = 0; i < intVec.size(); i++) { cout
2022.06.14 -
[C++] 30. 벡터(vector)란 무엇인가?
#include #include #include using namespace std; // 벡터 // 벡터는 동적배열을 편하게 만든것 // 그렇기 때문에 다양한 기능이 존재한다 void main() { // 벡터의 기능 // push_back(), insert(), erase(), size() 등이 자주 쓰인다. // [문법] vector 변수명; vector intVec; // vector intVec(10);생성자가 있을경우 값(10)만큼 10개의 공간을 미리 확보한다 // push_back(값) : 가변배열 vector에 요소를 추가해준다 따라서 총 13개의 공간확보 // 많이 쓸수록 과부화가 발생하기 때문에 유의하자 intVec.push_back(10); intVec.push_back(20); i..
2022.06.14 -
[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