Update README.md

选做
pvk3wty2e 2 years ago
parent dbd3dc9057
commit 9fc3f499a9

@ -1,65 +1,93 @@
# Student_registration_management_system
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Student {
char id[20];
char clas[20];
char name[20];
// 结构体定义
typedef struct student {
char *name;
char *clas;
char *num;
double score1;
double score2;
double score3;
double score;
};
double totscore;
struct student *prev; // 指向前驱结点
struct student *next; // 指向后继结点
} student;
// Function prototypes
void inputStudent(struct Student *stu);
void deleteStudent(struct Student *stu, int *numStudents);
void selectStudent(struct Student *stu, int numStudents);
// 头结点和尾结点
struct student *head = NULL;
struct student *tail = NULL;
// 函数声明
void addStudent(char *name, char *clas, char *num, double score1, double score2, double score3);
void printStudents();
void freeMemory();
int main() {
struct Student students[100]; // Adjust the size as needed
int numStudents = 0;
int option;
// 添加学生信息
addStudent("zhang", "Class 11", "1001", 99.5, 88.5, 89.5);
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
printf("1. Input\n2. Delete\n3. Select\n4. Order\n5. Output\n6. Quit\n");
printf("Please input your option: ");
scanf("%d", &option);
// 打印学生信息
printStudents();
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);
// 释放内存
freeMemory();
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…
Cancel
Save