10v.cpp

来自「C/C++程序设计导论(第二版)》程序源文件」· C++ 代码 · 共 27 行

CPP
27
字号
// GradeStudents ()  Using the `answers' test key, grade
//  each student quiz in file STUDENTFILE. Print score.
//  ASSUMPTION: file STUDENTFILE exists and contains
// 	one record per student.
// IN:		studfile is a string file name
//		answers contains (size) test key answers
//		size is the size of the answers and summary arrays
// OUT:  summary will be a count table of correct answers.
void  GradeStudents (string studfile, char answers[ ],
						int summary[ ], int size)
{	ifstream studentfile_in (studfile, ios::in);
	int id, score, ans;
	char thisanswer;
	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, update grade
				summary[ans]++;				// and tabulate
			}	
	   }					// end of loop over answers (ans)
	   cout << "student: "<< id <<"  score: " << score << endl;
	}  					 // end of loop over students
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?