Inputing data from .txt to array.
-
I have a program that is able to take the numbers out of the .txt if it is just a list of numbers. Problem is, I have a file with Names before the grades. I believe i need to set up another array inside the first one to fill with names. The .txt file will look like: Name grade grade grade grade grade grade grade grade grade grade Name ... Have 15 Names with 10 grades under each. I guess what i'm trying to do is take the strings out of the file. Is there a way to take the strings(there is a string every 11 lines) Here is what i have now: #include #include #include #include #include #include using namespace std; const int TESTS = 10; const int STUDENTS = 15; void displayGrades( int [][TESTS] ); void getGrades( int [][TESTS]); int main() { int data[STUDENTS][TESTS] = {0}; getGrades( data ); cout <> data[student][test]; } } } void displayGrades( int data[][TESTS] ) { double testTotal = 0.0; double classTotal = 0.0; double squared = 0.0; double var = 0.0; double sdev = 0.0; int mxm = data[0][0]; int min = data[0][0]; cout << "\nGrade summary" << endl; cout << "--------------" << endl; cout << left << setw(7) << "Student" << right << setw(5) << right << "Ex1" << setw(7) << "Ex2" <
-
I have a program that is able to take the numbers out of the .txt if it is just a list of numbers. Problem is, I have a file with Names before the grades. I believe i need to set up another array inside the first one to fill with names. The .txt file will look like: Name grade grade grade grade grade grade grade grade grade grade Name ... Have 15 Names with 10 grades under each. I guess what i'm trying to do is take the strings out of the file. Is there a way to take the strings(there is a string every 11 lines) Here is what i have now: #include #include #include #include #include #include using namespace std; const int TESTS = 10; const int STUDENTS = 15; void displayGrades( int [][TESTS] ); void getGrades( int [][TESTS]); int main() { int data[STUDENTS][TESTS] = {0}; getGrades( data ); cout <> data[student][test]; } } } void displayGrades( int data[][TESTS] ) { double testTotal = 0.0; double classTotal = 0.0; double squared = 0.0; double var = 0.0; double sdev = 0.0; int mxm = data[0][0]; int min = data[0][0]; cout << "\nGrade summary" << endl; cout << "--------------" << endl; cout << left << setw(7) << "Student" << right << setw(5) << right << "Ex1" << setw(7) << "Ex2" <