学生成绩管理系统(vs版)

#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#pragma warning(disable:4996).

#pragma warning(disable:6031).

#define MAX_NAME_LEN 50

#define MAX_ID_LEN 20

#define MAX_STUDENTS 100

#define MIN_GRADE 0

#define MAX_GRADE 100

// Student Information Structures

typedef struct {

char name[MAX_NAME_LEN];

char id[MAX_ID_LEN];

int grade[3]; // grade in three subjects

double avg; // average score

int temp;

} Student;

// Array of student information

Student students[MAX_STUDENTS];

int num_students = 0; // number of current students

// function declaration

void add_student();

void load_students();

void save_students();

void display_students();

void search_student();

void list_students();

void list_failed_students();

void sort_students();

void insert_grade();

void delete_student();

// Add student information

void add_student() {

if (num_students >= MAX_STUDENTS) {

printf("The maximum number of student information has been reached and no new student information can be added. \n");

return;

}

Student new_student;

printf("Please enter student's name: ");

scanf("%s", new_student.name);

printf("Please enter the student's number:");

scanf("%s", new_student.id);

printf("Please enter %s's three subject grades (separated by spaces):", new_student.name);

scanf("%d %d %d", &new_student.grade[0], &new_student.grade[1], &new_student.grade[2]);

for (int i = 0; i < 3; i++)

{

if (new_student.grade[i] < MIN_GRADE || new_student.grade[i] > MAX_GRADE) {

printf("Invalid grade, please re-enter. \n");

i--;

}

}

new_student.avg = (new_student.grade[0] + new_student.grade[1] + new_student.grade[2]) / 3.0;

students[num_students] = new_student;

num_students++;

printf("Student information has been added successfully. \n");

}

// Load student information from a file

void load_students() {

printf("Please enter the path to the student information file:");

char filename[100];

scanf("%s", filename);

FILE* file = fopen(filename, "r");

if (file == NULL) {

printf("Failed to open file, please check if the file path is correct. \n");

return;

}

int count = 0;

while (1) {

Student new_student;

int ret = fscanf(file, "%s %s %d %d %d", new_student.name, new_student.id,

&new_student.grade[0], &new_student.grade[1], &new_student.grade[2]);

if (ret == EOF) {

break;

}

new_student.avg = (new_student.grade[0] + new_student.grade[1] + new_student.grade[2]) / 3.0;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值