Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main()
- {
- int i, j;
- char id[10][5], studentAns[10][10];
- float totalMarks[10] = {0};
- char trueAnswer[10] = { 'A','C','D','A','A','B','B','D','C','D' };
- ifstream answerFile("studAnswers.txt"); //start read
- if(!answerFile) //check file availability
- {
- cout << "File \"studAnswers.txt\" not found!";
- return 0;
- }
- for(i=0; i<10; i++) //process read
- {
- answerFile >> id[i];
- for(j=0; j<10; j++)
- answerFile >> studentAns[i][j];
- }
- answerFile.close(); //end read
- ofstream resultFile("studResult.txt"); //start write
- for(i=0; i<10; i++) //process write
- {
- resultFile << id[i];
- for(j=0; j<10; j++)
- {
- if( studentAns[i][j] == trueAnswer[j] )
- {
- resultFile << " T ";
- totalMarks[i] ++;
- }
- else
- resultFile << " F ";
- }
- resultFile << "Marks: " << totalMarks[i]/10*5 << "%" << "\n";
- }
- resultFile.close(); //end write
- cout << "Output printed in \"studResult.txt\"";
- return 0;
- }
Add Comment
Please, Sign In to add comment