~cpp
#include <iostream>
using namespace std;
const bool TRUE=1;
const bool FALSE=0;
const int MAX_LONG=17;//5자리 숫자를 2진수로 표현하면 17이하의 자리수가 나옴.
const int MAX_NUMBER=99999;
const int MAX_JINBUB=24;
class stack
{
private:
char *data_p;
int where_is_save;
int max_size_of_stack;
public:
stack( int data_size )
{
data_p=(char*)malloc(data_size*sizeof(char));
max_size_of_stack=data_size;
where_is_save=0;
}
~stack()
{
free(data_p);
}
bool get_in(char save_data)
{
if (where_is_save != max_size_of_stack)
{
*(data_p+where_is_save)=save_data;
++where_is_save;
return TRUE;
}
else
return FALSE;
}
bool get_out(char *where_save_p )
{
if (where_is_save)
{
--where_is_save;
*where_save_p=*(data_p+where_is_save);
return TRUE;
}
return FALSE;
}
void clear_data()
{
where_is_save=0;
}
};
char number_to_char(int number)
{
const int NUMBER_TO_NUMBER=48;
const int NUMBER_TO_CHAR=55;
if (number<10)
return number+NUMBER_TO_NUMBER;
else
return number+NUMBER_TO_CHAR;
}
void main()
{
stack print_number(MAX_LONG);
int number=-1;
int jinbub=-1;
while (0>number || MAX_NUMBER<number)
{
cout << "10진수 = ";
cin >> number;
}
while (2>jinbub || MAX_JINBUB<jinbub)
{
cout << "진법 = ";
cin >> jinbub;
}
cout << "결과 = ";
while (0<number)
{
print_number.get_in(number_to_char(number%jinbub));
number=number/jinbub;
}
char temp;
while (print_number.get_out(&temp))
{
cout << temp;
}
}