【问题标题】:Proper approach for grading a quiz [closed]为测验评分的正确方法[关闭]
【发布时间】:2015-06-05 19:56:54
【问题描述】:

我有一个应用程序,它在 3 周内一次提供 3 个不同的测验。它被用作内部员工竞赛,旨在提供有关客户产品之一的知识。我已经使用 .NET aspx 页面对前端进行了编码,它显示了测验。然后,我有一个用于为测验评分的课程文件。我坚持的是在课堂上存储答案的正确方法。显然,答案将是静态的,不会改变。每个测验有 5 个问题。

我想到的一种方法是在课堂上声明一些对测验进行评分的变量,每个测验每个答案一个,然后传入已完成的测验,并使用这些变量的内容对测验进行评分。这不是非常面向对象的。因此,在不使事情过于复杂的情况下,最好为每个有答案的测验创建一个类,然后我可以创建该类的一个实例并在 Class.Answer1 等中阅读?一个粗略的例子是:

public class QuizOne {
   public property answer1 = "A";
   public property answer2 = "B";
   public property answer3 = "B";
   public property answer4 = "C";
   public property answer5 = "E";
}

每次测验我都可以上一堂这样的课。然后我可以在评分类中有一些代码来查找要实例化的类,然后一旦实例化我就可以这样做:

if(quiz.answer1 == answered1){
// do something for the correct answer 
} else {
// do something for the incorrect answer
}

想法或建议?

【问题讨论】:

  • 可以把这个发给:codereview.stackexchange.com
  • @puddinman13 没有要审查的代码。这或多或少是一个programmers 问题。
  • @EBrown 我也不确定这是一个很好的程序员问题。
  • @200_success 根据Programmers HelpIf you have a question about...software requirementssoftware architecture and designalgorithm and data structure concepts all 适合这个问题。 (内容可能不是最好的,但远不是不好。)

标签: c# asp.net oop


【解决方案1】:

这是一个有点宽泛的问题,所以这个答案有点宽泛,但听起来你可以在这里进行一些正确的对象设计。

首先,我一般将Quiz(在C# 中)声明为一个类。以下内容:

public class Quiz
{
    public Guid Id { get; set; }
    public List<Question> Questions { get; set; }
}

然后,我会声明一个Question 类:

public class Question
{
    public string Title { get; set; }
    public List<Answer> Answers { get; set; }
}

最后,声明一个Answer 类:

public class Answer
{
    public string Text { get; set; }
    public int Points { get; set; }
}

应该很清楚从这里去哪里。正确答案用Points &gt; 0 表示,错误答案用Points = 0 表示。

然后,您可以在将来扩展它以用于其他事情。

您可以通过多种方式将其保存到数据库中。最简单的是两列Quiz 表,一列用于Id (uniqueidentifier),另一列用于Questions (nvarchar(max))。您可以使用内置的System.Web.Script.Serialization.JavaScriptSerializer(或System.Xml.Serialization.XmlSerializer)将其获取到数据库。

然后您根据正确性奖励Points。 (我有时将它用于项目,因为我的一些 QuizesTests 有多个 正确 答案,其中一些比其他更正确。这意味着如果答案 B 和 C 是技术上都正确,并且答案 D 是 B and C,那么答案 D 将获得更多积分,依此类推。)您也不必担心 A/B/C/D/E 这里,因为 技术上这是一个显示问题

另外,请注意:这是我通常如何解决问题的非常基本的表示,但它绝对应该让你开始。


另外,这更适合 StackExchange 站点 programmers

Why?

如果您对...有任何疑问

  • 软件要求
  • 软件架构和设计
  • 算法和数据结构概念

...

...那么您来对地方了!

【讨论】:

    【解决方案2】:

    EBrown 有一个高质量的答案,而且肯定更正确,并且将支持加权问题值。如果您在一家大公司工作,并且正在提供公司范围内的培训,这是一个更好的解决方案。听起来这不是发生在我身上的事情(我可能会弄错),所以我想我会放弃另一个快速而肮脏的选择:

    class Question{
        public string QuestionText {get; set;}
        public ICollection<string> AnswerChoices {get; set;}
        public string CorrectAnswer {get; set;}
        public string AnswerProvided {get;set;}
    }
    
    public decimal GradeQuiz(ICollection<Question> questions){
    
        if(questions.Count == 0){
            throw new InvalidOperationException("Cannot grade a quiz with no questions");
        }
    
        var correct = questions.Count(x => x.AnswerProvided == x.CorrectAnswer);
        var total = questions.Count;
        return (decimal)correct * 100 / total;
    }
    

    【讨论】:

    • 正如您所说,这是一种非常快速/简单/肮脏的方法,实际上只需很少的工作即可成功满足 OP 的要求。这是我帖子的一个很好的替代品。不过,您确实将grade 拼成了grad。 :P 不幸的是,我的答案是针对如此广泛的场景而构建的,就像我为企业环境所做的所有这些一样,而且它们有非常严格的要求。
    • 是的。你的设计更灵活、更好。但是当有像“将答案存储在类文件中”这样的 cmets 时,它让我认为这个问题不需要设计水平。感谢您发现拼写错误!
    【解决方案3】:

    我会将问题、可能的答案和正确答案封装在 QuestionAndAnswers 类中。比如:

    public class QuestionAndAnswers
    {
       private readonly Dictionary<int, string> _answers;
    
       public string Question { get; set; }
    
       public Dictionary<int, string> Answers { get { return _answers; } }
    
       public int CorrectAnswer { get; set; }
    
       // Perhaps add a grade/points enumeration and a property to use it here,
       // if some questions are worth more than others
    
       public QuestionAndAnswers()
       {
          // You would probably want to provide arguments to the constructor
          // and make the class immutable
          _answers = new Dictionary<int, string> ();
       }
    }
    

    ...其中Answers 是一个字典,其中包含“可能的答案”字符串和每个字符串的标识号(id)。您可以更进一步,获得Answer 对象的列表,但我不确定这是否必要,因为每个答案都不过是一个字符串。

    然后我会有一个Quiz 类,它会公开一个Dictionary&lt;int, QuestionAndAnswers&gt;(或IDictionary),其中int 是问题编号。我更喜欢在 QuestionAndAnswers 类中使用数字属性,因为数字实际上是测验的一个特征,而不是问题。

    【讨论】:

      猜你喜欢
      • 2015-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多