U E D R , A S I H C RSS

진법바꾸기/조현태

느낀점

저번에 만든 스택을 사용했습니다.^^
클래스 하나 만들어놓으면 이럴땐 편하단 말야..ㅎㅎㅎ

여러일 동시에 하면서 짤려니..힘들닷..;;

소스

~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;
	}
}

나에게 할말

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2009-05-27 07:09:19
Processing time 0.0080 sec