C언어로 작성된 소스를 C++로 변경.
알찬마루
c언어로 작성된 소스를 c++로 변경어느부분을 바꿔야 될련지 모르겠어요질문 내용 :
#include stdio.h
#include stdlib.h
#include string.h
#define max_array 100
// 받은 10진의 값을 2, 8, 16진수의 값으로 변환
void notation(int input, int base)
{
char hex[max_array];
int result, j;
int i = 0;
while(input != 0)
{
result = input % base; // 입력받은 값과 base를 나누어 나머지 값을 result에보관
// 나머지가 10이하이면 0 1 2 3 4 5 6 7 8 9 을 hex배열에 저장
if(result 10)
{
hex[i]=(char)(result + 48);
}
// 나머지가 10이상이면 a b c d e f 를 hex배열에 저장
else
{
hex[i]=(char)(result + 55);
}
input /= base;//입력받은 값과 base를 나눈 값을 input에 저장
i++;
}
i--;// 마지막 배열에는 null값이 존재하므로 1을 감소한다.
printf(입력한 수의 %d의 진수는: , base);
// 저장된 hex배열의 값을 출력한다.
for(j = i; j = 0; j--)
{
printf(%c, hex[j]);
}
printf(\n);
}
// 2 8 16 진수의 값을 10진수로 변환하여 리턴해준다.
int transformation(char change[], int base)
{
int b=0;
int j=0;
int i=0;
int k=0;
k=strlen(change);//change배열의 길이를 찾는다.
for(; i k; i++)
{
j = change[i];// 배열의 하나 하나 의 값을 j에 저장한다.
//printf(%d\n, j);
// int값으로 받은 값을 아스키 값으로 변환한 다음 비교한다.
if(j 65)
{
b = (j - 48) + b * base;
}
else
{
b = (j - 55) + b * base;
}
}printf(\n입력한수의 10진수는: %d\n, b); // 변환된 값을 10진수로 출력
return b;// 10진수로 출력된 값을 리턴한다.
}
void main()
{
int input;
int n1 = 0;
char hex[max_array];
//input = (char *)malloc(sizeof(char));
system(cls);// 화면을 지운다.
printf(입력하려는 진수를 선택 하시오.\n\n 1. 2진수\n 2. 8진수\n 3. 10진수\n 4. 16진수\n: );
scanf(%d, &input);// 매뉴 선택
switch(input)
{
case 1:// 2진수를 입력한 값 변환
system(cls);
printf(2진수를 입력 하시오.: );
scanf(%s, hex);
n1 = transformation(hex, 2);
notation(n1, 8);
notation(n1, 16);
break;
case 2 :// 8진수 입력한 값 변환
system(cls);
printf(8진수를 입력하시오.: );
scanf(%s, hex);
n1 = transformation(hex, 8);
notation(n1, 2);
notation(n1, 16);
break;
case 3:// 10진수 입력한 값 변환
system(cls);
printf(10진수를 입력하시오.: );
scanf(%d, &n1);
notation(n1, 2);
notation(n1, 8);
notation(n1, 16);
break;
case 4 :// 16진수 입력한 값 변환
system(cls);
printf(16진수를 입력하시오(문자는 대문자로 입력): );
scanf(%s, hex);
n1 = transformation(hex, 16);
notation(n1, 2);
notation(n1, 8);
break;
}
}
c++로 변환하고자 하는데 제가 초보라 그런지 멍충해서 그런지 잘안되네요