(테스트) 학점 계산 프로그램
.NET프로그래밍/C# 3.5 SP1 2009. 8. 19. 11:54 |
==> 학점계산프로그램.cs
using System;
using System.Collections.Generic;
public class 학점계산프로그램
{
public static void Main() {
//[1] Input
List<Score> sco = new List<Score>() {
new Score{번호=1, 영어=90, 일어=98},
new Score{번호=2, 영어=76, 일어=22},
new Score{번호=3, 영어=83, 일어=68}
};
//[2] Process : 총점/평균/학점
for (int i = 0; i < sco.Count; i++) {
sco[i].총점 = sco[i].영어 + sco[i].일어;
sco[i].평균 = sco[i].총점 / 2;
int 학점 = Convert.ToInt32(sco[i].평균) / 10;
switch (학점) {
case 10:
case 9: sco[i].학점 = 'A'; break;
case 8: sco[i].학점 = 'B'; break;
case 7: sco[i].학점 = 'C'; break;
default: sco[i].학점 = 'D'; break;
}
}
//[3] Output
for (int i = 0; i < sco.Count; i++) {
Console.WriteLine(
"{0,8} {1,8} {2,8} {3,8} {4,8} {5}"
, sco[i].번호, sco[i].영어, sco[i].일어
, sco[i].총점, sco[i].평균, sco[i].학점);
}
}
}
==============================================================================================
==> Score.cs
using System;
public class Score
{
public int 번호 { get; set; }
public int 영어 { get; set; }
public int 일어 { get; set; }
public int 총점 { get; set; }
public float 평균 { get; set; }
public char 학점 { get; set; }
}
'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글
81. 람다식 (0) | 2009.08.19 |
---|---|
80. 확장메서드 (0) | 2009.08.19 |
79. 초기화자(Initializer) (0) | 2009.08.18 |
알고리즘 - 12. 그룹(Group) (0) | 2009.08.18 |
78. 특성(Attribute) (0) | 2009.08.18 |