C# 在streamwriter中使用answer循环时计算分数?
有人能看看我的代码吗?我如何在循环时计算分数,或者我可以从StreamWriter获取行并放置子字符串? 我一直把它弄得越来越乱。。。我需要像这样展示它 得分A的学生得了多少分? 得了B的学生得了多少?> 得到C的学生有多少个> 得到d的学生。。。f、C# 在streamwriter中使用answer循环时计算分数?,c#,loops,streamwriter,C#,Loops,Streamwriter,有人能看看我的代码吗?我如何在循环时计算分数,或者我可以从StreamWriter获取行并放置子字符串? 我一直把它弄得越来越乱。。。我需要像这样展示它 得分A的学生得了多少分? 得了B的学生得了多少?> 得到C的学生有多少个> 得到d的学生。。。f、 using (StreamReader reader = new StreamReader("Student.txt")) { StreamWriter output = new StreamWriter("Result.txt");
using (StreamReader reader = new StreamReader("Student.txt"))
{
StreamWriter output = new StreamWriter("Result.txt");
String line;
line = reader.ReadLine();
while (line != null)
{
String name = line.Substring(0, 9);
String Asg1 = line.Substring(10, 3);
String Asg2 = line.Substring(16, 3);
String Test = line.Substring(22, 3);
String Quiz = line.Substring(28, 3);
String Exam = line.Substring(34, 3);
int intAsg1 = int.Parse(Asg1);
int intAsg2 = int.Parse(Asg2);
int intTest = int.Parse(Test);
int intQuiz = int.Parse(Quiz);
int intExam = int.Parse(Exam);
int percentAsg1 = (intAsg1 * 25) / 100;
int percentAsg2 = (intAsg2 * 25) / 100;
int percentTest = (intTest * 10) / 100;
int percentQuiz = (intQuiz * 10) / 100;
int percentExam = (intExam * 30) / 100;
// this part i dont get it~
**String Grade;
if (overallScore >= 70)
{
Grade = "A";
}
else if (overallScore >= 60)
{
Grade = "B";
}
else if (overallScore >= 50)
{
Grade = "C";
}
else if (overallScore >= 40)
{
Grade = "D";
}
else
{
Grade = "F";
}
}
}
它没有循环
while !reader.EndOfStream
{
/*now check each Readline.
parse each line and create a new grade object for
each iteration and add to collection*/
}
用于存储每个学生数据的自定义类:
public class grade
{
public int asg1{ get; set; }
public int asg2{ get; set; }
public int test{ get; set; }
public int quiz{ get; set; }
public int exam{ get; set; }
//whatever else you need
}
等级集合:
var grades = New List<grade>
var等级=新列表
它没有循环
while !reader.EndOfStream
{
/*now check each Readline.
parse each line and create a new grade object for
each iteration and add to collection*/
}
用于存储每个学生数据的自定义类:
public class grade
{
public int asg1{ get; set; }
public int asg2{ get; set; }
public int test{ get; set; }
public int quiz{ get; set; }
public int exam{ get; set; }
//whatever else you need
}
等级集合:
var grades = New List<grade>
var等级=新列表
我认为除了纠正readline循环之外,您还需要一个类来保存结果
public class Student
{
public string Name { get; set; }
public List<Grade> Grades { get; set; }
}
公共班级学生
{
公共字符串名称{get;set;}
公共列表等级{get;set;}
}
然后在开始循环之前创建一个列表
var students = new List<Student>();
var students=newlist();
然后在每次迭代中添加到列表中我认为除了更正readline循环之外,您还需要一个类来保存结果
public class Student
{
public string Name { get; set; }
public List<Grade> Grades { get; set; }
}
公共班级学生
{
公共字符串名称{get;set;}
公共列表等级{get;set;}
}
然后在开始循环之前创建一个列表
var students = new List<Student>();
var students=newlist();
然后在每次迭代中添加到列表中以获得最佳答案。你能从文件中发布一行样本吗?你能试着让你的问题更清楚一点吗?在我得到分数后,我想把它放在数组中,这样我就可以计算“分数”有多少学生能得到最好的答案?你能从文件中发布一个样本行吗?你能试着让你的问题更清楚一点吗?在我得到分数后,我想把它放在数组中,这样我就可以计算“分数”有多少学生能得到。那么我如何计算总分呢?那么我如何计算总分呢?在那里