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");
|
||||||
int main() {
|
return;
|
||||||
struct Student students[100]; // Adjust the size as needed
|
}
|
||||||
int numStudents = 0;
|
|
||||||
int option;
|
|
||||||
|
|
||||||
do {
|
// Check if the new student ID already exists
|
||||||
// Display menu
|
for (int i = 0; i < *numStudents; ++i) {
|
||||||
printf("1. Input\n2. Delete\n3. Select\n4. Order\n5. Output\n6. Quit\n");
|
if (students[i].id == newStudent.id) {
|
||||||
printf("Please input your option: ");
|
printf("Error: Student with ID %d already exists.\n", newStudent.id);
|
||||||
scanf("%d", &option);
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (option) {
|
// Find the position to insert the new student based on class and total grade
|
||||||
case 1:
|
int insertIndex = 0;
|
||||||
inputStudent(&students[numStudents]);
|
while (insertIndex < *numStudents &&
|
||||||
numStudents++;
|
(students[insertIndex].class < newStudent.class ||
|
||||||
break;
|
(students[insertIndex].class == newStudent.class &&
|
||||||
case 2:
|
students[insertIndex].grade1 + students[insertIndex].grade2 + students[insertIndex].grade3 >
|
||||||
deleteStudent(students, &numStudents);
|
newStudent.grade1 + newStudent.grade2 + newStudent.grade3))) {
|
||||||
break;
|
++insertIndex;
|
||||||
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;
|
// Shift elements to make room for the new student
|
||||||
|
for (int i = *numStudents; i > insertIndex; --i) {
|
||||||
|
students[i] = students[i - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
void inputStudent(struct Student *stu) {
|
// Insert the new student at the correct position
|
||||||
|
students[insertIndex] = newStudent;
|
||||||
|
|
||||||
}
|
// Increment the number of students in the array
|
||||||
|
(*numStudents)++;
|
||||||
|
|
||||||
void deleteStudent(struct Student *stu, int *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);
|
||||||
|
|
||||||
|
// Check if the current student is the newly inserted one
|
||||||
|
if (i == insertIndex) {
|
||||||
|
printf("inserted\n");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
void selectStudent(struct Student *stu, int numStudents) {
|
// 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…
Reference in new issue