Answered step by step
Verified Expert Solution
Link Copied!

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: [Name][Surname][Student Number][Grade]. Finally it will
return the number of students read from the file. This function will have 2 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:
[Name][Surname][Student Number][Grade]. Each student's information should be
printed on a separate line. This function will take 2 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 2 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 2 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 0 to indicate
successful execution.
Create a text file named studentinformation.txt containing student information in the
specified format: [Name][Surname][Student Number][Grade]. Each student's information
should be on a separate line like shown below. Sample Run:
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions

Question

f. Did they change their names? For what reasons?

Answered: 1 week ago