文章目录

  • 前言:
  • 程序要求
  • 说明
  • 代码
    • main.c
    • def.c
    • myIO.c
    • file.c
    • menu.c
    • function.c

前言:

有朋友最近在做c语言课设,要求写一个班级成绩管理系统,便写份简单的代码来玩。代码原创,未参考任何其他人的代码

程序要求

说明

  • 本程序主要采用结构体数组
  • 本文件采用多文件编写,由于程序规模小,故未采用编写头文件的方式
  • 使用 #pragma once 来防止头文件重复包含

代码

怎么使用本程序看看注释应该就知道了。run main.c 就行。其他各文件作用:

  • def.c 定义了一些常量和全局变量,结构体
  • myIO.c 实现了成绩录入和成绩打印输出
  • file.c 实现了将成绩保存为文件
  • menu.c 实现了菜单功能
  • function.c 包含其他一些要用的函数

main.c

#include "menu.c"int main()
{select();return 0;
}

def.c

// 相同头文件只包含一次,后不赘述
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define OK 1
#define ERROR 0
#define TRUE 1
#define FALSE 0
#define Status int// 课程
typedef struct Course
{char name[30];int score;
} Course, *pCourse;// 学生
typedef struct Student
{char number[30];char name[30];pCourse pC;
} Student, *pStudent;// n是学生数, m是课程数
int n, m;
char courseName[30], studentName[30], course[20][30];
pStudent pS = NULL;

myIO.c

#pragma once
#include "def.c"pStudent inputStudentInfo(void);
void printStudentInfo(pStudent pS);// 录入学生信息
pStudent inputStudentInfo(void)
{int i, j;printf("Please input the number of students and courses: ");scanf("%d %d", &n, &m);printf("Please input the name of courses: ");for (i = 0; i < m; i++){scanf("%s", course[i]);}pStudent pS = (pStudent)malloc(sizeof(Student) * n);if (!pS)return NULL;printf("Please input the info: \n");for (i = 0; i < n; i++){pS[i].pC = (pCourse)malloc(sizeof(Course) * m);if (!pS[i].pC)return NULL;scanf("%s %s", pS[i].name, pS[i].number);for (j = 0; j < m; j++){strcpy(pS[i].pC[j].name, course[j]);scanf("%d", &pS[i].pC[j].score);}}return pS;
}// 打印所有学生信息
void printStudentInfo(pStudent pS)
{int i, j;// 打印标题printf("Name\tnumber\t");for (i = 0; i < m - 1; i++)printf("%s\t", course[i]);printf("%s\n", course[i]);// 显示信息for (i = 0; i < n; i++){printf("%s\t%s\t", pS[i].name, pS[i].number);for (j = 0; j < m - 1; j++)printf("%d\t", pS[i].pC[j].score);printf("%d\n", pS[i].pC[j].score);}
}

file.c

#pragma once
#include "def.c"
Status saveStudentInfo(pStudent pS);
Status saveStudentInfo(pStudent pS)
{FILE *fp;int i, j;char filename[30], str[100] = "student number";printf("please input the filename: ");scanf("%s", filename);fp = fopen(filename, "w");if (!fp)return ERROR;for (i = 0; i < m; i++){strcat(str, " ");strcat(str, course[i]);}strcat(str, "\n");for (i = 0; i < n; i++){strcat(str, pS[i].name);strcat(str, " ");strcat(str, pS[i].number);for (j = 0; j < m; j++){char score[30];itoa(pS[i].pC[j].score, score, 10);strcat(str, " ");strcat(str, score);}strcat(str, "\n");}fputs(str, fp);fclose(fp);return OK;
}

menu.c

#pragma once
#include "def.c"
#include "myIO.c"
#include "file.c"
#include "function.c"
void menu();
void select();
// 菜单
void menu()
{printf("------------------------------------\n");printf("|                Menu              |\n");printf("|              1. input            |\n");printf("|              2. show             |\n");printf("|              3. save             |\n");printf("|              4. sort             |\n");printf("|              5. modify           |\n");printf("|              6. count            |\n");printf("|              0. exit             |\n");printf("------------------------------------\n");
}void select()
{int branch;while (TRUE){system("cls");menu();printf("[Input]: ");scanf("%d", &branch);if (!branch)break;switch (branch){case 1:{pS = inputStudentInfo();if (pS == NULL)printf("input error! please input again\n");elseprintf("Input success!\n");system("pause");break;}case 2:{printStudentInfo(pS);system("pause");break;}case 3:{if (OK == saveStudentInfo(pS))printf("Save success!\n");elseprintf("Save fail!\n");system("pause");break;}case 4:{sort(pS);printf("sort success\n");system("pause");break;}case 5:{int res = modify(pS);if (res){printf("change success!\n");}else{printf("change fail!\n");}system("pause");break;}case 6:{int choose;// 输入1 显示每门课程最高成绩信息// 输入2 显示每门课程平均成绩信息printf("choose 1 for the highest score: \n ");printf("choose 2 for the average score: \n");printf("[Input]: ");scanf("%d", &choose);if (choose == 1){showMax(pS);}else if (choose == 2){showAverage(pS);}else{// 输入非法提示信息printf("Input error!\n");}system("pause");break;}}}
}

function.c

#include "def.c"void sort(pStudent pS);
void Swap(pStudent s1, pStudent s2);
void showAverage(pStudent pS);
void showMax(pStudent pS);
Status modify(pStudent pS);// 按课程成绩排序
void sort(pStudent pS)
{int courseNumber, i, j, k;char courseName[30];printf("please input the course name which you want to sort: ");scanf("%s", courseName);for (courseNumber = 0; courseNumber < m; courseNumber++)if (strcmp(course[courseNumber], courseName) == 0)break;// 如果找不到课程,则认为是按总分排序if (courseNumber == m){printf("Sort as total score: \n");// 选择排序for (i = 0; i < n - 1; i++){int flag = i;for (j = i + 1; j < n; j++){int totalScore_1 = 0, totalScore_2 = 0;for (k = 0; k < m; k++){totalScore_1 += pS[j].pC[k].score;totalScore_2 += pS[flag].pC[k].score;}if (totalScore_1 > totalScore_2){flag = j;}}Swap(&pS[i], &pS[flag]);}}else{// 选择排序for (i = 0; i < n - 1; i++){int flag = i;for (j = i + 1; j < n; j++){if (pS[j].pC[courseNumber].score > pS[flag].pC[courseNumber].score){flag = j;}}Swap(&pS[i], &pS[flag]);}}
}// 修改学生信息
Status modify(pStudent pS)
{// 密码是1314char password[30] = "1314", psd[30];char number[30];int score, i, j;printf("please input password: ");scanf("%s", psd);// 密码正确才继续,否则返回ERRORif (strcmp(password, psd) == 0){printf("please input the student's number: ");scanf("%s", number);for (i = 0; i < n; i++){// 找到学生则继续,否则返回ERRORif (strcmp(pS[i].number, number) == 0){printf("please input the course and score one by one: \n");scanf("%s %d", courseName, &score);for (j = 0; j < m; j++){// 找到课程才继续,否则返回ERRORif (strcmp(pS[i].pC[j].name, courseName) == 0){// 修改课程成绩pS[i].pC[j].score = score;return OK;}}return ERROR;}}return ERROR;}elsereturn ERROR;
}// 输出各课程最高分的学生
void showMax(pStudent pS)
{int i, j, max;for (i = 0; i < m; i++){max = 0;for (j = 0; j < n; j++){if (pS[j].pC[i].score > pS[max].pC[i].score)max = j;}printf("%s\t%s\t%s\t%d\n", course[i], pS[max].name, pS[max].number, pS[max].pC[i].score);}
}// 显示各课程的平均成绩
void showAverage(pStudent pS)
{int i, j;double ave;for (i = 0; i < m; i++){ave = 0;for (j = 0; j < n; j++){ave += pS[j].pC[i].score;}printf("%s\t%.2lf\n", course[i], ave / n);}
}void Swap(pStudent s1, pStudent s2)
{int i;char studentName[30], number[30];// 交换姓名strcpy(studentName, s1->name);strcpy(s1->name, s2->name);strcpy(s2->name, studentName);// 交换学号strcpy(number, s1->number);strcpy(s1->number, s2->number);strcpy(s2->number, number);// 交换成绩for (i = 0; i < m; i++){int temp = s1->pC[i].score;s1->pC[i].score = s2->pC[i].score;s2->pC[i].score = temp;}
}

C语言:班级成绩管理系统相关推荐

  1. C语言程序设计-班级成绩管理系统

    一.报告内容要求: 1.题目:班级成绩管理系统. 2.设计要求:对一个有N个学生的班级,每个学生有M门课程.该系统实现对班级成绩的录入.显示.修改.排序.保存等操作的管理. 3:功能要求:a.成绩录入 ...

  2. c语言编译班级成绩管理系统,C语言实现班级成绩管理系统

    C语言课程设计--班级成绩管理系统,供大家参考,具体内容如下 题目: 对一个有N个学生的班级,每个学生有M门课程.该系统实现对班级成绩的录入.显示.修改.排序.保存等操作的管理.功能 要求: (1)本 ...

  3. 班级成绩管理系统设计c语言,C语言程序设计-班级成绩管理系统.doc

    PAGE 课 程 设 计 报 告 课程名称 C语言程序设计 课题名称 班级成绩管理系统 专 业 机械设计 班 级 1083班 学 号 201013090303 姓 名 陈 玲 珑 指导教师 王 颖 2 ...

  4. 班级成绩管理系统(C语言)

    文章目录 一.设计任务与目标 二.实现功能 三.程序源码 四.效果展示 一.设计任务与目标 对一个有N个学生的班级,每个学生有M门课程.该系统实现对班级成绩的录入.显示.修改.排序.保存等操作的管理. ...

  5. 用C语言学生成绩数据库排序功能设计,[c语言学生成绩管理系统]C语言学生成绩管理系统实验报告...

    篇一 : C语言学生成绩管理系统实验报告 实 验 四:结构体(6学时) 实验目的: 1.更加灵活的使用数组作为函数参数: 2.初步掌握开发一个小型实用系统的基本方法: 3.初步掌握书写程序设计开发文档 ...

  6. C语言学生成绩管理系统(课程设计报告书)

    今天再跟大家分享一份课程设计报告:C语言学生成绩管理系统源码 程序设计组成框图: #include<stdio.h> #include<conio.h> #include< ...

  7. c语言学生成绩管理系统(增、删、查、改、排序、分析优秀及格率等)

    复制时运行出错请看这里:c语言学生成绩管理系统 添加公众号回复 学管 免费获取源代码 代做可私聊 c语言学生成绩管理系统(增.删.查.改.排序.分析优秀及格率等)详细内容 一.功能描述 实现学生基本信 ...

  8. c语言程序设计课题为车票管理系统,c语言 班级成管理系统.doc

    课 程 设 计 报 告 课程名称 C语言程序设计 课题名称 班级成绩管理系统 专 业 网络工程 班 级 1001 学 号 201003120129 姓 名 张剑 指导教师 唐北平.陈淑红.谭小兰 20 ...

  9. c语言程序设计班档案管理系统报告,C语言班级档案管理系统

    <C语言班级档案管理系统>由会员分享,可在线阅读,更多相关<C语言班级档案管理系统(28页珍藏版)>请在人人文库网上搜索. 1.c语言程序设计"课程设计报告班级档案管 ...

最新文章

  1. JAVA之JVM调优-从eclipse开始
  2. 如何在线把网站html生成xml文件_Sitemap在线生成器,网站地图在线生成工具
  3. win2008 server_R2 自动关机 解决
  4. python 服务端框架_GitHub - edisonlz/fastor: Python服务端开发框架-极易上手,超出你的想象!...
  5. 信息学奥赛一本通(2062:【例1.3】电影票)
  6. esxi 安装网卡驱动
  7. 苹果员工号召罢工 呼吁顾客平安夜不购买苹果产品
  8. 安全生产六步法是什么_支塘镇探索“五步法”压紧压实出租厂房安全生产主体责任...
  9. Linux下自动化监控内存、存储空间!
  10. 从入门到放弃C语言-入门篇(1)
  11. 域渗透-横向移动(PTH)
  12. 统计学习理论(SLT)与支持向量机(SVM)
  13. 情人节的自娱自乐——情书事件
  14. 对话腾讯云专家工程师常青,聊一聊全真互联网的“小小”变化
  15. C#结合数据库开发通讯录管理系统
  16. C# Revit二次开发基础/核心编程---建筑建模-标高和轴网
  17. 中国Linux发展前景怎么样?
  18. c语言中组件出现错误,错误消息:无法载入文件或组件 或其相依性的其中之一。 找到的组件资讯清单定义与组件参考不符。 (发生例外状况于 HRESULT: 0x80131040)...
  19. 平安好房想灭房产中介靠不靠谱?
  20. 以马丁格尔(翻倍加仓)为基础的长线交易策略

热门文章

  1. python中nonlocal是什么意思_Python中关键字nonlocal和global的声明与解析
  2. 如何走上通往IT职业的成功之路
  3. 厦门vr虚拟现实,工地安全教育VR体验,院校vr虚拟仿真实训系统,3d虚拟仿真交互系统开发
  4. 游戏图片推荐格式及压缩方式。TexturePacker、UE4、 贴图合并节约批次、贴图寻址、MipMap(一、参数设置)
  5. 对接服务,对方服务器更新SSL证书,服务https的get和post报错。 sun.security.validator.ValidatorException: PKIX path building
  6. 教你怎么夸一个项目经理
  7. centos8 开机自动运行dhclient
  8. 字符集与字符编码,java中的char和unicode
  9. 局域网arp攻击_「网络安全」常见攻击篇(23)——ARP攻击
  10. Excel每隔2行间隔设定颜色,是表格更加直观好看