// Define function prototypes
int main();
void fillArrays();
void displayMenu();
void displayTranscripts();
void changeAddress();
void addStudent();
void deleteStudent();
void displayUnder50();
void saveData();
int option = 1;
// Call fillArrays() to initialize all arrays from file
fillArrays();
// Display the main menu and wait for user input
while (option > 0) {
displayMenu();
scanf("%d", &option);
// Call the appropriate function based on user input
if (option == 1)
displayTranscripts();
if (option == 2)
changeAddress();
if (option == 3)
addStudent();
if (option == 4)
deleteStudent();
if (option == 5)
displayUnder50();
}
// If user chooses option 0, save data to file
if (option == 0) {
printf("\nSaving Data...");
saveData();
}
// Print goodbye message and exit
printf("\nBye!");
return 0;
// Displays the main menu
void displayMenu() {
printf("\nPresentation College Student Database");
printf("\n\nStudents Registered: %d", stuTotal);
printf("\n(1) Student Transcripts");
printf("\n(2) Change Student Address");
printf("\n(3) Add a new Student");
printf("\n(4) Delete a Student");
printf("\n(5) Under 50% Students");
printf("\n\n(0) Exit and Save");
printf("\n(-1) Exit without Saving\n");
printf("\nSelection: ");
}
// Saves all data from arrays to file
void saveData() {
// Open file for writing
FILE* file = fopen("./stuDetails.txt", "w");
int i;
// Loop through each student and write their details to file
for (i = 0; i <= stuTotal - 1; i++) {
// If student ID is -999, skip to next student
if (stuID_Arr[i] == -999)
continue;
// Write student's academic details to file
fprintf(file, "%d %d %d %d %d %d", stuID_Arr[i], Maths_Arr[i], IT_Arr[i],
Phys_Arr[i], Geo_Arr[i], Art_Arr[i]);
// Write student's name and address to file
fprintf(file, "\n%s", stuName_Arr[i]);
fprintf(file, "%s", stuAddr_Arr[i]);
}
// Write 0 to file as a marker indicating end of file
fprintf(file, "0");
// Close file and print confirmation message
fclose(file);
printf("\nData Saved!");
}
// Displays all students with an average grade under 50%
void displayUnder50() {
int i, total;
float avg;
printf("\n===================== UNDER 50 PERCENT ======================\n\
n");
// Loop through each student and calculate their average grade
for (i = 0; i <= stuTotal - 1; i++) {
total = Maths_Arr[i] + IT_Arr[i] + Phys_Arr[i] + Geo_Arr[i] + Art_Arr[i];
avg = (float)total / 5;
// If student's average grade is under 50%, display their details
if (avg < 50.0) {
printf("\nName: %s", stuName_Arr[i]);
printf("\