U E D R , A S I H C RSS

whiteblue/My Term Project

~cpp 
#include <iostream>
#include <cstdlib>
using namespace std;

struct student
{
	char name[20];
	int number;
	int kor;
	int eng;
	int math;
	int total;
	double ave;
	char * grade;
};		// 구조체 선언

student data[20] = 
{
	{ "고재선" ,20025301, 85, 90, 80 },
	{ "권현진" ,20025302, 80, 88, 85 }, 
	{ "김동욱" ,20025303, 88, 93, 75 },
	{ "김무영" ,20025309, 75, 85, 70 },
	{ "김민재" ,20025307, 73, 83, 77 },
	{ "김성원" ,20025304, 95, 88, 80 },
	{ "김영준" ,20025308, 95, 88, 80 },
	{ "김윤섭" ,20025305, 94, 70, 65 },
	{ "김철호" ,20025306, 80, 75, 88 },
	{ "김태완" ,20025310, 65, 73, 94 },
	{ "김태완" ,20025313, 77, 78, 99 },
	{ "김희균" ,20025312, 80, 77, 85 },
	{ "류재현" ,20025311, 95, 80, 95 },
	{ "문구봉" ,20025315, 78, 90, 75 },
	{ "박대원" ,20025314, 90, 95, 65 },
	{ "박세연" ,20025316, 88, 88, 80 },
	{ "박준성" ,20025317, 83, 76, 75 },
	{ "서수원" ,20025318, 75, 68, 70 },
	{ "양민우" ,20025319, 65, 70, 80 },
	{ "양정은" ,20025320, 88, 85, 90 }
};		// 데이터 값

//            함수 선언
void sort (int *);
void copy();
int input();
void error_message();
void showmenu();
void showsubmenu();
void pass();
void grade_();

void choose_1();
void choose_2();
void choose_3();
void choose_4();

void result_1(student l[] , int *);
void result_2(student m[]);

student temp, copy_data[20]; 

int select, i, j, check=0;

int main()
{
	for (i = 0 ; i <= 19 ; i++ ){
		data[i].total = data[i].kor + data[i].eng + data[i].math;
		data[i].ave = data[i].total / 3;
	}
	grade_();
	while (1)
	{
		if (check == 0 )
		{
			showmenu();
		}
		switch (input()) 
		{
		case 1 :
			choose_1();
			check = 0;
			break; 
		case 2 :
			choose_2();
			check = 0;
			break; 
		case 3 : 
			choose_3();
			check = 0;
			break; 
		case 4 : 
			choose_4();
			check = 0;
			break; 
		case 5 : 
			return 0;
			break; 
		default :
			error_message();
			check = 1;
			break; 
		}
	} 
}

////////////////////////////////////////////////////////////
//                   메인 함수의 끝                       //
////////////////////////////////////////////////////////////


//////////////////    메세지 출력 함수    //////////////////

void showmenu()
{
	cout << "\t◆ 메뉴 ◆" << endl 
		<< "1) 과목별 입력 결과 리스트 " << endl
		<< "2) 과목별 성적순 리스트 " << endl
		<< "3) 학생 전과목 입력 결과 리스트 " << endl
		<< "4) 학생 전과목 성적순 리스트 " << endl
		<< "5) 종료 " << endl << endl
		<< "메뉴를 선택하세요 -> ";
}

void showsubmenu()
{
	cout << "\t◇과목 선택 메뉴◇" << endl
		<< "1) 국어" << endl
		<< "2) 영어" << endl
		<< "3) 수학" << endl
		<< "과목을 선택하세요 -> ";
}

void error_message()
{
	cout << "다시 입력하세요 -> ";
}

///////////////    선택 메뉴 함수    ////////////////

void choose_1()		// 1번 선택
{
	system ("cls") ;
	showsubmenu();
	while (1)
	{
		switch (input()) 
		{
		case 1 :
			cout << "이름\t번호\t국어" << endl;
			result_1(data, &data[0].kor);
			pass();
			return; 
		case 2 :
			cout << "이름\t번호\t영어" << endl;
			result_1(data, &data[0].eng);
			pass();
			return; 
		case 3 : 
			cout << "이름\t번호\t수학" << endl;
			result_1(data, &data[0].math);
			pass();
			return; 
		default :
			error_message();
			break; 
		}
	} 

}

void choose_2()		// 2번 선택
{
	system ("cls") ;
	copy();
	showsubmenu();
	while (1)
	{
		switch (input()) 
		{
		case 1 :
			system ("cls");
			sort(&copy_data[0].kor);
			cout << "이름\t번호\t국어" << endl;
			result_1(copy_data , &copy_data[0].kor);
			pass();
			return; 
		case 2 :
			system ("cls");
			sort(&copy_data[0].eng);
			cout << "이름\t번호\t영어" << endl;
			result_1(copy_data , &copy_data[0].eng);
			pass();
			return; 
		case 3 : 
			system ("cls");
			sort(&copy_data[0].math);
			cout << "이름\t번호\t수학" << endl;
			result_1(copy_data , &copy_data[0].math);
			pass();
			return; 
		default :
			error_message();
			break; 
		}
	} 
}

void choose_3()			// 3번 선택
{
	system ("cls");
	result_2(data);
	pass();
}

void choose_4()			// 4번 선택
{
	copy();
	system ("cls");
	sort(&copy_data[0].total);
	result_2(copy_data);
	pass();
}

////////////////  결과 출력 함수들  ////////////////////

void result_1(student l[] , int * n)
{
	for (i = 0 ; i <= 19 ; i++ )
		cout << l[i].name << "\t" << l[i].number << " " << *(n+(i*14)) << endl;
}

void result_2(student m[])
{
	cout << "이름\t번호\t국어\t영어\t수학\t총점\t평균\t등급" << endl;
	for (i = 0 ; i <= 19 ; i++)
	{
		cout.precision(3);
		cout.setf(ios_base::showpoint);
		cout << m[i].name << "\t" << m[i].number << " "<< m[i].kor
			 << "\t" << m[i].eng << "\t" << m[i].math << "\t" << m[i].total
			 << "\t" << m[i].ave << "\t" << m[i].grade << endl;
	}
}

/////////////////  그 밖의 함수들  /////////////////////

void sort(int * x)		// 소트 함수
{
	for (i = 1 ; i <= 19 ; i++)
	{
		for (j = 19 ; j >= i ; j--)
		{
			if ( *(x+j*14) >= *(x+(j-1)*14) )
			{
				temp = copy_data[j];
				copy_data[j] = copy_data[j-1];
				copy_data[j-1] = temp;
			}
		}
	}
}

void copy()		// 데이터 훼손을 방지하기 위한 데이터 카피
{
	for (int i = 0 ; i <= 19 ; i++ )
		copy_data[i] = data[i];
}

int input()		// 올바른 입력을 위한 입력함수
{
	cin.clear();
	while (!(cin >> select))
	{
		cin.clear();
		while (cin.get() != '\n')
			continue;
		error_message();
	}
	return select;
}

void grade_()		// 등급을 입력하는 함수
{
	for (i = 0 ; i <= 19 ; i++ )
	{
		if ( data[i].ave >= 95 && data[i].ave <=100)
			data[i].grade = "a+";
		else if ( data[i].ave >= 90 && data[i].ave < 95)
			data[i].grade = "a";
		else if ( data[i].ave >= 85 && data[i].ave < 90)
			data[i].grade = "b+";
		else if ( data[i].ave >= 80 && data[i].ave < 85)
			data[i].grade = "b";
		else if ( data[i].ave >= 75 && data[i].ave < 80)
			data[i].grade = "c+";
		else if ( data[i].ave >= 70 && data[i].ave < 75)
			data[i].grade = "c";
		else if ( data[i].ave >= 65 && data[i].ave < 70)
			data[i].grade = "d+";
		else if ( data[i].ave >= 60 && data[i].ave < 65)
			data[i].grade = "d";
		else if ( data[i].ave <= 59)
			data[i].grade = "f";
	}
}

void pass()			// 바로 넘어가지 않기 위한 함수
{
	cout << "계속 하려면 Enter 키를 누르십시오. ";
	cin.get();
	while (cin.get() != '\n')
		continue;
	system ("cls");
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:31:46
Processing time 0.0114 sec