1 大家好2 我就是如假包换的...陈玲3 自从运营了C语言程序设计微信公众号4 很多粉丝都给我备注5 ...奇葩6 实在是不敢当7 也被人开始叫玲玲姐8 我知道9 很多人都想看我出境10 我本人也有 1年多的舞台演讲训练11 实话告诉大家 —— 我喜欢出境12

13 不过,既然我们做编程语言公众号的,就要去掉其他因素,我们挖掘文字本身所蕴含的力量。所以,这次分享的表达方式就是 —— 纯文字。14

15 今天的分享,只有一个目的16 就是上代码17 那么,准备好了18 #include

19 #include

20 //结构体可以存放的学生信息最大个数,不可变变量

21 int const MAX_LENGTH=100;22 //学生信息结构体数组,最多可以存放100个学生信息

23 structstudent{24 int id; //学号

25 char *name; //姓名

26 int age; //年龄

27 float c_score; //C语言成绩

28 float english_score; //英语成绩

29 float database_score; //数据库成绩

30 float total_score; //总分

31 }student_array[MAX_LENGTH];32

33 //学生信息数量

34 int student_count=0;35

36 //函数声明

37 voidprint_all_students();38 voidinput_info();39 voidquery_info();40 voidmodify_info();41 voiddelete_info();42 voidcompute_total_score();43 voidsort_info();44 intsearch_one_student();45 void print_one_student(structstudent one);46 void delete_one_student(intstudent_index);47 char * get_item_name(intitem_index);48 void modify_one_student(intstudent_index);49 voidsort_by_id();50 voidsort_by_c_score();51 voidsort_by_english_score();52 voidsort_by_database_score();53

54 //主函数

55 intmain()56 {57 while(1)58 {59 printf("请选择要使用的功能:n");60 printf("录入信息,请输入1,然后回车!n");61 printf("查询信息,请输入2,然后回车!n");62 printf("修改信息,请输入3,然后回车!n");63 printf("删除信息,请输入4,然后回车!n");64 printf("计算总分,请输入5,然后回车!n");65 printf("排序信息,请输入6,然后回车!n");66 printf("输出全部,请输入0,然后回车!n");67 printf("退出程序,请输入-1,然后回车!n");68 //函数选择变量

69 int function=0;70 //输入选择的函数编号值

71 scanf("%d",&function);72 //根据输入的函数编号,执行对应的功能

73 switch(function){74 case -1:75 exit(1);76 case 0:77 print_all_students();78 break;79 case 1:80 input_info();81 break;82 case 2:83 query_info();84 break;85 case 3:86 modify_info();87 break;88 case 4:89 delete_info();90 break;91 case 5:92 compute_total_score();93 break;94 case 6:95 sort_info();96 break;97 default:98 printf("请输入正确的功能编号!!!nn");99 break;100 }101 }102 return 0;103 }104

105 //录入信息函数

106 voidinput_info()107 {108 printf("当前功能————录入信息!n");109 //判断是否还有空间

110 if(student_count

113 int id=0; char *name=(char *)malloc(100);114 int age=0; float c_score=0;115 float english_score=0;116 float database_score=0;117 printf("请输入学生信息,格式为:学号,姓名,年龄,C语言成绩,英语成绩,数据库成绩n");118 scanf("%d %s %d %f %f %f",&id,name,&age,&c_score,&english_score,&database_score);119 printf("学生信息校对:学号:%d,姓名:%s,年龄:%d,C语言成绩:%f,英语成绩:%f,数据库成绩:%fn",id,name,age,c_score,english_score,database_score);120 //学生信息加入结构体数组

121 student_array[student_count].id=id;122 student_array[student_count].name=name;123 student_array[student_count].age=age;124 student_array[student_count].c_score=c_score;125 student_array[student_count].english_score=english_score;126 student_array[student_count].database_score=database_score;127 student_count++;128 //是否继续录入信息

129 printf("是否继续录入信息?继续请输入y,返回主菜单输入nn");130 chargo_on;131 scanf("%s",&go_on);132 if(go_on=='y')133 {134 input_info();135 }136 }137 else

138 {139 printf("学生结构体数据已满,可以删除一部分学生信息!n");140 }141 }142

143

144 //查询信息函数

145 voidquery_info()146 {147 printf("当前功能————查询信息!n");148 printf("请输入学生的学号n");149 int id=0;150 scanf("%d",&id);151 //查找输入id学生的序号

152 int student_index=search_one_student(id);153 if(student_index!=-1)154 {155 print_one_student(student_array[student_index]);156 }157 else

158 {159 printf("没有该学号的学生!n");160 }161 //是否继续查询信息

162 printf("是否继续查询信息?继续请输入y,返回主菜单输入nn");163 chargo_on;164 scanf("%s",&go_on);165 if(go_on=='y')166 query_info();167 }168

169

170 //修改信息函数

171 voidmodify_info()172 {173 printf("当前功能————修改信息!n");174 printf("请输入学生的学号n");175 int id=0;176 scanf("%d",&id);177 //查找输入id学生的序号

178 int student_index=search_one_student(id);179 if(student_index!=-1)180 {181 modify_one_student(student_index);182 }183 else

184 {185 printf("没有该学号的学生!n");186 }187 }188

189

190 //删除信息函数

191 voiddelete_info()192 {193 printf("当前功能————删除信息!n");194 printf("请输入学生的学号n");195 int id=0;196 scanf("%d",&id);197 //查找输入id学生的序号

198 int student_index=search_one_student(id);199 if(student_index!=-1)200 {201 //防止student_index被改变,传入temp_index计算

202 int temp_index=student_index;203 print_one_student(student_array[temp_index]);204 //删除前进行确认

205 printf("确定删除学号 %d 同学的信息?继续请输入yn",id);206 charbe_true;207 scanf("%s",&be_true);208 if(be_true=='y')209 {210 printf("%dn", student_index);211 //执行删除动作

212 delete_one_student(student_index);213 }214 }215 else

216 {217 printf("没有该学号的学生!n");218 }219 //是否继续删除信息

220 printf("是否继续删除信息?继续请输入y,返回主菜单输入nn");221 chargo_on;222 scanf("%s",&go_on);223 if(go_on=='y')224 delete_info();225 }226

227

228 //计算总分函数

229 voidcompute_total_score()230 {231 printf("当前功能————计算总分!n");232 for (int i = 0; i < student_count; ++i)233 {234 student_array[i].total_score=student_array[i].c_score+student_array[i].english_score+student_array[i].database_score;235 print_one_student(student_array[i]);236 printf("总成绩:%fn", student_array[i].total_score);237 }238 printf("总分计算完成!!!n");239 }240

241

242 //成绩排序函数

243 voidsort_info()244 {245 printf("当前功能————成绩排序!n");246 printf("排序前所有学生信息如下:n");247 print_all_students();248 intsort_type;249 while(1)250 {251 printf("请输入排序字段,学号:1,C语言成绩:2,英语成绩:3,数据库成绩:4n");252 scanf("%d",&sort_type);253 if(sort_type>=1&&sort_type<=4)254 break;255 }256 switch(sort_type)257 {258 case 1:259 sort_by_id();260 break;261 case 2:262 sort_by_c_score();263 break;264 case 3:265 sort_by_english_score();266 break;267 case 4:268 sort_by_database_score();269 break;270 }271 printf("排序后所有学生信息如下:n");272 print_all_students();273 //是否继续删除信息

274 printf("是否继续排序信息?继续请输入y,返回主菜单输入nn");275 chargo_on;276 scanf("%s",&go_on);277 if(go_on=='y')278 sort_info();279 }280

281

282 //根据输入的学号,遍历结构体数组,若存在该学生,返回数组下标,不存在返回-1

283 int search_one_student(intid)284 {285 for (int i = 0; i < student_count; ++i)286 {287 if(student_array[i].id==id)288 {289 returni;290 }291 }292 return -1;293 }294

295

296 //输出某个学生的信息

297 void print_one_student(structstudent one)298 {299 printf("学生信息:学号:%d,姓名:%s,年龄:%d,C语言成绩:%f,英语成绩:%f,数据库成绩:%fn",one.id,one.name,one.age,one.c_score,one.english_score,one.database_score);300 }301

302

303 //输出所有学生的信息

304 voidprint_all_students()305 {306 if(student_count==0)307 {308 printf("暂无学生信息nnn");309 }310 for (int i = 0; i < student_count; ++i)311 {312 print_one_student(student_array[i]);313 }314 }315

316

317 void modify_one_student(intstudent_index)318 {319 //修改前,输出学生信息

320 print_one_student(student_array[student_index]);321 //字段序号初始值

322 int item_index=0;323 //不允许修改学号字段

324 while(1)325 {326 printf("请输入要修改的字段序号,姓名:1,年龄:2,C语言成绩:3,英语成绩:4,数据库成绩:5n");327 scanf("%d",&item_index);328 if(item_index>=1&&item_index<=5)329 break;330 }331 switch(item_index)332 {333 case 1:334 printf("请输入 %s 字段的新值n", get_item_name(item_index));335 char* item_value_1=(char *)malloc(100);336 ;337 scanf("%s",item_value_1);338 student_array[student_index].name=item_value_1;339 break;340 case 2:341 printf("请输入 %s 字段的新值n", get_item_name(item_index));342 intitem_value_2;343 scanf("%d",&item_value_2);344 student_array[student_index].age=item_value_2;345 break;346 case 3:347 printf("请输入 %s 字段的新值n", get_item_name(item_index));348 floatitem_value_3;349 scanf("%f",&item_value_3);350 student_array[student_index].c_score=item_value_3;351 break;352 case 4:353 printf("请输入 %s 字段的新值n", get_item_name(item_index));354 floatitem_value_4;355 scanf("%f",&item_value_4);356 student_array[student_index].english_score=item_value_4;357 break;358 case 5:359 printf("请输入 %s 字段的新值n", get_item_name(item_index));360 floatitem_value_5;361 scanf("%f",&item_value_5);362 student_array[student_index].database_score=item_value_5;363 break;364 }365 printf("修改成功!新的学生信息如下:n");366 //修改后输出学生信息

367 print_one_student(student_array[student_index]);368 //是否继续删除信息

369 printf("是否继续修改该学生信息?继续请输入y,返回主菜单输入nn");370 chargo_on;371 scanf("%s",&go_on);372 if(go_on=='y')373 modify_one_student(student_index);374 }375

376

377 //删除数组对应序号的学生信息,把i位置后面的数据组元素向前移动覆盖i,student_count计数器减1

378 void delete_one_student(intstudent_index)379 {380 for (int i = student_index; i < student_count-1; ++i)381 {382 student_array[i]=student_array[i+1];383 }384 student_count--;385 printf("删除完成nnn");386 }387

388

389 //根据输入的字段序号,返回字段名称

390 char * get_item_name(intitem_index)391 {392 switch(item_index)393 {394 case 0:395 return "学号";396 case 1:397 return "姓名";398 case 2:399 return "年龄";400 case 3:401 return "C语言成绩";402 case 4:403 return "英语成绩";404 case 5:405 return "数据库成绩";406 default:407 return "";408 }409 }410

411

412 //按照id排序,使用最简单的冒泡排序法

413 voidsort_by_id()414 {415 for (int i = 0; i < student_count; ++i)416 {417 for (int j = i; j < student_count; ++j)418 {419 if(student_array[i].id>student_array[j].id)420 {421 struct student temp=student_array[i];422 student_array[i]=student_array[j];423 student_array[j]=temp;424 }425 }426 }427 printf("按照 学号 排序完成n");428 }429

430

431 //按照C语言成绩排序,使用最简单的冒泡排序法

432 voidsort_by_c_score()433 {434 for (int i = 0; i < student_count; ++i)435 {436 for (int j = i; j < student_count; ++j)437 {438 if(student_array[i].c_score>student_array[j].c_score)439 {440 struct student temp=student_array[i];441 student_array[i]=student_array[j];442 student_array[j]=temp;443 }444 }445 }446 printf("按照 C语言成绩 排序完成n");447 }448

449

450 //按照英语成绩排序,使用最简单的冒泡排序法

451 voidsort_by_english_score()452 {453 for (int i = 0; i < student_count; ++i)454 {455 for (int j = i; j < student_count; ++j)456 {457 if(student_array[i].english_score>student_array[j].english_score)458 {459 struct student temp=student_array[i];460 student_array[i]=student_array[j];461 student_array[j]=temp;462 }463 }464 }465 printf("按照 英语成绩 排序完成n");466 }467

468

469 //按照数据库成绩排序,使用最简单的冒泡排序法

470 voidsort_by_database_score()471 {472 for (int i = 0; i < student_count; ++i)473 {474 for (int j = i; j < student_count; ++j)475 {476 if(student_array[i].database_score>student_array[j].database_score)477 {478 struct student temp=student_array[i];479 student_array[i]=student_array[j];480 student_array[j]=temp;481 }482 }483 }484 printf("按照 数据库成绩 排序完成n");485 }486

487 转发自:微信公众号 xs-cyy

学生签到系统c代码_C语言学生管理系统源码分享相关推荐

  1. 学生签到系统c代码_C语言实现简单学生学籍管理系统

    #include #include #include #include #define N 100 /*存储100个学生的学籍信息*/ int flag; /*标记是否登录*/ struct date ...

  2. 学生签到系统c代码_C++实现学生考勤信息管理系统

    学生考勤信息管理系统记录了学生的缺课情况,它包括: 缺课日期.第几节课.课程名称.学生姓名.学生学号.缺课类型(迟到.请假及旷课).系统具有以下功能: 1).录入学生的缺课记录: 2).修改某个学生的 ...

  3. java进销存系统源码_青云源码——最新企业进销存管理系统源码分享

    基于http://Asp.Net MVC4.0 + WebAPI + Knockout 技术,采用EasyUI为前台开发展示UI,Knockout主要负责前端的逻辑交互,再结合jQuery Ajax进 ...

  4. 新版PHP云进销存系统ERP销售库存仓库员工管理系统源码

    简介: 新版云进销存系统ERP销售库存仓库员工管理系统源码,2022独家版本,带合同报价单打印,修复子账号不显示新加客户的BUG,还有其他方面的优化,网上流传的大多数都是老版本,没有这些功能,注意甄别 ...

  5. 2022新版云进销存系统ERP销售库存仓库员工管理系统源码

    正文: 2022新版PHP云进销存系统ERP销售库存仓库员工管理系统源码,2022独家版本,带合同报价单打印,修复子账号不显示新加客户的BUG,还有其他方面的优化,网上流传的大多数都是老版本,没有这些 ...

  6. 学生签到系统c代码_学生考勤系统源代码

    - 1 - 学生考勤系统源代码 void lace(int n)  /* 花边函数 */ { int i; for(i=0;i { putchar('*');   /* 输出 n 个 **/ } } ...

  7. 地理位置定位php代码,百度地理位置定位的源码分享

    百度地理位置定位的源码分享 实现百度定位 1. 使用APIclound IDE新建立一个项目,名称为定位: 2. 登陆APIclound官网,进入自己的控制台,会看到应用名称: 3. 使用自己的百度账 ...

  8. c语言json结构体_C语言解析JSON源码

    2020-01-09 关键字:cJSON.linux JSON解析 JSON 是一种在互联网领域内很常用的轻量级数据交换协议. 它与 XML 的地位差不多,但就笔者而言,笔者更喜欢 JSON 的风格, ...

  9. C# 系统应用之EM安全卫士总结及源码分享

    本文主要是总结自己"C#系统应用系列"的一篇文章,讲述以前的毕设"个人电脑使用记录清除软件设计与实现".希望对大家有所帮助,同时建议大家下载源代码,不论是界面还 ...

最新文章

  1. 静态链接库和动态链接库(转)
  2. 沈向洋谈做研究的那些事儿
  3. JavaScript 判断浏览器类型
  4. 计算机国家实验教学示范中心,教育部、财政部关于批准2007年国家级实验教学示范中心建设单位的通知...
  5. 深度学习-数学-第一篇-标量,向量,矩阵,张量
  6. 动态文本_(302期)【动态】|| 立足相同文本,描绘不同风景 ——工作室开展“同课异构”活动...
  7. POJ 1611 The Suspects(简单并查集)
  8. 全国青少年软件编程等级考试内容,知识点思维导图(Scratch编程三级)
  9. 免费从5sing上下载歌曲
  10. 快速排序的两种写法:左右填坑法与前后交换法
  11. linux征途架设教程,Linux下征途私服架设详细教程
  12. 阿里技术专家楚衡:架构制图的工具与方法论
  13. 学习PHP遇到的乱码问题
  14. python期货数据 库_如何用python或者基于vnpy框架将期货tick数据聚合成1分钟数据呢?...
  15. 海贼王:第86话 (希鲁鲁克的樱花与被继承的意志!)
  16. 【Andrew Gelman多元统计】(基于R)
  17. 【docker】出现segmentation fault,如何导出转储
  18. IFE2018-DAY05
  19. 小区宽带需求分析解决方案
  20. 一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第n次落地时,共经过多少米?第n次反弹多高?

热门文章

  1. Problem I. Hall of Fame (2014 Syria ICPC)
  2. Kotlin第三章:AndroidUI简介
  3. html 悬停 div,关于html:如何在div悬停时影响其他元素
  4. VS2019安装 VisualSVN Server 插件
  5. android 8.1 wifi提示“已连接 但无法访问互联网“的解决办法
  6. C/C++语言——数据类型
  7. javaSE探赜索隐之二<第二篇博客,磕磕绊绊,收货满满!加油>
  8. 一顿操作猛如虎,老罗也要啃老土
  9. 100天精通Python(基础篇)——第19天:练习题:我要买票吗
  10. linux 下使用isign 签名ipa包