Real
Real
h>
#include <string.h>
struct Student {
int sid;
char fname[50];
char address[100];
char num[15];
float icp;
};
// Function
void insertNewStudent(struct Student records[], int *totalStudents);
void findStudentByID(struct Student records[], int totalStudents);
void displayAllStudents(struct Student records[], int totalStudents);
void deleteStudentByID(struct Student records[], int *totalStudents);
void updateStudentDetails(struct Student records[], int totalStudents);
int main() {
struct Student records[100];
int totalStudents = 0;
int choice;
do {
//options
printf("\n======== University Student Management System ========\n");
printf("1. Add New Student\n");
printf("2. Find Student by ID\n");
printf("3. Display All Students\n");
printf("4. Delete Student by ID\n");
printf("5. Update Student Details\n");
printf("6. Exit\n");
printf("======================================================\n");
printf("Enter your choice: ");
scanf("%d", &choice);
//menu options
switch (choice) {
case 1:
insertNewStudent(records, &totalStudents);
break;
case 2:
findStudentByID(records, totalStudents);
break;
case 3:
displayAllStudents(records, totalStudents);
break;
case 4:
deleteStudentByID(records, &totalStudents);
break;
case 5:
updateStudentDetails(records, totalStudents);
break;
case 6:
printf("Exiting program. Goodbye!\n");
break;
default:
printf("Invalid choice! Please try again.\n");
}
} while (choice != 6);
return 0;
}
//new student
void insertNewStudent(struct Student records[], int *totalStudents) {
printf("\nEnter details for the new student:\n");
printf("Student ID: ");
scanf("%d", &records[*totalStudents].sid);
printf("Full Name: ");
getchar();
fgets(records[*totalStudents].fname, 50, stdin);
records[*totalStudents].fname[strcspn(records[*totalStudents].fname, "\n")]
= '\0';
printf("Address: ");
fgets(records[*totalStudents].address, 100, stdin);
records[*totalStudents].address[strcspn(records[*totalStudents].address, "\
n")] = '\0';
printf("Contact Number: ");
scanf("%s", records[*totalStudents].num);
printf("ICP Marks: ");
scanf("%f", &records[*totalStudents].icp);
(*totalStudents)++;
printf("Student added successfully!\n");
}
//student by ID
void findStudentByID(struct Student records[], int totalStudents) {
int id, found = 0;
printf("\nEnter Student ID to search: ");
scanf("%d", &id);
// delete a student by ID
void deleteStudentByID(struct Student records[], int *totalStudents) {
int id, found = 0;
printf("\nEnter Student ID to delete: ");
scanf("%d", &id);