1

2つのtxtファイルが互いに比較されているコードを書き込もうとしています。1つのテキストファイルには「TFTTFFT」のような答えがあり、他のtxtファイルには「1234TT-FFT」のようなIDを含む結果があります。クレイジーな部分は、正解ごとに生徒が4ポイントを獲得し、不正解ごとに生徒が得られることです。 -1を取得し、回答がない場合はすべて、この場合はダッシュ(-)で表され、生徒はゼロになります。このためのコードを作成するにはどうすればよいですか?助けていただければ幸いです。ファイルを開いて適切な変数に格納することはほぼ完了しているので、これをコーディングするために必ずしも誰かが必要なわけではありません。これを実行する方法についてのフィードバックだけがいいでしょう。前もって感謝します。

更新:コード全体を改訂し、検討のために提出します。Joshに感謝し、これまでに貢献してくれたすべての人に感謝します。改訂されたコーディングについて皆さんがどう思うか、さらに教えてください。

更新:プログラムが機能していません:(

4

2 に答える 2

0
    Dim answers As String = 'Text from the answor file
    Dim student As String = 'Text from the student file

    ' a will be used to hold the first char from the answers file
    ' s will be used to hold the first char from the student file
    Dim a As String
    Dim s As String

    ' veriable that holds the student grad
    Dim grade As Integer = 0

    ' loop while we still have an answer
    While answers.Length > 0

        ' get the first answer and student respond
        a = answers.First
        s = student.First

        ' compare the two and update the student grade accourdingly
        If a = "-" Then
            grade = grade - 1

        ElseIf a = s Then
            grade = grade + 4
        Else
            grade = grade - 1
        End If

        ' remove the first answer from the two strings
        answers = answers.Substring(1)
        student = student.Substring(1)
    End While


    return grade
于 2012-10-21T07:50:15.603 に答える
0

あなたがプログラミングを始めたばかりだと想定しているので、問題を解決するためのアドバイスと一般的なアプローチを共有します。

プログラマーとして開発する必要がある最も重要なスキルは、複雑な問題を単純で消化しやすいチャンクに分解できることです。私が見ているように、この問題には 3 つの個別の部分があります。これらを疑似コードで表現してみます。

ファイルの読み取りと解析

Open (Answer Key File)

Read All Text From (Answer Key File) into (String)

Convert (String) into array of characters as (Answer Key Array)

Close (Answer Key File)

Open (Student's File)

Read All Text From (Student's File) into (String)

Extract (Student ID) from (String)

Extract (Student's Answers) from (String)

Convert (Student's Answers) to Character Array as (Student Answers Array)

Close (Student's File)

キーに対する学生の回答を比較し、学生のスコアを計算する

Set (Student Score) equal to '0'

FOR EACH (Answer) in (Student's Answers Array)

   Get (Key) from (Answer Key Array) at (Current Loop Index)

   IF (Answer) equals [NO_ANSWER] THEN
      Continue

   IF (Answer) equals (Key) THEN
      Add 4 to (Student Score)
   ELSE
      Subtract 1 from (Student Score)

プログラム全体には、いくつかのメソッドのみを含める必要があります。もっと複雑なものは何でも、あなたはそれを考えすぎています;)

どのプログラムでも、この演習を実行すると役立つことを忘れないでください。さらに良いのは、これらをソース ファイルにコメントとして書き込んでから、必要なコードを記入することです。驚くほど早く作業を完了できます。

于 2012-10-21T01:57:12.583 に答える