学生成绩单统计与查询C语言作业,数据结构与算法C语言版 学生成绩统计

作者:杨

版权声明:

本文为博主原创文章,转载请附上源文链接!

本文链接:https://my.oschina.net/yangmufa/blog/3096426

首先创建一个线性表用来存储学生成绩,每个学生的成绩作为一个数据元素对应标注的一行。

定义线性表的结构体类型,成绩表的数据项包括 学号、姓名、数学、英语、政治、专业课1、专业课2、总成绩。

手机终端 显示不全 可在代码区 左右 滑动屏幕

#include

#include

#define MaxLength 255

//数据元素

typedef struct {

int id;//学号

char name[20];//姓名

int score[5];//英语、政治、专业课1、专业课2的成绩

int total;//总成绩

}studentElement;

//顺序表结构

typedef struct {

studentElement studentArray[MaxLength];

int length;

}seqList;

然后在operation.h定义并实现函数用于满足各种操作(

int InitList(seqList*seqList);  初始化(输入学生人数建立线性表长度,录入每个学生的各科成绩信息,计算出每个人总成绩)。

int Sort(seqList *seqList);  排序(首先输入要对所有人成绩排序的科目后按照升序排列,最后打印显示排序后的所有人成绩表。)

int Puery(seqList *seqList);  查询(输入学号,将线性表中的每个学生的学号与给定的字符串相比较若有匹配则打印显示该学生多所有信息,否则出错误提示。)

int Print(seqList *seqList);  (输出所有信息。)

)。

手机终端 显示不全 可在代码区 左右 滑动屏幕

#include

#include

#include "DataElement.h"

//初始化(输入学生人数建立线性表长度,录入每个学生的各科成绩信息,计算出每个人总成绩)。

int InitList(seqList*seqList){

int length=0;

int i=0;

int total=0;

int j=0;

printf("输入学生人数:");

scanf_s("%d",&length);

if(length<0||length>MaxLength){

printf("输入的学生人数不符合吹逻辑!Over!!!");

}else{

seqList->length=length;

}

if(seqList->length<0||seqList->length>MaxLength){

printf("初始化学生人数失败!\n");

return 0;

}else{

for(i=0;i

seqList->studentArray[i].total=0;//每个学生的确立之前总成绩归零

printf("输入第%d个人的信息:\n",i+1);

//输入学号和姓名

printf("学号:\n");

scanf("%d",&seqList->studentArray[i].id);

printf("姓名:\n");

scanf("%s",&seqList->studentArray[i].name);

//输入 数学、英语、政治、专业课1、专业课2的成绩

printf("数学:\n");

scanf_s("%d",&seqList->studentArray[i].score[0]);

printf("英语:\n");

scanf_s("%d",&seqList->studentArray[i].score[1]);

printf("政治:\n");

scanf_s("%d",&seqList->studentArray[i].score[2]);

printf("专业课1:\n");

scanf_s("%d",&seqList->studentArray[i].score[3]);

printf("专业课2:\n");

scanf_s("%d",&seqList->studentArray[i].score[4]);

printf("\n第%d个同学插入操作完毕!\n\n",i+1);

for(j=0;j<5;j++){//计算每个学生的总成绩

seqList->studentArray[i].total+=seqList->studentArray[i].score[j];

}

}

}

return 0;

};

//排序(首先输入要对所有人成绩排序的科目后按照升序排列,最后打印显示排序后的所有人成绩表。)

int Sort(seqList *seqList){

int option=0;

int i=0,j=0;

studentElement temp;

printf("开始排序......\n\n数学输入0,英语输入1,政治则输入2,专业课1输入3,专业课2输入4,总成绩输入5 \n");

printf("输入基于排序分数的科目:");

scanf("%d",&option);

if(option<6||option>=0){

//安装某科成绩升序排列

if(option>=0&&option<5){

for(i=0;ilength-1;i++){

for(j=i+1;jlength;j++){

if(seqList->studentArray[i].score[option]>seqList->studentArray[j].score[option]){

temp=seqList->studentArray[i];

seqList->studentArray[i]=seqList->studentArray[j];

seqList->studentArray[j]=temp;

}

}

}

printf("\n\n按某科成绩排序操作完毕!!!\n");

}

//安装某科成绩升序排列

if(option==5){

for(i=0;ilength-1;i++){

for(j=i+1;jlength;j++){

if(seqList->studentArray[i].total>seqList->studentArray[j].total){

temp=seqList->studentArray[i];

seqList->studentArray[i]=seqList->studentArray[j];

seqList->studentArray[j]=temp;

}

}

}

printf("\n按总成绩排序操作完毕!!!");

}

}else{

printf("输入不正确!!!");

}

return 0;

};

//查询(输入学号,将线性表中的每个学生的学号与给定的字符串相比较

//若有匹配则打印显示该学生多所有信息,否则出错误提示)。

int Puery(seqList *seqList){

int id=0;

int i=0;

printf("输入学号即可查询该生的所有信息:");

scanf_s("%d",&id);

if(id<0){

printf("\n学号不存在查询失败!\n\n");

}else{

for(i=0;ilength);i++){//打印输出各学生的全部信息

if(id==seqList->studentArray[i].id){

printf("学号:%d\n姓名:%s\n数学:%d\n英语:%d\n政治:%d\n\

专业课1:%d\n专业课2:%d\n总分:%d\n\n恭喜!查询成功!\n\n",\

seqList->studentArray[i].id,\

seqList->studentArray[i].name,\

seqList->studentArray[i].score[0],\

seqList->studentArray[i].score[1],\

seqList->studentArray[i].score[2],\

seqList->studentArray[i].score[3],\

seqList->studentArray[i].score[4],\

seqList->studentArray[i].total);

}

}

}

return 0;

};

//输出所有信息

int Print(seqList *seqList){

int i=0;

for(i=0;ilength;i++){

printf("|学号:%d|姓名:%s|数学:%d|英语:%d|政治:%d|专业课1:%d|专业课2:%d|总分:%d\n",\

seqList->studentArray[i].id,\

seqList->studentArray[i].name,\

seqList->studentArray[i].score[0],\

seqList->studentArray[i].score[1],\

seqList->studentArray[i].score[2],\

seqList->studentArray[i].score[3],\

seqList->studentArray[i].score[4],\

seqList->studentArray[i].total);

}

printf("\n打印完毕!\n");

return 0;

}

测试:

手机终端 显示不全 可在代码区 左右 滑动屏幕

#include

#include

#include "operation.h"

int main(){

seqList SL;

//seqList *SL=&sl;

InitList(&SL);

printf("--------------------------------------\n");

printf("排序前:\n");

Print(&SL);

printf("\n--------------------------------------\n");

Sort(&SL);

printf("\n--------------------------------------\n");

printf("排序后:\n");

Print(&SL);

printf("\n--------------------------------------\n");

Puery(&SL);

printf("\n--------------------------------------\n");

}

测试结果:

dadd7371d90db6acd0055143ca582293.png

486c68d7aa24891db560721bfb570551.png

/*-------------------反爬声明o(*▽*)咻咻咻--------------------

作者:版权声明:本文为博主倾情原创文章,整篇转载请附上源文链接!

如果觉得本文对你有所收获,你的请评论点赞 与

合理优质的转发也将是鼓励支持我继续创作的动力,

更多精彩可百度搜索 杨木发 或:

坚持创作 善于总结 开源共享 高质进步。

-------------------反爬声明o(*▽*)咻咻咻--------------------*/

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值