diff --git a/README.md b/README.md index 868e0ef..fa7c569 100644 --- a/README.md +++ b/README.md @@ -1,65 +1,81 @@ -# Student_registration_management_system #include -#include -#include +#define MAX_STUDENTS 100 + +// Structure to represent a student struct Student { - char id[20]; - char clas[20]; - char name[20]; - double score1; - double score2; - double score3; - double score; + int id; + int class; + float grade1; + float grade2; + float grade3; }; -// Function prototypes -void inputStudent(struct Student *stu); -void deleteStudent(struct Student *stu, int *numStudents); -void selectStudent(struct Student *stu, int numStudents); +// Function to insert a new student into the array and maintain the sorting order +void insertStudent(struct Student students[], int *numStudents, struct Student newStudent) { + // Check if the array is full + if (*numStudents >= MAX_STUDENTS) { + printf("Error: Array is full. Cannot insert more students.\n"); + return; + } -int main() { - struct Student students[100]; // Adjust the size as needed - int numStudents = 0; - int option; + // Check if the new student ID already exists + for (int i = 0; i < *numStudents; ++i) { + if (students[i].id == newStudent.id) { + printf("Error: Student with ID %d already exists.\n", newStudent.id); + return; + } + } - do { - // Display menu - printf("1. Input\n2. Delete\n3. Select\n4. Order\n5. Output\n6. Quit\n"); - printf("Please input your option: "); - scanf("%d", &option); + // Find the position to insert the new student based on class and total grade + int insertIndex = 0; + while (insertIndex < *numStudents && + (students[insertIndex].class < newStudent.class || + (students[insertIndex].class == newStudent.class && + students[insertIndex].grade1 + students[insertIndex].grade2 + students[insertIndex].grade3 > + newStudent.grade1 + newStudent.grade2 + newStudent.grade3))) { + ++insertIndex; + } - switch (option) { - case 1: - inputStudent(&students[numStudents]); - numStudents++; - break; - case 2: - deleteStudent(students, &numStudents); - break; - case 3: - selectStudent(students, numStudents); - break; - // Add cases for other options (order, output) if needed - case 6: - printf("Exiting the program.\n"); - break; - default: - printf("Invalid option. Please try again.\n"); - } - } while (option != 6); + // Shift elements to make room for the new student + for (int i = *numStudents; i > insertIndex; --i) { + students[i] = students[i - 1]; + } - return 0; -} + // Insert the new student at the correct position + students[insertIndex] = newStudent; -void inputStudent(struct Student *stu) { - -} + // Increment the number of students in the array + (*numStudents)++; + + // Display the updated student information + for (int i = 0; i < *numStudents; ++i) { + printf("%d %d %.2f %.2f %.2f\n", students[i].id, students[i].class, + students[i].grade1, students[i].grade2, students[i].grade3); -void deleteStudent(struct Student *stu, int *numStudents) { - + // Check if the current student is the newly inserted one + if (i == insertIndex) { + printf("inserted\n"); + } + } } -void selectStudent(struct Student *stu, int numStudents) { - +int main() { + // Initialize array with three students + struct Student students[MAX_STUDENTS] = { + {10001, 11, 99.5, 88.5, 89.5}, + {10002, 12, 77.9, 56.5, 87.5}, + {10003, 11, 92.5, 99.0, 60.5} + }; + + // Number of students in the array + int numStudents = 3; + + // New student information (you can modify this based on user input) + struct Student newStudent = {10004, 11, 23.4, 45.6, 99.0}; + + // Insert the new student and display the updated information + insertStudent(students, &numStudents, newStudent); + + return 0; }