统计学分成绩

 1 using System;
 2 using System.Collections.Generic;
 3 using System.IO;
 4 using System.Linq;
 5 using System.Text;
 6 using System.Threading.Tasks;
 7 
 8 namespace Sum
 9 {
10     class Program
11     {
12         static void Main(string[] args)
13         {
14             //获取总数居
15             string[] TotalData = File.ReadAllLines(@"D:sum	emp.txt");
16 
17             #region 声明数组
18             int number = 15;
19 
20             double[] Credit = new double[] { 4, 4.5, 4, 2, 5, 4.5, 7.5, 4.5, 2, 2, 2, 2, 4.5, 4, 2 };
21 
22             double[] Score = new double[number];
23 
24             double[] ScoreTotal = new double[number];
25 
26             double TotalCredit = 0.0;
27 
28             double AllStudentScore = 0.0;
29 
30             double FinalResult = 0.0;
31 
32             StringBuilder strFinalResult = new StringBuilder();
33             #endregion
34 
35             #region 获取数据
36 
37             for (int j = 0; j < TotalData.Length; j++)
38             {
39                 #region 抽取成绩信息
40                 for (int i = 0; i < number; i++)
41                 {
42                     Score[i] = Convert.ToDouble(TotalData[j].Replace('	', '&').Split(new char[] { '&' })[i].ToString().Trim());
43                 }
44                 #endregion
45 
46                 #region 部分数据计算
47                 //学分乘以成绩
48                 for (int i = 0; i < number; i++)
49                 {
50                     //每一个学生总合
51                     ScoreTotal[i] = Credit[i] * Score[i];
52                 }
53 
54                 //所有学生学分乘以成绩总合
55                 for (int i = 0; i < number; i++)
56                 {
57                     AllStudentScore += ScoreTotal[i];
58                 }
59 
60                 //总学分
61                 for (int i = 0; i < number; i++)
62                 {
63                     TotalCredit += Credit[i];
64                 }
65                 #endregion
66 
67                 #region 最终计算结果
68                 FinalResult = AllStudentScore / TotalCredit;
69                 #endregion
70 
71                 #region 输出结果
72                 string strPath = @"D:sum
esult.txt";
73                 StreamWriter fs = new StreamWriter(strPath, false, System.Text.Encoding.Default);
74                 //string num = Convert.ToString(j+1)+":";
75                 strFinalResult.Append(FinalResult.ToString() + System.Environment.NewLine);
76                 fs.WriteLine(strFinalResult);
77                 fs.Close();
78                 #endregion
79             }
80             #endregion
81 
82             Console.WriteLine(@"计算结束,请查看 [ D:sum
esult.txt ] 文件中的内容!");
83 
84             Console.ReadKey();
85         }
86     }
87 }
原文地址:https://www.cnblogs.com/KTblog/p/4823138.html