Within my code, i have a one-d array that holds 10 students names, while the other array is a 2-d array (is 10x5) and holds the students' score. i'm supposed to be using a function that will pull out both of these arrays. I have the code to pull out the information from the txt file but i'm not sure how to implement it into function
also, later on within my code i will have to use these arrays again in order to search for names within the array, i'm not sure how to "save" the array for future reference within my code.
if you would also tell me how the code works too that would be awesome
To read the data from the file you can create a function like this:
1 2 3 4 5 6
void readStudentData (ifstream& inputfile, string student_name[10], int student_score[10][5])
{
// your code to read the data
// names into student_name
// score into student_score.
}
In main you declare your variables and pass them to the function
1 2 3 4 5
string student_names[10];
int student_scores[10][5];
ifstream inputfile("dataIP1.txt");
// check if file is opened
readStudentData (inputfile, student_names, student_scores);
There is no need to save the array. If it is in main() it will be there as long as the program is running and you can easily pass it to a function to search or print it.