|
| MrExist (2) | |
| So i started off on the wrong foot with this assignment, i started by using a set ammount of students, but i did it wrong cause i won't know how many students there will actually be. the project is going to open a txt file that contains information such as: 3 6 600 1479 98 90 78 89 90 99 1785 79 88 89 90 93 75 1396 88 85 98 87 92 76 the 3 stands for number of student, 6 for how many graded tests and 600 for over all points. (the file will be different from what the instructor will use, and will have more or less students then example file) my question is how do i get my program to read in the data for each student without having a set number of students. here is what i have so far and reading the file works, but this is where i am stuck at, please help.. #include <iostream> #include <fstream> #include <iomanip> using namespace std; #define MAX_NAME 32 int main() { char fileName[MAX_NAME]; cout << "Enter a file name: "; cin >> fileName; ifstream in( fileName, ios::in); if ( in.fail() ) { cout << "Error opening file: " << fileName << endl; return 0; } int numberStudent; int grade; int max; in >> numberStudent >> grade >> max; any suggestions are helpful, the main goal is to read in the text file show the student id and overall grade percentage and letter grade example: Student ID Percentage Grade ---------- ---------- ----- 1479 89% B i can do the display i understand that, but manipulating the data into seperate students, note: i cannot use arrays on this assignment, thats how i did it wrong the first time through. | |
| gnewfenix (13) | ||
Try a vector. You can use the push_back member function to add elements to it, so you don't need to know how many students you'll have. The index number could be the student number, and each value is the score. Maybe another vector for max, too. Hope that helps. It IS pretty late >.> | ||
| MrExist (2) | |
| new vector? | |
| Galik (42) | |||
Well you have just read in the number of students, the number of grades and the max score. So now you could make a loop to read in each student and inside that another loop to read in their grades: Something like this:
| |||
Last edited on | |||
This topic is archived - New replies not allowed.
