Advertisement
Need4Sleep

main.cpp (DailyC++) 7/19/12

Jul 23rd, 2012
1,029
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. ///CODED BY AARGH(cplusplus.com)
  2. /// http://www.cplusplus.com/forum/beginner/75558/
  3. #include <iostream>
  4. #include <fstream>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     char* data = "text.txt"; //use to open a text file
  10.     char student_info[50]; //holds student ID
  11.     char student_answers[20]; //stores students' answers
  12.     char answers[20]; //holds correct answers and used to compare with students' answers
  13.     double score = 0; //counts the students' score
  14.     const double max_score = 40; //sets the max score possible and used for calculations
  15.     char grade; //stores a letter grade used for output
  16.  
  17.     ifstream in(data); //text.txt must be present in same folder as this ccp file or program will not run correctly or crash.
  18.     in >> answers;
  19.     cout << "Processing student Data;" << "  " << answers << " = Correct answers.\n";
  20.  
  21.     while (in >> student_info)
  22.     {
  23.         in.get();
  24.         in.getline(student_answers, 21);
  25.         for (int i = 0; i < 20; i++)
  26.         {
  27.             if (student_answers[i] == answers[i])
  28.                 score += 2;
  29.             else if (student_answers[i] == ' ')
  30.                 ;
  31.             else
  32.                 --score;
  33.         }
  34.         double grade_scale = score / max_score * 100;
  35.         if (grade_scale > 89)
  36.             grade = 'A';
  37.         else if (grade_scale > 79 && grade_scale < 90)
  38.             grade = 'B';
  39.         else if (grade_scale > 69 && grade_scale < 80)
  40.             grade = 'C';
  41.         else if (grade_scale > 59 && grade_scale < 70)
  42.             grade = 'D';
  43.         else if (grade_scale > -40 && grade_scale < 60)
  44.             grade = 'F';
  45.         cout << endl << student_info << "\t" << student_answers << "\t" << score << " " << grade_scale << "% " << grade << endl;
  46.         score = 0;
  47.     }
  48.     char p; // used for gracefully exiting program
  49.     cout << "\nDone.  Press enter key to quit."; //trying to stay platform-independant
  50.     cin.get(p);
  51.  
  52.  
  53.  
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement