parent
dbd3dc9057
commit
9fc3f499a9
@ -1,65 +1,93 @@
|
|||||||
# Student_registration_management_system
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
struct Student {
|
// 结构体定义
|
||||||
char id[20];
|
typedef struct student {
|
||||||
char clas[20];
|
char *name;
|
||||||
char name[20];
|
char *clas;
|
||||||
|
char *num;
|
||||||
double score1;
|
double score1;
|
||||||
double score2;
|
double score2;
|
||||||
double score3;
|
double score3;
|
||||||
double score;
|
double totscore;
|
||||||
};
|
struct student *prev; // 指向前驱结点
|
||||||
|
struct student *next; // 指向后继结点
|
||||||
|
} student;
|
||||||
|
|
||||||
// Function prototypes
|
// 头结点和尾结点
|
||||||
void inputStudent(struct Student *stu);
|
struct student *head = NULL;
|
||||||
void deleteStudent(struct Student *stu, int *numStudents);
|
struct student *tail = NULL;
|
||||||
void selectStudent(struct Student *stu, int numStudents);
|
|
||||||
|
// 函数声明
|
||||||
|
void addStudent(char *name, char *clas, char *num, double score1, double score2, double score3);
|
||||||
|
void printStudents();
|
||||||
|
void freeMemory();
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
struct Student students[100]; // Adjust the size as needed
|
// 添加学生信息
|
||||||
int numStudents = 0;
|
addStudent("zhang", "Class 11", "1001", 99.5, 88.5, 89.5);
|
||||||
int option;
|
addStudent("li", "Class 22", "1002", 77.9, 56.5, 87.5);
|
||||||
|
addStudent("wang", "Class 11", "1003", 92.5, 99.0, 60.5);
|
||||||
|
|
||||||
do {
|
// 打印学生信息
|
||||||
// Display menu
|
printStudents();
|
||||||
printf("1. Input\n2. Delete\n3. Select\n4. Order\n5. Output\n6. Quit\n");
|
|
||||||
printf("Please input your option: ");
|
|
||||||
scanf("%d", &option);
|
|
||||||
|
|
||||||
switch (option) {
|
// 释放内存
|
||||||
case 1:
|
freeMemory();
|
||||||
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);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void inputStudent(struct Student *stu) {
|
// 添加学生信息到链表
|
||||||
|
void addStudent(char *name, char *clas, char *num, double score1, double score2, double score3) {
|
||||||
|
// 分配内存并初始化学生结点
|
||||||
|
struct student *newStudent = (struct student *)malloc(sizeof(struct student));
|
||||||
|
newStudent->name = strdup(name);
|
||||||
|
newStudent->clas = strdup(clas);
|
||||||
|
newStudent->num = strdup(num);
|
||||||
|
newStudent->score1 = score1;
|
||||||
|
newStudent->score2 = score2;
|
||||||
|
newStudent->score3 = score3;
|
||||||
|
newStudent->totscore = score1 + score2 + score3;
|
||||||
|
newStudent->prev = NULL;
|
||||||
|
newStudent->next = NULL;
|
||||||
|
|
||||||
|
// 如果链表为空,设置头结点和尾结点
|
||||||
|
if (head == NULL) {
|
||||||
|
head = newStudent;
|
||||||
|
tail = newStudent;
|
||||||
|
} else {
|
||||||
|
// 否则,将新结点添加到链表末尾
|
||||||
|
tail->next = newStudent;
|
||||||
|
newStudent->prev = tail;
|
||||||
|
tail = newStudent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteStudent(struct Student *stu, int *numStudents) {
|
// 打印学生信息
|
||||||
|
void printStudents() {
|
||||||
|
struct student *current = head;
|
||||||
|
|
||||||
|
printf("学生信息:\n");
|
||||||
|
while (current != NULL) {
|
||||||
|
printf("姓名: %s, 班级: %s, 学号: %s, 总分: %.2f\n", current->name, current->clas, current->num, current->totscore);
|
||||||
|
current = current->next;
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void selectStudent(struct Student *stu, int numStudents) {
|
// 释放内存
|
||||||
|
void freeMemory() {
|
||||||
|
struct student *current = head;
|
||||||
|
struct student *next;
|
||||||
|
|
||||||
|
while (current != NULL) {
|
||||||
|
next = current->next;
|
||||||
|
free(current->name);
|
||||||
|
free(current->clas);
|
||||||
|
free(current->num);
|
||||||
|
free(current);
|
||||||
|
current = next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue