Question: Define a Student structure that contains an integer variable id , a string variable name, and a float variable GPA. Write a program to read
Define a Student structure that contains an integer variable id a string variable name, and a float variable GPA.
Write a program to read students' information from an input text file entered by the user. The program then print to the standard output
students' names who have a GPA in order. For simplicity, you can safely assume that the number of students
in the file is always less than or equal to
Ex: if the input file contains:
namePeter GPA
nameAdina GPA
nameMike GPA
nameGina GPA
then the program will output
Peter
Adina
Note: the content in the input file may be empty.
You Must define and call the following function to read and parse the students' information from a text file. This function takes an ifstream
object assuming the file is opened successfully the Student array and an integer counting the number of students in the file as input.
void ReadStudentInfoifstream sifs, Student array int cnStudents;
Hint: use the getline function to load the individual students' information one line at a time. To parse the information in this line, you
may use a stringstream object. Assume the student's information is stored in a string studentInfo, you then can create a
stringstream object as stringstream myStream studentInfo You then can use myStream to get the information like how
you used cins to get multiple input from the user. To suocessfully retrieve the individual information, you may need to first replace each
with a whitespace before creating the stringstream object.
In the main function,
first, create a Student array with elements
second, read information into the created array, count the number of students in the file
third, print students names in the reversed order to the screen
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
