Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a C program that reads unknown number of students' information from a file, stores it in an array of struct, and performs basic operations
Write a C program that reads unknown number of students' information from a file,
stores it in an array of struct, and performs basic operations such as displaying student
information name surname, student number, grade ranking the students according to their
grade in descending order and calculating the class average.
The program should have the following:
struct Student that stores the following student information:
name: A character array to store the student's name.
surname: A character array to store the student's surname.
number: A character array to store the student's number.
grade: An integer to store the student's grade.
readStudentsFromFile function will read unknown number of student information
from a file specified by the user. Each line in the file represents a student's information
in the following format: NameSurnameStudent NumberGrade Finally it will
return the number of students read from the file. This function will have parameters;
character array filename and array of struct Student. If the file cannot be opened wrong
file name entered by user it will print an error message like below.
Enter file name: stu.txt
Error: Unable to open file stu.txt
printStudents function will display student information on the screen which is stored
in the structured array. Each student's information should be printed in the format:
NameSurnameStudent NumberGrade Each student's information should be
printed on a separate line. This function will take parameters; array of struct Student
and integer number of students. rankStudents function will rank the students based on their grades in descending order
highest grade to lowest grade After ranking, it will print the rank, name, surname,
number, and grade of each student in a formatted manner the format is given in the
sample run This function will take parameters; array of struct Student and integer
number of students.
The calculateClassAverage function will calculate and return the class average based
on the grades of all students as a double value. This function will take parameters;
array of struct Student and integer number of students.
The int main function will declare variables, including an array of Student structs and
a filename. It will prompt the user to enter the filename from which the student
information will be read. It will read the student information using the
readStudentsFromFile function. If an error occurs during file reading, it will exit the
program with an error code. It will print student information, rank students, calculate
the class average and print the class average. Finally, it will return to indicate
successful execution.
Create a text file named studentinformation.txt containing student information in the
specified format: NameSurnameStudent NumberGrade Each student's information
should be on a separate line like shown below. Sample Run:
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