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:
1. 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.
2. 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
3. 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 students information should be
printed on a separate line. This function will take 2 parameters; array of struct Student
and integer number of students.
4. 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.
5. 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.
6. 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.
studentinformation.txt - Notepad
File Edit Format View Help
Elif Demir 1234590
Emre Kaya 6789070
Ali Atak 0001260
Sample Run:
Enter file name: studentinformation.txt
Student information:
Elif Demir 1234590
Emre Kaya 6789070
Ali Atak 0001260
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_2

Step: 3

blur-text-image_3

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

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions

Question

=+How are the first copy costs and distribution costs comprised?

Answered: 1 week ago