二級C語言程序填空題型簡介
1、/**********found**********/
緊跟的下面一行的程序設空,一般為3個空;
2、常見錯誤:
(1)
(2)
3、做題推薦步驟:
(1)
(2)
---------------一、結構體---------------
2、題目要求【結構體】
程序通過定義學生結構體變量,存儲了學生的學號、姓名和3門課的成績。函數fun的功能是對形參b所指結構體變量中的數據進行修改,最后在主函數中輸出修改后的數據。 例如:b所指變量t中的學號、姓名和三門課的成績依次是:10002、“ZhangQi”、93.00、85.00、87.00,修改后輸出t中的數據應為: 10004、“LiJie”、93.00、85.00、87.00。請在程序的下劃線處填入正確的內容并把下劃線刪除,使程序得出正確的結果。注意:源程序存放在考生文件夾下的BLANK1.C中。不得增行或刪行,也不得更改程序的結構!
#include <stdio.h>
#include <string.h>
struct student {long sno;char name[10];float score[3];
};
void fun( struct student *b)
{
/**********found**********/b__1__ = 10004;
/**********found**********/strcpy(b__2__, "LiJie");
}
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__);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");getchar();
}
【我的答案】
#include <stdio.h>
#include <string.h>
struct student {long sno;char name[10];float score[3];
};
void fun( struct student *b)
{
/**********found**********/b->sno = 10004;//(1)結構體指針變量 訪問屬性的方式 ->
/**********found**********/strcpy(b->name, "LiJie");//(2)結構體指針變量 訪問屬性的方式 ->
}
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(&t);//(3)函數調用 參數為指針類型的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");getchar();
}
【知識點提要】
1、結構體:結構體指針變量屬性的訪問->
;普通結構體面兩屬性的訪問.
;(考察知識)
2、指針:指針變量就是記錄地址值的變量;指針變量的賦值;指針作為函數的參數。(考察知識)
【技巧總結】
1、變量賦值所在行,結構體的屬性缺失:①根據右值確定屬性;②根據變量類型確定訪問運算符為->
還是.
2、函數調用所在行,參數缺失:①查看函數定義時的參數列表中的形參類型;②檢查所在代碼塊相關變量的類型。
4、題目要求【結構體】
程序通過定義學生結構體變量,存儲了學生的學號、姓名和3門課的成績。函數fun的功能是將形參a所指結構體變量s中的數據進行修改,并把a中地址作為函數值返回主函數,在主函數中輸出修改后的數據。例如: a所指變量s中的學號、姓名、和三門課的成績依次是: 10001、 ”ZhangSan”、95、80、88, 修改后輸出t所指變量的數據應為: 10002、 "LiSi”、96、81、89。請在程序的下劃線處填入正確的內容并把下劃線刪除,使程序得出正確的結果。注意:源程序存放在文件BLANK1. C中,不得增行或刪行,也不得更改程序的結構。
#include <stdio.h>
#include <string.h>
struct student {long sno;char name[10];float score[3];
};
/**********found**********/
__1__ fun(struct student *a)
{ int i;a->sno = 10002;strcpy(a->name, "LiSi");
/**********found**********/for (i=0; i<3; i++) __2__ += 1;
/**********found**********/return __3__ ;
}
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");getchar();
}
【我的答案】
#include <stdio.h>
#include <string.h>
struct student {long sno;char name[10];float score[3];
};
/**********found**********/
struct student* fun(struct student *a)//(1)函數返回值類型缺失
{ int i;a->sno = 10002;strcpy(a->name, "LiSi");
/**********found**********/for (i=0; i<3; i++) a->score[i] += 1;//(2)for循環中,賦值語句左值缺失
/**********found**********/return a;//(3)函數返回值缺失
}
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")