二级C语言上机填空题技巧总结

  • 格式:doc
  • 大小:214.06 KB
  • 文档页数:19

上机填空题技巧总结 一、 填空题之方法 1. 上机填空题占30分,一般有3个空需要填写,每个空为10分; 2. 填空题做题之前必须弄清题目含义,抓住关键字,例如:要求对数组进行从小到大排序,则将会出现大于符号,如果是从大到小排序则出现小于符号; 3. 填空题中出现频率最高的就是函数的调用、函数的首部、函数的返回值等和函数相关的问题,因此必须牢牢掌握祝函数的基本特征; 4. 填空题中有的“空”比较难,考生除了掌握必须的C语言知识之外,还需要很好的逻辑思路,如果一个空将花很多时间来解决,那么建议使用“死记硬背”的方法来缩短复习时间; 5. 上机题库中100题有部分题目是重复的或是相似的题目很多,同学们要使用比对的方法尽量去理解; 6. 多练习,多思考,多总结

二、 填空题与结构体相关 1. 结构体成员引用:上机题库P18第9题(和92题一致),P27第23题(和51题一样)

读清楚题目要求: (1) 要求将形参a所指结构体变量的数据赋值给函数中的结构体变量b (2) 从例如可以看出来:结构体中的学号和姓名变为了1002和“LiSi”,但是3门课成绩没有变化 23题:

(1) 从例如中可以看出:变化的是结构体中的学号和姓名

#include #include struct student { long sno; char name[10]; float score[3]; }; void fun(struct student a) { struct student b; int i; /**********found**********/ b = __1__;题目要求将形参a的值赋值给结构体变量b,因此填:a b.sno = 10002;学号变为了10002 /**********found**********/ strcpy(__2__, "LiSi");姓名要变为”LiSi”,则要引用b中的name成员 printf("\nThe data after modified :\n");/*讲解是一句带过不用多讲*/ printf("\nNo: %ld Name: %s\nScores: ",b.sno, b.name); /*讲解是一句带过不用多讲*/ /**********found**********/ for (i=0; i<3; i++) printf("%6.2f ", b.__3__);分析:这个是一个循环语句,执行3次循环,printf("%6.2f ", b.__3__)要求输出是一个实型数据的成员,因此可以得知是score成员,因为score是一个数组,因此填:b.score[i],当i变化就可以取出第一门、第二门、第三门课的成绩 printf("\n"); } main() { struct student s={10001,"ZhangSan", 95, 80, 88}; int i; printf("\n\nThe original data :\n"); printf("\nNo: %ld Name: %s\nScores: ",s.sno, s.name); for (i=0; i<3; i++) printf("%6.2f ", s.score[i]); printf("\n"); fun(s); } 2. 函数调用and结构体:上机题库P22第16题(和78、82题一样)

重点注意: (1)把a中地址作为函数返回值返回函数 (2)观察可知a中的学号、姓名边为了10002和“zhangSan”,每门课的成绩增加了1分

#include #include struct student { long sno; char name[10]; float score[3]; }; void fun( struct student *b) { int i; /**********found**********/ b__1__ = 10004;题目中t的学号变化为了10004,因此填写:b->sno,不能填写b.sno,因为b是一个指针 /**********found**********/ strcpy(b__2__, "LiJie");t的姓名变为了”LiJie”,因此填写:b->name } main() { struct student t={10002,"ZhangQi", 93, 85, 87}; int i; printf("\n\nThe original data :\n"); printf("\nNo: %ld Name: %s\nScores: ",t.sno, t.name); for (i=0; i<3; i++) printf("%6.2f ", t.score[i]); printf("\n"); /**********found**********/ fun(__3__);此处为函数调用,根据形参的类型来判定实参,形参struct student *b为结构体指针,联系main函数定义部分只有struct student t和b的类型相同,因此可知需要填的是:&t printf("\nThe data after modified :\n"); printf("\nNo: %ld Name: %s\nScores: ",t.sno, t.name); for (i=0; i<3; i++) printf("%6.2f ", t.score[i]); printf("\n"); } 3. 结构体和排序:上机题库P14第2题 重点注意:

#include #include struct student { long sno; char name[10]; float score[3]; }; /**********found**********/ __1__ fun(struct student *a)根据函数调用t = fun(&s);可知函数返回类型和t的类型相同,struct student s={10001,"ZhangSan", 95, 80, 88}, *t;可知t的类型为struct student * { int i; a->sno = 10002; strcpy(a->name, "LiSi"); /**********found**********/ for (i=0; i<3; i++) __2__ += 1;题目要求将每门课成绩增加1分,因此填为:a->score[i],不能为a.score[i]或是a.score /**********found**********/ return __3__ ;题目要求返回a的地址,a本身就是一个指针,因此填入a即可 } main() { struct student s={10001,"ZhangSan", 95, 80, 88}, *t; int i; printf("\n\nThe original data :\n"); printf("\nNo: %ld Name: %s\nScores: ",s.sno, s.name); for (i=0; i<3; i++) printf("%6.2f ", s.score[i]); printf("\n"); t = fun(&s); printf("\nThe data after modified :\n"); printf("\nNo: %ld Name: %s\nScores: ",t->sno, t->name); for (i=0; i<3; i++) printf("%6.2f ", t->score[i]); printf("\n"); } (1)排序的格式:红色部分为考试中的重点,必须记住

从小到大排序: for(i=0;ia[j]) {t=a[i];a[i]=a[j];a[j ]=t;} 从大到小排序: for(i=0;ifor(j=i+1;jif(a[i]{t=a[i];a[i]=a[j];a[j ]=t;}

void fun(struct student a[], int n) { /**********found**********/ __1__ t;此处要求填入t的类型,可以从t = a[i];中得知t和a数组的类型必须一致,void fun(struct student a[], int n)中得知a为结构体类型,因此填写:struct student int i, j; /**********found**********/ for (i=0; i<__2__; i++)根据排序的格式填空,因此记住是关键 for (j=i+1; j/**********found**********/ if (strcmp(__3__) > 0)按照姓名字典顺序从小到大排序,因此: strcmp(a[i].name,a[j].name),此处需要特别注意 { t = a[i]; a[i] = a[j]; a[j] = t; } } main() { struct student s[4]={{10001,"ZhangSan", 95, 80, 88}, {10002,"LiSi", 85, 70, 78}, {10003,"CaoKai", 75, 60, 88}, {10004,"FangFang", 90, 82, 87}}; int i, j; printf("\n\nThe original data :\n\n"); for (j=0; j<4; j++) { printf("\nNo: %ld Name: %-8s Scores: ",s[j].sno, s[j].name); for (i=0; i<3; i++) printf("%6.2f ", s[j].score[i]); printf("\n"); } fun(s, 4); printf("\n\nThe data after sorting :\n\n"); for (j=0; j<4; j++) { printf("\nNo: %ld Name: %-8s Scores: ",s[j].sno, s[j].name); for (i=0; i<3; i++) printf("%6.2f ", s[j].score[i]); printf("\n"); } }