Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++ Please 9.19 Reading student information Implement a program that opens and reads from an student information file. The file name is provided by the
C++ Please
9.19 Reading student information Implement a program that opens and reads from an student information file. The file name is provided by the user. The program will check whether the file can be opened successfully or not. If not, the program will output Input file not found! and exit the program. If the file can be opened successfully, it then will read the students' information and perform the operation described later. The students' information is stored in a format similar to a.cvs file. That is, each row represents an entry that consists of multiple attributes (or columns) separated by comma "". The following provides an example of the student information file. John Smith, Computer Science, 123456, 3.55 Mary Jane, Electrical Engineering, 231450, 3.68 Jone Doe, Computer Science, 113222, 3.9 where the first attribute/column of each entry stores the student's full name, the second attribute specifies the major of the student, the third column is the student's ID, and the last column is that student's current average GPA. Define a structure, name studentInfo to store a student's information as described above. Specifically, the structure should include the following member variables o a string to store the student's full name o a string to store the student's major o an integer to store the student's ID o a float to store the student's average GPA Create an array of studentInfo. You can assume the maximum size of this array to be 10. The number of the students in the student information file is unknown. You need to first go over the file and determine the number of entries (rows) in the file to determine the actual size of the array (i.e., the number of students). Then, your program should read the student information one-hw-one and store them into the individual structure elements of the array The number of the students in the student information file is unknown. You need to first go over the file and determine the number of entries (rows) in the file to determine the actual size of the array (i.e., the number of students). Then, your program should read the student information one-by-one and store them into the individual structure elements of the array Create a list of menu options to allow the user to select from 1 - print all student information 2 - sort students based on their IDs and print 3 - sort students based on their average GPAs and print If the user selects 1, the program will print out all the students' information stored in the array in same format as in the input file. If the user selects 2, the program will sort the students based on their IDs in the ascending order (from small to large), and print out all the students' information based on the sorted results in the same format as in the input file. If the user selects 3, the program will sort the students based on their average GPAs in the descending order (from high to low), and print out all students' information based on the sorted results in the same format as in the input file. After the above operation, the program will exit. Hint for file reading: You may first use getline() function to read a student's info, then parse the individual attributes from this line using stringstream (you need to include the header). The following shows an example of using stringstream to get the first attribute from the line stored in tmp: stringstream check (tmp); //initialize a stringstream variable with the line stored in tmp string name; getline (check, name, ','); //get the portion of string before conna',' and store it to the string variable name If the read string is an integer, you can use stoi() function to convert the string to an integer. Similarly, if the read string is a float number, you can use stof() function to convert it to a float
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started