Write a program that reads from a text file containing student records and puts the data into the below parallel arrays. A student record consists of a student’s netID, followed by that student’s major, followed by that student’s GPA. An example of student record is as follows (for simplicity, assume the student’s netID is an int):
1001 CS 3.8
In the above record, the netID is 1001, major is CS, and GPA is 3.8.
• The program puts the students’ netIDs in an array called netIDArray.
• The program puts the students’ majors in an array called majorArray
• The program puts the students’ GPA in an array called gpaArray
The arrays are populated in the order the data is read from the file. For example, the first netID read from the file is assigned to the first element of the netIDArray, the second netID read is assigned to the second element of the netIDArray, and so on. The other arrays are populated in the same fashion. Make sure when you read from the file, you store the items in the arrays in the proper order.
The program then displays the students’ netIDs, the students’ majors, and the students’ GPAs, as they are read from the arrays. All the data is displayed in the order they are in the arrays. Then the program searches the gpaArray for the lowest GPA, displays that GPA, along with the netID and major of the corresponding student. Similarly it searches the gpaArray for the highest GPA, displays that GPA, along with the netID and major of the corresponding student. Then the program enters a loop where it prompts the user to enter a student’s netID, searches on that netID, and displays the netID, GPA and major if found, or “NetID not found” if not found. The loop is exited when the user enters -1.
Note that your code must work for any file which contains student records, where the record contents are arbitrary netIDs (int), arbitrary majors (string) and arbitrary GPAs (double). The number of records is arbitrary, but you should set the array sizes to 15. If the number of records exceeds the array size, only the first 15 records will be stored in the arrays.
1. Additional requirements – Make sure you meet all the requirements to avoid losing points
To complete the assignment, you are required to use only what has been taught in class. If you have prior programming experience, refrain from using more advanced C++ constructs, so all the homework programs can be graded on a consistent basis.
Make sure you follow the requirements in the “Homework Notes”.
You are required to implement the following function. You may implement additional functions to make your program more modular.
populateArrays: The function’s parameter list is (follow this order in your code):
- a file name as a string passed by value
- the “netIDArray”, the “majorArray” and the “gpaArray” arrays
- the size of the arrays passed by value. If the number of records in the file exceeds the array size, the function will populate the arrays only up to their size and ignore the remaining records.
- the number of records as a reference variable. The function writes the number of records found into the reference variable. If the number of records in the file exceeds the array size, the function writes the array size as the number of records
The function opens the file, reads the records, and populates the arrays. The function closes the file. The function returns an int as status. If the file open fails, the function returns 1, else the function returns 0.
The array contents should be displayed three consecutive elements per row.
This is the pseudocode of the main function for part 1: