วันอังคารที่ 31 มีนาคม พ.ศ. 2558
C# Calculate Grade T-Score (Using List Object)
Posted by
Aagkasit Tontan
at
21:23
Labels:
c#,
Grade Calculator,
Grade Calculator Custom,
Grade Calculator Dynamic,
T-Score
สมมุติ มีคะแนนนักเรียนดังนี้ คนที่ 1 มี 1 คะแนน คนที่ 2 มี 2 คะแนน คนที่ 3 มี 4 คะแนน คนที่ 4 มี 6 คะแนน คนที่ 5 มี 8 คะแนน คนที่ 6 มี 9 คะแนน ให้ตัดเกรดของนักเรียนเหล่านี้ โดยวิธีตัดเกรดด้วย T-Score ที่มาของโจทย์ : http://www.stvc.ac.th/elearning/stat/csu3.htmlใช้การคำนวณ SD จากบทความที่แล้ว C# Calculate Standard Deviation (Using List Object)
class Program
{
static void Main(string[] args)
{
//Ex2.จากข้อมูลต่อไปนี้จงหาส่วนเบี่ยงเบนมาตรฐาน 1, 2, 4, 6, 8, 9
List listScore = new List();
listScore.Add(1d);// 1, 2, 4, 6, 8, 9
listScore.Add(2d);
listScore.Add(4d);
listScore.Add(6d);
listScore.Add(8d);
listScore.Add(9d);
//1.การหาส่วนเบี่ยงเบนมาตรฐาน(S.D.) ในกรณีข้อมูลไม่ได้มีการแจกแจงความถี่
StandardDeviation sd = new StandardDeviation(listScore);
//จาก สมการ T = 10Z + 50
//1 หา z = (14- ค่าเฉลี่ยเรขาคณิต ) / SD
double sd_ = sd.Calculator();//3.22
double xbar = average(listScore);//1.5
for (int i = 0; i < listScore.Count; i++) {
double z = (listScore[i] - xbar) / sd_; //14
//Console.WriteLine("Z Score : " + z);
double t = 10 * z + 50;
Console.WriteLine(listScore[i]+" To T Score : " + t);
}
Console.ReadLine();
}
static double average(List listScore)
{
double sum = 0.0d;
int n = listScore.Count;
for (int i = 0; i < listScore.Count; i++)
{
sum = sum + listScore[i];
}
double result = sum / n;
return result;
}
}
รันแล้วเราก็จะได้ คะแนนนักเรียนออกมาจากนั้นเอาโปรแกรมตัดเกรดจากบทความ c# Grade Calculator (Using List Object) มาใช้
static void Main(string[] args)
{
//Ex2.จากข้อมูลต่อไปนี้จงหาส่วนเบี่ยงเบนมาตรฐาน 1, 2, 4, 6, 8, 9
List listScore = new List();
listScore.Add(1d);// 1, 2, 4, 6, 8, 9
listScore.Add(2d);
listScore.Add(4d);
listScore.Add(6d);
listScore.Add(8d);
listScore.Add(9d);
//ตั้งค่าเกรด
List ls = new List();
ls.Add(new Grades(49f, "F"));
ls.Add(new Grades(49.5f, "D"));
ls.Add(new Grades(55f, "D+"));
ls.Add(new Grades(60f, "C"));
ls.Add(new Grades(65f, "P"));
ls.Add(new Grades(70f, "B"));
ls.Add(new Grades(75f, "B+"));
ls.Add(new Grades(80f, "A"));
//1.การหาส่วนเบี่ยงเบนมาตรฐาน(S.D.) ในกรณีข้อมูลไม่ได้มีการแจกแจงความถี่
StandardDeviation sd = new StandardDeviation(listScore);
//จาก สมการ T = 10Z + 50
//1 หา z = (14- ค่าเฉลี่ยเรขาคณิต ) / SD
double sd_ = sd.Calculator();//3.22
double xbar = average(listScore);//1.5
for (int i = 0; i < listScore.Count; i++)
{
double z = (listScore[i] - xbar) / sd_; //14
//Console.WriteLine("Z Score : " + z);
double t = 10 * z + 50;
//Console.WriteLine(listScore[i] + " To T Score : " + t);
Console.WriteLine(listScore[i] + " To T Score : " + t + " -> grade : " + CalGrade((float)t, ls));
}
Console.ReadLine();
}
จะได้ผลเกรดดังนี้อยากได้โค้ดทั้งหมด ติดต่อผมทางได้นี้นะครับ (ไม่มีค่าใช้จ่ายใดๆแค่อยากรู้ว่ามีคนเอาใช้จริงๆหรือเปล่า)
Facebook: https://www.facebook.com/DotNetUnderLine
E-mail: agkasit.ecp7@gmail.com
สมัครสมาชิก:
ส่งความคิดเห็น (Atom)
ไม่มีความคิดเห็น:
แสดงความคิดเห็น