Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///CODED BY AARGH(cplusplus.com)
- /// http://www.cplusplus.com/forum/beginner/75558/
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main()
- {
- char* data = "text.txt"; //use to open a text file
- char student_info[50]; //holds student ID
- char student_answers[20]; //stores students' answers
- char answers[20]; //holds correct answers and used to compare with students' answers
- double score = 0; //counts the students' score
- const double max_score = 40; //sets the max score possible and used for calculations
- char grade; //stores a letter grade used for output
- ifstream in(data); //text.txt must be present in same folder as this ccp file or program will not run correctly or crash.
- in >> answers;
- cout << "Processing student Data;" << " " << answers << " = Correct answers.\n";
- while (in >> student_info)
- {
- in.get();
- in.getline(student_answers, 21);
- for (int i = 0; i < 20; i++)
- {
- if (student_answers[i] == answers[i])
- score += 2;
- else if (student_answers[i] == ' ')
- ;
- else
- --score;
- }
- double grade_scale = score / max_score * 100;
- if (grade_scale > 89)
- grade = 'A';
- else if (grade_scale > 79 && grade_scale < 90)
- grade = 'B';
- else if (grade_scale > 69 && grade_scale < 80)
- grade = 'C';
- else if (grade_scale > 59 && grade_scale < 70)
- grade = 'D';
- else if (grade_scale > -40 && grade_scale < 60)
- grade = 'F';
- cout << endl << student_info << "\t" << student_answers << "\t" << score << " " << grade_scale << "% " << grade << endl;
- score = 0;
- }
- char p; // used for gracefully exiting program
- cout << "\nDone. Press enter key to quit."; //trying to stay platform-independant
- cin.get(p);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement