Ok Im trying to use a struct to take in input from a file "grades.txt" which looks like:
Smith 9 9.33 8 10 5.5 8 10 20 47.5 47 45 47.5 48 83 87 100 98 96 100 98 92 88 96 92 86 92 94 100 96
Jones 9 8 6 6 8 7.5 8 20 35 40 42.5 40 44 62 72 100 88 86 90 92 92 88 86 88 86 94 88 86 90....etc i don't know how many students their will be.
And I need to store them in a structre like how I have in my code...Im unsure how to get all the input to go into each of these arrays . ANy help will be greatly appreciated..heres wha i have so far.
-
#include <iostream>
-
#include <string>
-
#include <vector>
-
#include <fstream>
-
using namespace std;
-
-
//Structure for holding all the grades
-
struct Grades
-
{
-
string student;
-
float quizzes[7];
-
float projects[6];
-
float exams[2];
-
float labs[14];
-
};
-
-
int main()
-
{
-
ifstream inFile;
-
inFile.open("grades.txt");
-
if (inFile.fail()) {
-
cerr << "unable to open file input.dat for reading" << endl;
-
exit(1);
-
}
-
-
-
}
-
the student name comes first then the quizzes (7) then the Projects (6) then exams (2) then labs (14) I dont know how I'm going to get the input to go into the right arrays...Also I don't know how I will be able to take all that input at once (defferent amounts of students and their scores and get them to go into seperate structs so that the one struct doesn't have more than 1 student in it....Im kinda lost and I need some direction any help will be great. In the future of this program im going to need to output a table like this if thats any help to you:
No. –Name-- --Quiz-- -Project- -Exam- -Lab- -Total- Grade
--- ----------- -------- ---------- ------ ----- ------- -----
1. Smith 90.55 94.44 85.00 94.86 91.41 A-
2. Jones 77.50 82.04 67.00 89.57 78.88 C+
.
.
.
--- ----------- -------- ---------- ------ ----- ------- -----
Avg: ?