Problem:
동일한 크기로 배열을 변환하는 다음 2개의 static 멤버 함수를 가진 ArrayUtility 클래스를 만들어라.
| 1 2 3 4 | static void intToDouble(int source[], double dest[], int size); // int[]을 double[]로 변환 static void doubleToInt(double source[], int dest[], int size); // double[]을 int[]로 변환 |
ArrayUtility를 활용하는 main()은 다음과 같다.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 | int main() { int x[] = {1,2,3,4,5}; double y[5]; double z[] = {9.9,8.8,7.7,6.6,5.6}; ArrayUtility::intToDouble(x, y, 5); // x[] -> y[] for(int i=0; i<5; i++) cout << y[i] << ' '; cout << endl; ArrayUtility::doubleToInt(z, x, 5); // z[] -> x[] for(int i=0; i<5; i++) cout << x[i] << ' '; cout << endl; } |
Execution Result:

Objective & Hints:
static 멤버 함수 만들기
Code:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include |
Explanation:
static 멤버 함수를 만들어서 사용하는 문제입니다.
static 멤버 함수는 클래스의 객체가 생성되지 않아도 범위 지정 연산자(Scope Operator) :: 를 사용해서 접근할 수 있습니다.