Write a program that reads student information from a file. The information incl
ID: 3536159 • Letter: W
Question
Write a program that reads student information from a file. The information includes the students’ name (first and last name) followed by their test scores. The student data will be stored in a struct variable of type StudentType which has three components: studentName of type string, testScore of type int (testScore is between 0 and 100 inclusive). We will assume that a class has at most 20 students.
We will assume that a class has at most 20 students.
Function Prototypes
Listed below are the function prototypes that your program is required to use.
// Function Prototypes
void PrintNameHeader(ostream& out);
bool OpenInputFile(ifstream& infile, string& infilename);
void Pause(); // same as in previous labs
void ReadStudentData(ifstream& infile, StudentType student[],
int& numStudents);
This function reads all the students data into the array. When reading the data, read the student’s first name and last name as separate strings, then read the test score. If the score is in the proper range (0 to 100) add the student to the list. Ignore any students with scores outside the range.Update the number of students in the array, making sure that the number of students does not go beyond the maximum number allowed while reading the data. Use the information that I will give in class regarding the loop that correctly reads and counts the student data.
void AssignGrades(StudentType student[], int numStudents);
This function assigns the grade to every student.
int HighestScore(const StudentType student[], int numStudents);
This function finds the highest test score of all the students and returns its value.
void PrintNamesWithHighestScore(const StudentType student[], int numStudents);
This function prints the names of the students having the highest test score. The function calls the HighestScore() function, then prints out the names of all the students who have the highest score. (Also print the score and the grade.)
void DisplayAllStudents(const StudentType student[], int numStudents);
This function displays the name of each student with his/her score and the student’s grade.
void GetLowHighRangeValues(int& lowRange, int& highRange);
This function asks the user for the low and high values for a range of scores that he/she would like to view. The function checks that the values are in the order 0 =< lowRange =< highRange =< 100. If the values are out of order, an error message is printed and the user is asked to enter the range again. The updated parameters are returned by the function.
void DisplayStudentsInRange(const StudentType student[], int numStudents,
int lowNum, int highNum);
This function displays the students in the low to high range. The range boundaries are passed in as arguments to the function.
void SortStudentsByName(StudentType student[], int numStudents);
This function sorts the student list by name.
void SortStudentsByScore(StudentType student[], int numStudents);
This function sorts the student list by test score from highest to lowest.
The Main Program
Design main() to:
1. Ask the user for the student data input file and open the file.
2. Read the student data from the input file.
3. Assign the grades.
4. Display the list of students. Print the number of students in the class.
5. Display the list of students with the highest score.
6. Set up a do/while loop to allow the user to view students in different ranges.
a. Ask the user for the low and high score range values.
b. Display the students with scores in the selected range.
c. Ask the user if he/she wants to see another range [y/n].
d. Loop if yes, otherwise end the loop.
7. Sort the list by name, then display the list.
8. Sort the list by test score, then display the list.
After displaying the list of students (see steps #4 and #7), you should “pause†the screen so the user can view the list before continuing with the next part of the program. Use the Pause() function.
Design main() so that it is mostly a series of function calls with cout statements. Make the output user friendly by labeling the output with an appropriate message or label.
Explanation / Answer
Here is my code for your program: http://pastebin.com/idJ1VCJS
Note that there were a few things not specified in your question, so I had to guess or leave them blank. Please look at the comments and adjust them accordingly. It should only take you a few minutes. Specifically, check the struct for StudentType and the functions Pause() and PrintNameHeader(). The rest should be good, and I tested it to make sure it worked. If there happens to be an issue with it, let me know and I will fix/change it for you. Also let me know if you have any questions.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.