aprsc7

Array

Nov 30th, 2019 (edited)
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int i, j;
  9.     char id[10][5], studentAns[10][10];
  10.     float totalMarks[10] = {0};
  11.     char trueAnswer[10] = { 'A','C','D','A','A','B','B','D','C','D' };
  12.  
  13.     ifstream answerFile("studAnswers.txt"); //start read
  14.  
  15.     if(!answerFile) //check file availability
  16.     {
  17.         cout << "File \"studAnswers.txt\" not found!";
  18.         return 0;
  19.     }
  20.  
  21.     for(i=0; i<10; i++) //process read
  22.     {
  23.         answerFile >> id[i];
  24.         for(j=0; j<10; j++)
  25.             answerFile >> studentAns[i][j];
  26.     }
  27.  
  28.     answerFile.close(); //end read
  29.  
  30.     ofstream resultFile("studResult.txt"); //start write
  31.  
  32.     for(i=0; i<10; i++) //process write
  33.     {
  34.         resultFile << id[i];
  35.         for(j=0; j<10; j++)
  36.         {
  37.             if( studentAns[i][j] == trueAnswer[j] )
  38.             {
  39.                 resultFile << " T ";
  40.                 totalMarks[i] ++;
  41.             }
  42.             else
  43.                 resultFile << " F ";
  44.         }
  45.  
  46.         resultFile << "Marks: " << totalMarks[i]/10*5 << "%" << "\n";
  47.     }
  48.  
  49.     resultFile.close(); //end write
  50.  
  51.     cout << "Output printed in \"studResult.txt\"";
  52.     return 0;
  53. }
Add Comment
Please, Sign In to add comment