[ create a new paste ] login | about

Link: http://codepad.org/ZmN2Zy6i    [ raw code | output | fork ]

박정욱 - C++, pasted on May 12:
//객체지향 금123 2012.05.11
//4번		200911636박정욱
#include<iostream>
#include<iomanip>
using namespace std;

#define WRONG -1																		//code값이나 age값이 틀릴경우 함수의 리턴값을 WRONG으로 한다.
#define RIGHT 1																		//쓰이지는 않지만 주석문의 슈드코드를 이해하기 쉽게 하기위해 만듬.
	
#define CIN_NUM 10																	//입력받을 data의 갯수;입력갯수를 줄이거나 늘릴 시 이곳에서 수정한다.
																					//					 0	  1		2	  3		4
#define NUM_OF_AGE_SECTION 5														//나이 범위의 갯수; 0~20/20~40/40~60/60~80/80이상  총 5개.

//				  0		 1		2		3		 4		 5		코드갯수 6개
enum AREA_CODE {Seoul, Busan, Deagu, Gwangju, Incheon, Ulsan, NUM_OF_AREA_CODE};
//데이타 테이블		나이 범위			코드
int data_table[NUM_OF_AGE_SECTION][NUM_OF_AREA_CODE];								//ex) 광주사는 30살 입력시 -> data_table[1][3]++ 

void cout_area_codes_age();															//입력받을 age와 code의 범위를 보여준다; age(0~150),code(0~NUM_OF_AREA_CODE)
int Input();																		//입력받는 함수.
int Right_age(int input);															//age범위 확인 함수 ;if(input ∈ age) return input;  else return WRONG
int Right_code(int input);															//code범위 확인 함수;if(input ∈ code) return code;  else return WRONG
int convert_age_to_age_section(int right_age);										//age의 값을 범위단위로 리턴해주는 함수.
void cin_data(int age_section, int right_code);										//나이 범위과,지역코드를 data_table에 입력 해주는 함수.
void cout_area_name_by_code(int right_code);										//지역코드를 지역이름으로 출력해주는 함수.
void cout_data_table();																//입력받았던 data_table을 표로 풀력시키는 함수.

//{main 함수.--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void main()
{
	int age,												//Right_age함수의 리턴값을 받을 변수
		code, 												//Right_code함수의 리턴값을 받을 변수
		age_section,										//convert_age_to_age_section함수의 리턴값을 받을 변수
		i=0;												//i=0~CIN_NUM	i번째 입력

	cout_area_codes_age();									//입력받기전에 age와 code값의 범위를 알려준다;											①convert_age_to_age_section함수 호출;	입력받을 범위를 출력

	cout << "총 "<< CIN_NUM<<"명입력" <<endl;				//입력받기전에 총 몇명을 입력하게 되는지 알려준다.(CIN_NUM명 만큼 입력)
	
	//data의 저장
	while(i < CIN_NUM)										//CIN_NUM명 만큼 입력 받을때까지 반복.
	{
		cout << i+1 <<"번째 입력 : "<<endl;					//i+1명째 입력중임을 알려준다.
		do													
		{	cout << "나이 : ";								//Right_age함수 호출.																②Right_age 함수 호출;					age 입력
			age = Input();									//입력받은 age 값이 age범위(0~150) 안에 있는지 확인후 대입.							
			age = Right_age(age);	}						//Right_age 함수에서 입력받은 값이 0~150이 아닐경우, return WRONG => age	
		while(age == WRONG);								//age==WRONG 일경우 재수행.
	
		do
		{	cout << "코드 : ";								//Right_code함수 호출.																③Right_code 함수 호출;					code 입력
			code = Input();									//입력받은 code 값이 enum안에 있는지 확인후 대입(6:NUM_OF_AREA_CODE은 제외).			
			code = Right_code(code);	}					//Right_code 함수에서 입력받은 값이 0~5가 아닐경우, return WRONG => code
		while(code == WRONG);								//code==WRONG 일경우 재수행.

															//if(age == RIGHT && age == RIGHT)=> cin_data(age_section, code)					④cin_data함수 호출;						data를 저장
		age_section = convert_age_to_age_section(age);		//age와 code값이 정상일 경우, age를 age_section으로 변환한 후 cin_data함수 호출.
		cin_data(age_section, code);						//																					

		i++;												//i를 증가; i가 CIN_NUM이 될때 data저장을 종료한다.
	}
	//data의 출력
	cout_data_table();										//데이타를 테이블표로 출력시켜주는 cout_data_table함수 호출;							⑤cout_data_table함수 호출;				data의 출력
}		
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------main 함수.}

void cout_area_codes_age()//-------------------------------------------------------------------------------------[나이 입력 범위 와 지역코드 번호를 출력.]-------------------------------------------------------------
{																												//출력시
	cout << "나이 입력범위 : 0세~150세"<< endl																	//나이 입력범위 : 0세~150세
		 << "코드 입력범위 : 0~"<<NUM_OF_AREA_CODE<< endl														//코드 입력범위 : 0~50
		 << Seoul	<< " = Seoul"	<< endl																		//0 = Seoul
		 << Busan	<<" = Busan"	<< endl																		//1 = Busan
		 << Deagu	<<" = Deagu"	<< endl																		//2 = Deagu
		 << Gwangju	<<" = Gwangju"	<< endl																		//3 = Gwangju
		 << Incheon	<<" = Incheon"	<< endl																		//4 = Incheon
		 << Ulsan	<<" = Ulsan"	<< endl;																	//5 = Ulsan
};		 

int Input()//----------------------------------------------------------------------------------------------------[입력 함수; 입력받은 정수를 그대로 리턴.]--------------------------------------------------------------
{	int input;
	cin >> input;
	return input;
};

int Right_age(int input)//---------------------------------------------------------------------------------------[age범위 확인 함수;if(input ∈ age) return input;  else return WRONG]---------------------------------
{	int right_age,																								//input 값이 올바르면 right_age에 대입하여 return.
		wrong_age = WRONG;																						//input 값이 구간 밖이면 wrong_age에 WRONG을 대입하여 return.
	if(input < 0 || input >150)																					//wrong_age인 경우 
	{	cout << "error : 나이 입력범위 : 0세~150세"<<endl;														//age범위를 다시 알려주고
		return wrong_age;										}												//return (wrong_age)
	
	else																										//그 외의 경우(right_age인 경우)
	{	right_age= input;																						//return (right_age)
		return right_age;	}
};

int Right_code(int input)//--------------------------------------------------------------------------------------[code범위 확인 함수;if(input ∈ code) return code;  else return WRONG]--------------------------------
{
	int right_code,																								//input 값이 올바르면 right_code에 대입하여 return.
		wrong_code = WRONG;																						//input 값이 구간 밖이면 wrong_code에 WRONG을 대입하여 return.
	if(input < 0 || input > 5)																					//wring_code 인 경우 code범위를 다시 알려준다.
	{	cout <<"error : 코드 입력범위 : 0~"<<NUM_OF_AREA_CODE<< endl												//code범위를 다시 알려주고
			 << Seoul	<< " = Seoul"	<< endl																	//return (wrong_code)
			 << Busan	<<" = Busan"	<< endl
			 << Deagu	<<" = Deagu"	<< endl
			 << Gwangju	<<" = Gwangju"	<< endl
			 << Incheon	<<" = Incheon"	<< endl
			 << Ulsan	<<" = Ulsan"	<< endl;
		return wrong_code;								}
	else																										//그 외의 경우(right_code인 경우)
	{	right_code= input;																						//return (right_code)
		return right_code;	}																					
};

int convert_age_to_age_section(int right_age)//------------------------------------------------------------------[age의 값을 범위단위로 리턴해주는 함수.]---------------------------------------------------------------
{
	/*if(right_age/20<0)																							
	{	cout << "error : convert_to_age_section-> right_age != RIGHT"<<endl; exit(1);	} 에러 방지*/
	if(right_age/20>3)																							//age/20 >4이상 일경우(80세 이상) 
	{	return 4;	}																							//return (4)
	else																										//그외의 경우
	{	return right_age/20;	}																				//return (age/20)
};

void cin_data(int age_section, int right_code)//-----------------------------------------------------------------[나이 범위과,지역코드를 data_table에 입력 해주는 함수.]-------------------------------------------------
{
	switch(right_code)
	{
		case Seoul	 : data_table[age_section][Seoul]++;	break;
		case Busan	 : data_table[age_section][Busan]++;	break;
		case Deagu	 : data_table[age_section][Deagu]++;	break;
		case Gwangju : data_table[age_section][Gwangju]++;	break;
		case Incheon : data_table[age_section][Incheon]++;	break;
		case Ulsan   : data_table[age_section][Ulsan]++;	break;
		default		 : cout<<"error : cin_data -> switch(right_code)"<< endl; exit(1);
		
	}
	
};

void cout_area_name_by_code(int right_code)//--------------------------------------------------------------------[지역코드를 지역이름으로 출력해주는 함수.]--------------------------------------------------------------
{
	switch(right_code)
	{
		case Seoul	 : cout << "Seoul";	 break;
		case Busan	 : cout << "Busan";	 break;
		case Deagu	 : cout << "Deagu";	 break;
		case Gwangju : cout << "Gwangju";break;
		case Incheon : cout << "Incheon";break;
		case Ulsan   : cout << "Ulsan";  break;
		default		 : cout<<"error : cout_area_nameby_code -> switch(right_code)"<< endl; exit(1);
	}
};

void cout_data_table()//-----------------------------------------------------------------------------------------[입력받았던 data_table을 표로 출력시키는 함수.]--------------------------------------------------------
{
	int age_section, code;																						//data_table[age_section][code]

	cout << "age\code	";																						//출력시
	for(code=0 ; code < NUM_OF_AREA_CODE ; code++)																//age\code		Seoul	Busan	Deagu	Gwangju  Incheon   Ulsan
	{	cout << "  "; cout_area_name_by_code(code);	}
	cout << endl;				
																												//출력시
	for(age_section=0 ; age_section < NUM_OF_AGE_SECTION ; age_section++)										//1)나이구간 출력, 2)data_table[age_section][code] 출력(code : 0~5), 3)줄바꿈.
	{																											//1)나이구간
		if(age_section != 4)																					//80세이상 시 
		{cout << age_section*20 << "이상~"<< (age_section+1)*20<<"미만	";}										//80세이상~  출력
		else																									//80세미만 시
		{cout << (age_section)*20 << "이상~		";}																//0이상~20미만, 20이상~40미만, 40이상~60미만, 60이상~80미만		출력
 
		for(code=0 ; code < NUM_OF_AREA_CODE ; code++)															//2) data_table[age_section][code]출력  (code : 0~5)
		{	cout <<"  "<< data_table[age_section][code]<<"	";	}
		cout << endl;																							//3)줄바꿈
	}

}


Output:
1
2
Line 29: error: '::main' must return 'int'
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: