c语言学生管理系统,可以在原有学生表增删查改学生,列表显示所有学生,学生表包括学号姓名性别出生日期电话号码,已修课程门数,已获得学分,缴费总额。 可以在原有缴费表增删查改缴费记录,缴费表包括缴费编号学号缴费时间金额工作人员。 对原有的课程表进行增删查改,课程表包括课程代码课程名称学时学分 对原有的成绩表增删查改,成绩表包括课程学号学期平时成绩考试成绩及派生的总评成绩已获得学分,总评成绩大于等于60才能获得学分,否则为0。总评成绩=平时成绩*0.4+考试成绩*0.6。
时间: 2024-04-16 09:28:27 浏览: 105
这是一个C语言学生管理系统的示例代码,可以在原有的学生表、缴费表、课程表和成绩表上进行增删查改操作。请注意,此示例代码仅提供了基本的操作功能,您可以根据实际需求进行修改和扩展。
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
char studentID[10];
char name[20];
char gender[10];
char birthdate[15];
char phoneNumber[15];
int completedCourses;
float earnedCredits;
float totalPayment;
} Student;
typedef struct {
int paymentID;
char studentID[10];
char paymentDate[15];
float amount;
char staff[20];
} Payment;
typedef struct {
char courseCode[10];
char courseName[20];
int hours;
float credits;
} Course;
typedef struct {
char courseCode[10];
char studentID[10];
int semester;
float regularGrade;
float examGrade;
float totalGrade;
float earnedCredits;
} Grade;
void addStudent(FILE *file) {
Student newStudent;
printf("Enter student ID: ");
scanf("%s", newStudent.studentID);
printf("Enter student name: ");
scanf("%s", newStudent.name);
printf("Enter student gender: ");
scanf("%s", newStudent.gender);
printf("Enter student birthdate: ");
scanf("%s", newStudent.birthdate);
printf("Enter student phone number: ");
scanf("%s", newStudent.phoneNumber);
printf("Enter completed courses: ");
scanf("%d", &newStudent.completedCourses);
printf("Enter earned credits: ");
scanf("%f", &newStudent.earnedCredits);
printf("Enter total payment: ");
scanf("%f", &newStudent.totalPayment);
fprintf(file, "%s %s %s %s %s %d %.2f %.2f\n", newStudent.studentID, newStudent.name, newStudent.gender, newStudent.birthdate, newStudent.phoneNumber, newStudent.completedCourses, newStudent.earnedCredits, newStudent.totalPayment);
printf("Student added successfully.\n");
}
void deleteStudent(FILE *file) {
char studentID[10];
char line[200];
FILE *tempFile = fopen("temp.txt", "w");
printf("Enter student ID to delete: ");
scanf("%s", studentID);
while (fgets(line, sizeof(line), file)) {
if (strncmp(line, studentID, strlen(studentID)) != 0) {
fputs(line, tempFile);
}
}
fclose(file);
fclose(tempFile);
remove("students.txt");
rename("temp.txt", "students.txt");
printf("Student deleted successfully.\n");
}
void displayStudents(FILE *file) {
char line[200];
printf("---------- Student List ----------\n");
while (fgets(line, sizeof(line), file)) {
printf("%s", line);
}
printf("-----------------------------------\n");
}
void addPayment(FILE *file) {
Payment newPayment;
printf("Enter payment ID: ");
scanf("%d", &newPayment.paymentID);
printf("Enter student ID: ");
scanf("%s", newPayment.studentID);
printf("Enter payment date: ");
scanf("%s", newPayment.paymentDate);
printf("Enter amount: ");
scanf("%f", &newPayment.amount);
printf("Enter staff name: ");
scanf("%s", newPayment.staff);
fprintf(file, "%d %s %s %.2f %s\n", newPayment.paymentID, newPayment.studentID, newPayment.paymentDate, newPayment.amount, newPayment.staff);
printf("Payment added successfully.\n");
}
void deletePayment(FILE *file) {
int paymentID;
char line[200];
FILE *tempFile = fopen("temp.txt", "w");
printf("Enter payment ID to delete: ");
scanf("%d", &paymentID);
while (fgets(line, sizeof(line), file)) {
int currentPaymentID;
sscanf(line, "%d", ¤tPaymentID);
if (currentPaymentID != paymentID) {
fputs(line, tempFile);
}
}
fclose(file);
fclose(tempFile);
remove("payments.txt");
rename("temp.txt", "payments.txt");
printf("Payment deleted successfully.\n");
}
void displayPayments(FILE *file) {
char line[200];
printf("---------- Payment List ----------\n");
while (fgets(line, sizeof(line), file)) {
printf("%s", line);
}
printf("-----------------------------------\n");
}
void addCourse(FILE *file) {
Course newCourse;
printf("Enter course code: ");
scanf("%s", newCourse.courseCode);
printf("Enter course name: ");
scanf("%s", newCourse.courseName);
printf("Enter course hours: ");
scanf("%d", &newCourse.hours);
printf("Enter course credits: ");
scanf("%f", &newCourse.credits);
fprintf(file, "%s %s %d %.2f\n", newCourse.courseCode, newCourse.courseName, newCourse.hours, newCourse.credits);
printf("Course added successfully.\n");
}
void deleteCourse(FILE *file) {
char courseCode[10];
char line[200];
FILE *tempFile = fopen("temp.txt", "w");
printf("Enter course code to delete: ");
scanf("%s", courseCode);
while (fgets(line, sizeof(line), file)) {
if (strncmp(line, courseCode, strlen(courseCode)) != 0) {
fputs(line, tempFile);
}
}
fclose(file);
fclose(tempFile);
remove("courses.txt");
rename("temp.txt", "courses.txt");
printf("Course deleted successfully.\n");
}
void displayCourses(FILE *file) {
char line[200];
printf("---------- Course List ----------\n");
while (fgets(line, sizeof(line), file)) {
printf("%s", line);
}
printf("----------------------------------\n");
}
void addGrade(FILE *file) {
Grade newGrade;
printf("Enter course code: ");
scanf("%s", newGrade.courseCode);
printf("Enter student ID: ");
scanf("%s", newGrade.studentID);
printf("Enter semester: ");
scanf("%d", &newGrade.semester);
printf("Enter regular grade: ");
scanf("%f", &newGrade.regularGrade);
printf("Enter exam grade: ");
scanf("%f", &newGrade.examGrade);
newGrade.totalGrade = newGrade.regularGrade * 0.4 + newGrade.examGrade * 0.6;
newGrade.earnedCredits = (newGrade.totalGrade >= 60) ? 1.0 : 0.0;
fprintf(file, "%s %s %d %.2f %.2f %.2f %.2f\n", newGrade.courseCode, newGrade.studentID, newGrade.semester, newGrade.regularGrade, newGrade.examGrade, newGrade.totalGrade, newGrade.earnedCredits);
printf("Grade added successfully.\n");
}
void deleteGrade(FILE *file) {
char courseCode[10];
char studentID[10];
char line[200];
FILE *tempFile = fopen("temp.txt", "w");
printf("Enter course code to delete: ");
scanf("%s", courseCode);
printf("Enter student ID to delete: ");
scanf("%s", studentID);
while (fgets(line, sizeof(line), file)) {
char currentCourseCode[10];
char currentStudentID[10];
sscanf(line, "%s %s", currentCourseCode, currentStudentID);
if (strcmp(currentCourseCode, courseCode) != 0 || strcmp(currentStudentID, studentID) != 0) {
fputs(line, tempFile);
}
}
fclose(file);
fclose(tempFile);
remove("grades.txt");
rename("temp.txt", "grades.txt");
printf("Grade deleted successfully.\n");
}
void displayGrades(FILE *file) {
char line[200];
printf("---------- Grade List ----------\n");
while (fgets(line, sizeof(line), file)) {
printf("%s", line);
}
printf("---------------------------------\n");
}
int main() {
FILE *studentsFile = fopen("students.txt", "a+");
FILE *paymentsFile = fopen("payments.txt", "a+");
FILE *coursesFile = fopen("courses.txt", "a+");
FILE *gradesFile = fopen("grades.txt", "a+");
int choice;
if (studentsFile == NULL || paymentsFile == NULL || coursesFile == NULL || gradesFile == NULL) {
printf("Error opening file.\n");
return 1;
}
while (1) {
printf("\n----- Student Management System -----\n");
printf("1. Add student\n");
printf("2. Delete student\n");
printf("3. Display all students\n");
printf("4. Add payment\n");
printf("5. Delete payment\n");
printf("6. Display all payments\n");
printf("7. Add course\n");
printf("8. Delete course\n");
printf("9. Display all courses\n");
printf("10. Add grade\n");
printf("11. Delete grade\n");
printf("12. Display all grades\n");
printf("0. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
addStudent(studentsFile);
break;
case 2:
deleteStudent(studentsFile);
break;
case 3:
displayStudents(studentsFile);
break;
case 4:
addPayment(paymentsFile);
break;
case 5:
deletePayment(paymentsFile);
break;
case 6:
displayPayments(paymentsFile);
break;
case 7:
addCourse(coursesFile);
break;
case 8:
deleteCourse(coursesFile);
break;
case 9:
displayCourses(coursesFile);
break;
case 10:
addGrade(gradesFile);
break;
case 11:
deleteGrade(gradesFile);
break;
case 12:
displayGrades(gradesFile);
break;
case 0:
fclose(studentsFile);
fclose(paymentsFile);
fclose(coursesFile);
fclose(gradesFile);
return 0;
default:
printf("Invalid choice. Please try again.\n");
}
}
return 0;
}
```
请注意,此示例代码使用了文本文件来存储学生、缴费、课程和成绩信息。每个实体信息在文件中占据一行,以空格分隔。您可以根据需要进行修改和扩展,以适应实际的学生管理系统需求。
阅读全文