📄 10i.cpp
字号:
// gradtest.cpp Grade student quiz answers in file `students.txt' against
// the key in disk file `key.txt'. Report each student's score and a class
// summary of the number correct for each question.
#include <iostream.h>
#include <fstream.h>
const int SIZE = 5;
void main ()
{ ifstream keyfile_in ("key.txt", ios::in);
ifstream studentfile_in ("students.txt", ios::in);
char answers[SIZE], thisanswer;
int ans, summary[SIZE] = {0, 0, 0, 0, 0}, id, n, score;
for (n=0; n<SIZE; n++)
keyfile_in >> answers[n]; // input answer key array
while (studentfile_in >> id) // loop over students
{ score = 0; // assume a zero score
for (ans=0; ans<SIZE; ans++) // loop over answers
{ studentfile_in >> thisanswer; // get next answer
if (thisanswer==answers[ans]) // is it right?
{ score++; // if so, increase grade
summary[ans]++; // and tabulate
}
} // end of loop over answers (ans)
cout << "student: "<< id <<" score: " << score << endl;
} // end of loop over students (while)
cout << " correct answers sumary for each question; ";
for (n=0; n<SIZE; n++)
cout <<summary[n] << " "; // output summary table
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -