Update README.md

步骤4
pvk3wty2e 2 years ago
parent dbd3dc9057
commit 28959d0c6f

@ -1,65 +1,81 @@
# Student_registration_management_system
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENTS 100
// Structure to represent a student
struct Student { struct Student {
char id[20]; int id;
char clas[20]; int class;
char name[20]; float grade1;
double score1; float grade2;
double score2; float grade3;
double score3;
double score;
}; };
// Function prototypes // Function to insert a new student into the array and maintain the sorting order
void inputStudent(struct Student *stu); void insertStudent(struct Student students[], int *numStudents, struct Student newStudent) {
void deleteStudent(struct Student *stu, int *numStudents); // Check if the array is full
void selectStudent(struct Student *stu, int numStudents); if (*numStudents >= MAX_STUDENTS) {
printf("Error: Array is full. Cannot insert more students.\n");
return;
}
int main() { // Check if the new student ID already exists
struct Student students[100]; // Adjust the size as needed for (int i = 0; i < *numStudents; ++i) {
int numStudents = 0; if (students[i].id == newStudent.id) {
int option; printf("Error: Student with ID %d already exists.\n", newStudent.id);
return;
}
}
do { // Find the position to insert the new student based on class and total grade
// Display menu int insertIndex = 0;
printf("1. Input\n2. Delete\n3. Select\n4. Order\n5. Output\n6. Quit\n"); while (insertIndex < *numStudents &&
printf("Please input your option: "); (students[insertIndex].class < newStudent.class ||
scanf("%d", &option); (students[insertIndex].class == newStudent.class &&
students[insertIndex].grade1 + students[insertIndex].grade2 + students[insertIndex].grade3 >
newStudent.grade1 + newStudent.grade2 + newStudent.grade3))) {
++insertIndex;
}
switch (option) { // Shift elements to make room for the new student
case 1: for (int i = *numStudents; i > insertIndex; --i) {
inputStudent(&students[numStudents]); students[i] = students[i - 1];
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);
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;
} }

Loading…
Cancel
Save