中国石油大学(华东)C语言在线测评答案-第12章结构体和共用体(2013级亲测正确).docxVIP

  • 66
  • 0
  • 约6.33千字
  • 约 11页
  • 2019-09-14 发布于江苏
  • 举报

中国石油大学(华东)C语言在线测评答案-第12章结构体和共用体(2013级亲测正确).docx

12.1 修改学生的各科成绩 给定程序通过定义并赋初值的方式,利用结构体变量存储了一名学生的学号、姓名和3门课的成绩。函数fun的功能是将该学生的各科成绩都乘以一个系数a。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:只需提交补充完整的fun函数和main函数 预设代码 /**********found**********/ void fun(___1___ *ss,float a) { ??? int i; ??? for(i=0; i3; i++) /**********found**********/ ??? ss-___2___ *=a; } int main(?? ) { ??? STU std={ 1,Zhanghua,76.5,78.0,82.0 }; ??? float a; ??? scanf(%f,a); /**********found**********/ ??? fun(___3___,a); ??? show(std); ??? return 0; } /* PRESET CODE BEGIN - NEVER TOUCH CODE BELOW */ #include stdio.h #include string.h #include stdio.h typedef struct { int num; char name[9]; float score[3]; }STU; void show(STU tt) { int i; printf(%d %s : ,tt.num,tt.name); for(i=0; i3; i++) printf(%5.1f,tt.score[i]); printf(\n); } /* PRESET CODE END - NEVER TOUCH CODE ABOVE */ /**********found**********/ void fun(STU *ss,float a) { int i; for(i=0; i3; i++) /**********found**********/ ss-score[i] *=a; } int main( ) { STU std={ 1,Zhanghua,76.5,78.0,82.0 }; float a; scanf(%f,a); /**********found**********/ fun(std,a); show(std); return 0; } 12.2 修改学生信息 程序通过定义学生结构体变量,存储了学生的学号、姓名和 3 门课的成绩。函数 fun 的功能是对形参 b 所指结构体变量中的数据进行修改 , 最后在主函数中输出修改后的数据。 例如 : b 所指变量 t 中的学号、姓名、和三门课的成绩依次是 : 10002 、 ZhangQi 、 93 、 85 、 87 ,修改后输出 t 中的数据应为: 10004 、 LiJie 、 93 、 85 、 87 。 请在程序的下划线处填入正确的内容并把下划线删除 , 使程序得出正确的结果。 不得增行或删行,也不得更改程序的结构! 注意:只需提交补充完整的fun函数和main主函数 预设代码 void fun( struct student? *b) { /**********found**********/ ??? b__1__ = 10004; /**********found**********/ ??? strcpy(b__2__, LiJie); } int main() { ??? struct student? t={10002,ZhangQi, {93, 85, 87}}; ??? int? i; /**********found**********/ ??? fun(__3__); ??? printf(No: %ld? Name: %s\nScores:,t.sno, t.name); ??? for (i=0; i3; i++)? printf(%6.2f, t.score[i]); ??? printf(\n); ??? return 0; } /* PRESET CODE BEGIN - NEVER TOUCH CODE BELOW */ #include stdio.h #include string.h struct student { long sno; char name[10]; float score[3

文档评论(0)

1亿VIP精品文档

相关文档