분류 전체보기
-
[C++] 극장 좌석 예약 시스템(2차원 배열)C++/문제풀이 2022. 6. 13. 22:46
4 * 13 극장 좌석 예약 시스템 만들기 - 처음에는 전부 X로 초기화 - 좌석이 예약되면 배열 원소의 값이 O로 변경 // // main.cpp // // Created by yeonsu on 2022/06/13. // // 4 * 13 극장 좌석 예약 시스템 만들기 #include #include //rand 함수 #include using namespace std; void printArray(); char seats[4][13] = { {'X','X','X','X','X','X','X','X','X','X','X','X','X',}, {'X','X','X','X','X','X','X','X','X','X','X','X','X',}, {'X','X','X','X','X','X','X','X','X..
-
[C++] 2차원 배열을 이용하여 3개 학급 학생들의 평균 성적 구하기C++/문제풀이 2022. 6. 13. 20:34
power C++ 230p 2차원 배열을 이용하여 3개 학급 학생들의 평균 성적 구하기 [목표] 각 학급의 평균, 총 학생의 평균을 구한다. // // main.cpp // // Created by yeonsu on 2022/06/13. // // 3개 학급 학생들의 평균 성적 구하기 // [목표] // 각 학급의 평균, 총 학생의 평균을 구한다. #include #include //rand 함수 #include using namespace std; const int CLASSES = 3; const int STUDENTS = 5; int main(){ int array[CLASSES][STUDENTS] = { {1,2,3,4,5}, {6,7,8,9,10}, {11,12,13,14,15}, }; int ..
-
[C++] 2차원 배열 원소들의 합 구하기(난수 이용)C++/문제풀이 2022. 6. 13. 20:15
Power C++ p.229 2차원 배열 원소들의 합 구하기(난수 이용) // // main.cpp // // Created by yeonsu on 2022/06/13. // // 함수를 이용하여 2차원 배열의 원소들의 합 구하기 #include #include //rand 함수 #include using namespace std; //함수 원형 선언 int sum(int sum_array[][3]); int main(){ int array[3][3] = {0}; //2차원 배열 초기화 srand((unsigned)time(NULL)); //매번 새로운 난수 출력 //2차원 배열에 난수 집어넣기(이중 for문 활용) for(int i = 0; i
-
[C++] 문자열(string)C++/class 2022. 6. 9. 16:25
C++에서 문자열을 나타내는 방법 1. 문자 배열을 생성해서 문자열을 저장하고, 맨 끝에 NULL문자를 추가하는 방법 2. string 클래스를 사용하는 방법(추후) a 'a' "a" 변수 a 하나의 문자, 아스키 코드값과 같음 문자열, 끝에 NULL문자 추가됨 문자 배열의 초기화 char str[6] = "HELLO"; 1. 문자열 상수를 할당하면 컴파일러가 자동으로 끝에 NULL 문자 추가 2. 배열의 크기는 문자열보다 +1 되어야 함(NULL 문자) 문자열의 길이를 구하는 프로그램 cout
-
class_lab11.cpp 참조에 의한 호출C++/class 2022. 6. 8. 14:29
값에 의한 호출 1. int형, double형, ... 2. 지역변수이기 때문에 변수의 값을 교환할 수 없다. 참조에 의한 호출(포인터 이용) 같은 메모리값을 공유하기 때문에 변수의 값을 교환할 수 있다. Key Point 1. 값을 교환하는 방법 int tmp; tmp = *px; *px = *py; *py = tmp; 2. 값에 의한 호출과 참조에 의한 호출 차이점 - swap(int 형 변수 a,b) - swap(&a, &b) // // main.cpp // pointer II // // Created by yeonsu on 2022/06/08. // #include using namespace std; // ====================== ==============..
-
[C++] 배열과 포인터(*)를 이용하여 최대, 최소 구하기C++/문제풀이 2022. 5. 29. 21:57
[문제] C++ 200제 044번 배열과 포인터(*)를 이용하여 최대, 최소 구하기 - *를 인자로 사용하는 함수를 이용하여 최대, 최소를 구해보자. [기존 코드] // // main.cpp // // // Created by yeonsu on 2022/05/28. // #include #include #include using namespace std; int findMax(int x[], int n){ int max; max = x[0]; // 배열의 첫 번째 원소가 최댓값이라고 가정 for (int i = 0; i max) max = x[i]; } return max; } int findMin(int y[], int n){ int min; min = y[0]..
-
[C++] rand와 배열을 이용하여 임의의 수를 역순으로 출력하기C++/문제풀이 2022. 5. 26. 22:36
[문제] C++ 200제 038번 10개 임의의 수를 대입받아 역순으로 출력한다. [코드] // // 역순 출력.cpp // function // // Created by yeonsu on 2022/05/26. // #include #include //setw #include //rand using namespace std; int main(){ int random_num[10]; //배열 선언 -> 초기화를 하지 않아 현재는 쓰레기값이 들어있음 srand((unsigned)time(NULL)); //매번 실행할 때마다 새로운 난수를 생성하기 위해서 꼭 필요! for(int i = 0; i
-
[C++] 함수를 이용하여 커피잔 수 구하기C++/문제풀이 2022. 5. 25. 23:25
[C++ 200제 024번] 문제: 200원짜리 커피 자판기에 800원을 넣으면 몇 잔이 나오는지 구하는 함수를 만들자. 내가 짠 코드 // // coffee.cpp // function // // Created by yeonsu on 2022/05/25. // #include using namespace std; //커피 1잔 값 기호상수로 선언 const int cupOfCoffee = 200; const int Money = 800; //함수 원형 int coffeeMachine(int x, int y); int main(){ int inputMoney; cout