学生管理系统c代码实现
时间: 2023-10-09 10:17:38 浏览: 37
很抱歉,我是一名AI语言模型,无法提供完整的学生管理系统c代码实现。但是,我可以给出大致代码框架,希望能对你有所帮助。
```
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct student{
char name[20];
int id;
int age;
float score;
};
void addStudent(struct student stus[], int n);
void deleteStudent(struct student stus[], int n);
void searchStudent(struct student stus[], int n);
void modifyStudent(struct student stus[], int n);
void displayStudent(struct student stus[], int n);
int main(){
struct student stus[100];
int n = 0;
int choice;
printf("Welcome to Student Management System!\n");
while(1){
printf("\nPlease select an operation:\n");
printf("1. Add a student\n");
printf("2. Delete a student\n");
printf("3. Search a student\n");
printf("4. Modify a student\n");
printf("5. Display all students\n");
printf("0. Exit\n");
scanf("%d", &choice);
switch(choice){
case 1:
addStudent(stus, n);
n++;
break;
case 2:
deleteStudent(stus, n);
n--;
break;
case 3:
searchStudent(stus, n);
break;
case 4:
modifyStudent(stus, n);
break;
case 5:
displayStudent(stus, n);
break;
case 0:
printf("Thank you for using Student Management System!\n");
return 0;
default:
printf("Invalid choice!\n");
}
}
}
void addStudent(struct student stus[], int n){
printf("Please enter the name of the student: ");
scanf("%s", stus[n].name);
printf("Please enter the id of the student: ");
scanf("%d", &stus[n].id);
printf("Please enter the age of the student: ");
scanf("%d", &stus[n].age);
printf("Please enter the score of the student: ");
scanf("%f", &stus[n].score);
printf("Student added successfully!\n");
}
void deleteStudent(struct student stus[], int n){
int id, i;
printf("Please enter the id of the student you want to delete: ");
scanf("%d", &id);
for(i = 0; i < n; i++){
if(stus[i].id == id){
printf("Student %s with id %d deleted successfully!\n", stus[i].name, stus[i].id);
memmove(&stus[i], &stus[i+1], (n-i-1)*sizeof(struct student));
break;
}
}
if(i == n){
printf("Student with id %d not found!\n", id);
}
}
void searchStudent(struct student stus[], int n){
int id, i;
printf("Please enter the id of the student you want to search: ");
scanf("%d", &id);
for(i = 0; i < n; i++){
if(stus[i].id == id){
printf("Name: %s\n", stus[i].name);
printf("Id: %d\n", stus[i].id);
printf("Age: %d\n", stus[i].age);
printf("Score: %.2f\n", stus[i].score);
break;
}
}
if(i == n){
printf("Student with id %d not found!\n", id);
}
}
void modifyStudent(struct student stus[], int n){
int id, i;
printf("Please enter the id of the student you want to modify: ");
scanf("%d", &id);
for(i = 0; i < n; i++){
if(stus[i].id == id){
printf("Name: %s\n", stus[i].name);
printf("Id: %d\n", stus[i].id);
printf("Age: %d\n", stus[i].age);
printf("Score: %.2f\n", stus[i].score);
printf("Please enter the new name of the student: ");
scanf("%s", stus[i].name);
printf("Please enter the new id of the student: ");
scanf("%d", &stus[i].id);
printf("Please enter the new age of the student: ");
scanf("%d", &stus[i].age);
printf("Please enter the new score of the student: ");
scanf("%f", &stus[i].score);
printf("Student modified successfully!\n");
break;
}
}
if(i == n){
printf("Student with id %d not found!\n", id);
}
}
void displayStudent(struct student stus[], int n){
int i;
printf("Name\tId\tAge\tScore\n");
for(i = 0; i < n; i++){
printf("%s\t%d\t%d\t%.2f\n", stus[i].name, stus[i].id, stus[i].age, stus[i].score);
}
}
```