Loading...
PHP 를 이용하여 간단하게 만든 총 학점 출력 프로그램
REDINFO
약 1년전 2022-08-28 22:25:39

대학교 시절 학점이 그렇게 좋지 않아 만들기 싫었지만 우연히 학점 계산방법 소개글을 보다가 학점 출력 프로그램을 만들어 보았다. 

 

본 프로그램은 하단 블로그를 통해 학점 계산 방법을 숙지한 뒤 간단하게나마 만들어 보았으니 참고 바라며 해당 프로그램은 스타일을 고려하지 않을려다가 조금이나나 CSS를 넣었기때문에 가독성을 위한 수정이 필요할 수 있다. 

 
학점은 처음이지? 학점계산기 사용법 및 학점관리 노하우
대학 신입생이 된 지 엊그제 같은데, 밀려드는 과제를 마감 기한에 맞춰 정신 없이 제출하다 보니 어느덧 시험까지 마치고 한 학기가 끝나버렸습니다. 처음 해보는 대학생활이 낯설어 설령 학점관리에 소홀했더..
www.sindohblog.com/1463

 

 

총 학점 출력 프로그램 소스
<?php 
# 학점 점수 참고 배열 정의
$grades = array(
	'A+'=>4.5,
	'A'=>4.0,
	'B+'=>3.5,
	'B'=>3.0,
	'C+'=>2.5,
	'C'=>2.0,
	'D+'=>1.5,
	'D'=>1.0,
	'F'=>0
);
asort($grades); // 점수 오름차순으로 정의

# 학생 정보 배열 정의
$student = array(
	array(
		'name'=>'홍길동'
		,'subject'=>array(
			'PHP'=>array('score'=>4.2,'grades'=>3),
			'파이썬'=>array('score'=>2.2,'grades'=>3),
			'자바'=>array('score'=>3.2,'grades'=>3),
			'자바스크립트'=>array('score'=>4.2,'grades'=>3),
			'C언어'=>array('score'=>3.2,'grades'=>3),
			'MFC'=>array('score'=>1.0,'grades'=>3),
			'출생의비밀'=>array('score'=>4.5,'grades'=>3),			
		)
	),	
	array(
		'name'=>'전우치'
		,'subject'=>array(
			'PHP'=>array('score'=>4.5,'grades'=>3),
			'파이썬'=>array('score'=>4.5,'grades'=>3),
			'자바'=>array('score'=>4.5,'grades'=>3),
			'자바스크립트'=>array('score'=>4.5,'grades'=>3),
			'C언어'=>array('score'=>4.5,'grades'=>3),
			'MFC'=>array('score'=>4.5,'grades'=>3),			
			'비쥬얼베이직'=>array('score'=>4.2,'grades'=>3),			
		)
	),						
);

# 테이블 스타일 정의 
$arrStyle = array(
	'h1{ border-bottom:solid 5px #333;border-top:solid 5px #333;}',
	'th,td{ padding:5px 10px; }',
	'th{ background-color:#eee; }',
	'td{ text-align:center; }',
);
echo '<style>'.implode("\n",$arrStyle).'</style>';


$arrSumStudent = array();
echo '<h1>REDINFO 과목별 총 학점관리 시스템 (총 '.number_format(count($student)).'명)</h1>';
foreach($student as $k=>$v){

	$arrSumStudent[$k] = array();
	$arrSumStudent[$k]['subjectCount'] = count($v['subject']);
	$arrSumStudent[$k]['subjectScoreSum'] =  $arrSumStudent[$k]['subjectGradesSum'] = $arrSumStudent[$k]['gradesSum'] = 0; //(성적별 총합계 = 신청학점총합계 = 총합계)

	echo '<h2>['.$v['name'].'] 학생 과목별 학점(총 '.number_format($arrSumStudent[$k]['subjectCount']).'과목)</h2>';
	echo '<table>';
	echo ' <tr><th width="*">과목명</th><th width="*">성적</th><th width="80">점수</th><th width="80">신청학점</th></tr>';

	foreach($v['subject'] as $sk=>$sv){

		$arrSumStudent[$k]['subjectScoreSum'] += $sv['score']*$sv['grades'];
		$arrSumStudent[$k]['subjectGradesSum'] += $sv['grades'];

		$gradesClass = 'F';
		foreach($grades as $ssk=>$ssv){
			if( $sv['score'] >= $ssv ){ $gradesClass = $ssk; }
			else{ break; }
		}

		echo '<tr>';
		echo '<td>'.$sk.'</td>';
		echo '<td>'.$gradesClass.'</td>';
		echo '<td>'.number_format($sv['score'],1).'</td>';
		echo '<td>'.$sv['grades'].'</td>';
		echo '</tr>';
	}

	$arrSumStudent[$k]['gradesSum'] = round($arrSumStudent[$k]['subjectScoreSum']/$arrSumStudent[$k]['subjectGradesSum'],1);


	echo '<tr>';
	echo '<th colspan="2">총점</th>';
	echo '<th>'.number_format($arrSumStudent[$k]['subjectScoreSum'],1).'</th>';
	echo '<th>'.$arrSumStudent[$k]['subjectGradesSum'].'</th>';
	echo '</tr>';
	echo '</table>';
}


echo '<h1>REDINFO 학생별 총 학점관리 시스템 (총 '.number_format(count($student)).'명)</h1>';
echo '<table>';
echo ' <tr><th width="30">No</th><th width="*">이름</th><th width="80">성적</th><th width="80">점수</th><th width="*">신청학점</th></tr>';
foreach($student as $k=>$v){

	$gradesSum = $arrSumStudent[$k]['gradesSum'];
	$gradesClass = $arrSumStudent[$k]['gradesClass'];
	$subjectGradesSum = $arrSumStudent[$k]['subjectGradesSum'];

	$gradesClass = 'F';
	foreach($grades as $ssk=>$ssv){
		if( $gradesSum >= $ssv ){ $gradesClass = $ssk; }
		else{ break; }
	}

	echo '<tr>';
	echo '<td style="text-align:center;">'.($k+1).'</td>';
	echo '<td style="text-align:center;">'.$v['name'].'</td>';
	echo '<td style="text-align:center;">'.number_format($gradesSum,1).'</td>';
	echo '<td style="text-align:center;">'.$gradesClass.'</td>';
	echo '<td style="text-align:center;">'.$subjectGradesSum.'</td>';
	echo '</tr>';
	
}
echo '</table>';

 

 

결과
이 포스트글이 도움이 되었나요?
5
카테고리 연관글

Comment

댓글작성

0(500) | 1(30)