資源簡介
1.用文件保存試題庫。(每個試題包括題干、4個備選答案、標準答案)
2.試題錄入:可隨時增加試題到試題庫中
3.試題抽取:每次從試題庫中可以隨機抽出N道題(N由鍵盤輸入)
4.答題:用戶可實現輸入自己的答案
5.自動判卷:系統可根據用戶答案與標準答案的對比實現判卷并給出成績。
代碼片段和文件信息
#include
#include//應用動態存儲分配函數//
#include
#?define?LEN?sizeof(struct?question)
struct?question
{
char?ask[200];//選擇題題目//
char?answer[4][80];//選擇題選項每個答案的長度//
int?right;//正確答案//
struct?question?*next;//next是指針類型的成員,
//它指向struct?question類型數據(即next所在的結構體類型)
//使用指針類型成員存放下一個結點的地址
//此步驟實現了問題的連續輸入輸入
};
int?menu(void);//聲明菜單選擇函數
struct?question?*seek(struct?question?*seeklong?lenlong?max);//尋找讀取答案的位置
struct?question?*insert(struct?question?*fstconst?struct?question?*ad);//插入試題
void?getquestion(struct?question?*s);//獲取問題,選項,以及正確答案
void?savefile(const?struct?question?*aFILE?*sf);//保存最佳答案在文件中//
struct?question?*loadfile(struct?question?*bFILE?*lf);//讀取題目,將題目添加到列表中
int?getanswer(void);//得到答案
int?getyouranswer(void);//得到考生答案
void?explainquestion(const?struct?question?*qint?n);//統計答對題目數,顯示得分
//選擇菜單//
int?menu(void)
{
int?v;
printf(“1—添加選擇題\n2—回答選擇題\n3—退出\n“);
scanf(“%d“&v);
return?v;
}
//seek函數確定一個讀取答案的位置,len代表要讀取的答案數,max代表列表的長度//
struct?question?*seek(struct?question?*seeklong?lenlong?max)
{
int?i;
srand(time(NULL));
while(i=rand()%max+len while(i--)
seek=seek->next;//找到指定的位置//
return?seek;
}
//向列表中插入試題//
struct?question?*insert(struct?question?*fstconst?struct?question?*ad)
{
struct?question?*newptr=(struct?question?*)malloc(LEN);//分配新的內存空間//
if?(newptr==NULL)
exit(0);
*newptr=*ad;
newptr->next=fst;
return?newptr;
}
//獲取問題,選項,以及正確答案//
void?getquestion(struct?question?*s)
{
int?i=0;
printf(“請輸入選擇題題目:\n“);
scanf(“%s“s->ask);//指向結構體中的成員//
while(i<4)
{
printf(“請輸入選項%c的答案:\n“i+‘A‘);
scanf(“%s“s->answer[i++]);
}
s->right=getanswer();
}
//試題保存//
void?savefile(const?struct?question?*aFILE?*sf)//使用const說明成員函數//
{
fclose(sf);
if((sf=fopen(“kstm.dat““w“))==NULL)//以寫的方式重新打開文件//
return
- 上一篇:c語言實現json的創建及解析
- 下一篇:利用HDF4庫讀取*.hdf文件
評論
共有 條評論