由于我假设您刚刚开始编程,因此我将分享一些建议和解决问题的一般方法。
作为一名程序员,你需要培养的最重要的技能是能够将一个复杂的问题分解成简单且易于消化的块。正如我所看到的,这个问题有 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)
你的整个程序应该只包含几个方法。任何更复杂的事情,你都想多了;)
请记住,对您的任何程序进行此练习都会有所帮助。更好的是,将这些作为注释写在源文件中,然后填写必要的代码。你会惊讶于你完成的速度有多快。