Question: Can someone help me with my code, I'm supposed to enter the test key and have the student.txt file come up in my output with
Can someone help me with my code, I'm supposed to enter the test key and have the student.txt file come up in my output with students names and answers. Here is a copy of my code and the output.
#include
using namespace std;
void readDataFromFile(); void calculateResult(); void displayResult(); void removeCharsFromString(string &str); //Name of the file char file_name[20] = "student.txt"; int total_record = 0;
char answer_keys[10];
struct Student { int stud_id; string full_name, answers; char letter_grade; double total_points, avg;
int operator=(const Student& s) { this->stud_id = s.stud_id; this->full_name = s.full_name; this->letter_grade = s.letter_grade; this->answers = s.answers; this->total_points = s.total_points; this->avg = s.avg; return 0; }
}record[50];
void StudentSort() { int i, j; Student check;
for (i = 1; i int main() { readDataFromFile(); //Promt user for answer key cout > answer_keys[i]; } calculateResult(); displayResult(); return 0; } void readDataFromFile() { //File information ifstream ifile; ifile.open(file_name); total_record = 0; string line = ""; while (!ifile.eof()) { getline(ifile, line); string id = line.substr(0, line.find(" ")); record[total_record].stud_id = atoi(id.c_str()); record[total_record].full_name = line.substr(line.find(" ") + 1); line = ""; getline(ifile, line); record[total_record].answers = line; total_record++; } if (total_record > 0) total_record--; ifile.close(); StudentSort(); } void calculateResult() { cout for (int i = 0; i int points = 0; for (int j = 0; j if (record[i].avg >= 90) { record[i].letter_grade = 'A'; } else if (record[i].avg >= 80 && record[i].avg = 70 && record[i].avg = 60 && record[i].avg cout } void displayResult() //Display { cout for (int i = 0; i cout for (int i = 0; i cout for (int i = 0; i void removeCharsFromString(string &str) { str.erase(remove(str.begin(), str.end(), ' '), str.end()); } and this is the error I get.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
