在C#中创建一个测验 [英] Creating a quiz in C#

查看:86
本文介绍了在C#中创建一个测验的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,我正在为学校做一个项目(所以我想要建议或例子,但需要自己做这项工作)。我在youtube上观看视频的唯一途径。现在我需要一些更具体的帮助。下面是对作业的描述,然后描述我在哪里以及我在寻找什么。一切都在C#

完成作业:

程序应该一次显示一个问题和可能的答案,并接受用户的回答。如果答案是正确的,程序应该继续下一个问题。如果不正确,请存储第二次尝试的问题并继续下一个问题。当问题列表结束时,之前错过或回答错误的问题应按原始顺序再次显示。为每类问题保留正确答案的计数,并在两次尝试后显示最终计数。此外,必要时,在第二轮提问中显示正确答案。



我尝试过:



我第一次做这种形式的编程是3周前所以我非常新(有编程CNC机器的经验但完全不同)。我已经设法将问题全部解决了,当用户回答问题时,它可以注册,如果它是正确的或不正确的。我试图弄清楚如何让它循环第二次(在问到所有问题之后)只询问错误回答的问题,然后在第二次循环结束时(如果需要)给出数字纠正总数。我尝试使用Correct = 1然后在程序结束时添加一行,以便添加正确,但它似乎只注册1而不是它应该的10倍。

任何帮助非常感谢。

解决方案

这是一般性指导:在第一轮问题中,添加一些未正确回答的问题列表。在第一次传递之后,迭代这个问题列表并再次询问它们。


回答你的评论:

一个计数器只是你的一个int变量可以增加。

这里有一些链接,你应该花些时间来基本了解OOP编程:

类(C#编程指南)

C#列表示例

创建多个使用C#中的数组进行选择测验

这些只是一些常规指南,向您展示如何以OOP方式构建程序;它们不是你可以复制/粘贴的直接解决方案。

你应该先学习一些课程和清单,然后拿笔和纸,用新获得的知识写下这个过程。由于我们不知道您已经知道多少c#开发,因此很难给您有意义的指导;唯一可以说的是,你第一次考虑设计你的程序的方式会很快来咬你。

最后,这里有一些通用算法来帮助你开始:

  int  counter =  0 ; 
列表<问题> questions = new List< Question>();
// 在此列表中填写问题
列表<问题> wrongAnswered = new List< Question>();
每个(问题问题 问题){
// 向用户提出问题并等待答案
// 如果答案是正确的 - >递增计数器1
// 如果答案不正确,请将问题添加到错误的答案列表中
}
for each(问题问题 in wrongAnswered){
// 向用户提出问题并等待答案
< span class =code-comment> // 如果答案是正确的 - >递增计数器1
}
// 将结果(计数器)显示给用户



希望这会有所帮助。亲切。


如果没有为你工作,我会给你一些我会用的方法。我假设你没有连接到数据库。





    我会创建一个数据结构

  • 它将包含问题
  • 它将包含您想要服务器的任何内容作为答案
  • 它将包含一个标记问题正确的字段
  • 它可能还包含用于计算尝试次数等的字段,具体取决于您还想做什么。




这些结构的数组可以通过任何你想要的方式进行处理。



学习理解,创建和使用数据结构将为你提供很好的服务!结果

Greetings, I am working on a project for school (so I would like advice or examples but need to do the work myself). The only way I have gotten as far as I have watching videos on youtube. Now I need some more specific help. Below is a description of the assignment, then a description of where I am at and what I am looking for. Everything is done in C#
Assignment:
The program should display the questions, one at a time, and possible answers, and accept an answer from the user. If the answer is correct, the program should go on to the next question. If it is incorrect, store the question for the second attempt and go on to the next question. When the list of questions has ended, the questions that were missed previously, or answered incorrectly, should be displayed again, in their original order. Keep a count of the correct answers for each category of questions and display the final count after two attempts. Also, display the correct answer, when necessary, in the second round of questioning.

What I have tried:

The first time I have ever done this form of programming is 3 weeks ago so I am VERY new (have experience programming CNC machines but that is entirely different). I have managed to get the questions all in and when they are answered by the user it can register if it is correct or incorrect. I am trying to figure out how to get it to loop around a second time (after all the questions have been asked) to ask only the questions that were answered incorrectly, then at the end of the second loop (if necessary) give the number correct out of the total. I tried having Correct = 1 then at the end of the program put a line in for it to add "Correct" up but it only seems to register 1 and not the 10 times it should.
Any help would be greatly appreciated.

解决方案

Here's a general guidance: on the first pass of questions, add to a list of questions those which have not been answered correctly. After the first pass, iterate over this questions list and ask them a second time.


Answering to your comment:
A counter is just an int variable that you can increase.
Here are a few links, you should take time to get a basic understanding of OOP programming:
Classes (C# Programming Guide)
C# Lists examples
Create a Multiple Choice Quiz with arrays in C#
These are only some general guidances to show you how you can structure your program in an OOP way; they are not a direct solution that you can copy/paste.
You should first study a little bit of classes and lists, then take a pen and paper and write down the process using your newly acquired knowledge. It is quite hard to give you meaningful guidance since we do not know how much of c# development you already know; the only thing that can be said is that the way you first considered to architect your program will come and bite you very quickly.
Finally, here is some kind of general algorithm to help you started:

int counter = 0;
List<Question> questions = new List<Question>();
// Fill this list with questions
List<Question> wrongAnswered = new List<Question>();
for each (Question question in questions) {
  // Present the question to the user and wait for the answer
  // If answer is correct -> increment counter by 1
  // If answer is incorrect, add the question to the wrongAnswered list
}
for each (Question question in wrongAnswered) {
  // Present the question to the user and wait for the answer
  // If answer is correct -> increment counter by 1
}
// Present the result (counter) to the user


Hope this helps. Kindly.


Without doing the work for you, I'll give you some approaches I would use. I'm assuming you're NOT connected to a database.


    I would create a data structure
  • It would contain the question
  • It would contain whatever you want to server as the answer
  • It would contain a field to mark question correct
  • It might also contain fields for counting the number of tries, etc., depending upon what else you'd like to do.


An array of these structures can be gone through and handled any way you wish.

Learning to understand, create and use data structures will server you very well !


这篇关于在C#中创建一个测验的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆