본문 바로가기
프로그래밍

[C++] 명품 c++ 프로그래밍 실습 6장 5번

by 엽기토기 2020. 12. 23.
반응형
#include <iostream>
using namespace std;

class ArrayUtility {
public:
	static void intToDouble(int source[], double dest[], int size);
	static void doubleToint(double source[], int dest[], int size);
};
void ArrayUtility::intToDouble(int source[], double dest[], int size) {
	for (int i = 0; i < size; i++)
		dest[i] = source[i]; //자동형변환
}
void ArrayUtility::doubleToint(double source[], int dest[], int size) {
	for (int i = 0; i < size; i++)
		dest[i] = source[i]; //자동형변환
}

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;
}
반응형