Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <algorithm>
- #include <time.h>
- #include <string>
- #include <vector>
- using namespace std;
- /*
- METHODS
- */
- void createFile();
- void readFile();
- void getResults();
- void printResults();
- void getID();
- /*
- Variables
- */
- const char possibleAnswers[] = "TFTFTFTF ";
- const string answers = "TTFTFTFFTFTTFFFTTFTF";
- vector <string> students;
- vector <int> scores;
- int main()
- {
- createFile();
- readFile();
- getResults();
- printResults();
- }
- void createFile()
- {
- ifstream file("scores.txt");
- if(file.good())
- {
- }
- else
- {
- ofstream file;
- file.open("scores.txt", ios::in | ios::app);
- string tAnswers;
- char numberOrLetter;
- int counter = 1;
- srand (time(NULL));
- for(int i = 0; i < 150; i++)
- {
- for (int i = 0; i < 8; i++)
- {
- numberOrLetter = rand() % 26 + 65;
- file << numberOrLetter;
- counter++;
- }
- file << " ";
- for(int i = 0; i < 20; i++)
- {
- tAnswers[i] = possibleAnswers[rand() % 9];
- file << tAnswers[i];
- }
- file << "\n";
- }
- }
- }
- void readFile()
- {
- string line;
- ifstream file("scores.txt");
- if(file)
- {
- while(getline(file, line))
- {
- students.push_back(line);
- }
- }
- }
- void getResults()
- {
- string found;
- string foundSubString;
- int score = 0;
- for(int i = 0; i < 150; i++)
- {
- found = students[i];
- foundSubString = found.substr (9,20);
- for(int x = 0; x < 20; x++)
- {
- if(foundSubString[x] == answers[x])
- {
- score += 2;
- }
- else if(found[x] != answers[x] && found[x] != ' ')
- {
- score -=1;
- } else if(found[x] = ' ') {
- //no score change
- }
- }
- scores.push_back(score);
- score = 0;
- }
- }
- void printResults()
- {
- string student;
- string id;
- char grade;
- cout << "||--------------------------------------------------------------||" << endl;
- cout << "||---------------------------RESULTS----------------------------||" << endl;
- cout << "|| ||" << endl;
- for(int i = 0; i < students.size(); i++)
- {
- student = students[i];
- id = student.substr(0, 8);
- if(scores[i] >= 35)
- {
- grade = 'A';
- }
- else if (scores[i] >= 30 && scores[i] < 35)
- {
- grade = 'B';
- }
- else if (scores[i] >= 25 && scores[i] < 30)
- {
- grade = 'C';
- }
- else if (scores[i] >= 20 && scores[i] < 25)
- {
- grade = 'D';
- }
- else if (scores[i] >= 15 && scores[i] < 20)
- {
- grade = 'E';
- }
- else
- {
- grade = 'F';
- }
- cout << "||\t Student ID: " << id << "\tScore: " << scores[i] << "\tGrade: " << grade << "\t||" <<endl;
- }
- cout << "||--------------------------------------------------------------||" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment