C++ Programming Ch.6 Exercise 5 Solution
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: ...