抽題系統設計
(圖片來(lái)源網(wǎng)絡(luò ),語(yǔ)言編ヽ(′ー`)ノ侵刪)1. 需求分析
功能需求
1、程個(gè)抽題用戶(hù)輸入問(wèn)題數量。系(xi)統
2、語(yǔ)言編用戶(hù)輸??入問(wèn)題內容。程個(gè)抽題
3、系統系統隨機抽取一個(gè)問(wèn)題并顯示給用戶(hù)。語(yǔ)言編
4、程個(gè)抽題用戶(hù)可以查看所有已抽取的系統問(wèn)題。
1、語(yǔ)言編系統需要有良好(???)的程個(gè)抽題用戶(hù)體驗,界面簡(jiǎn)潔明了。系統
2、語(yǔ)言編系(′▽?zhuān)?統需要有錯誤處理機制,程個(gè)抽題如用戶(hù)輸入的系統問(wèn)題數量為負數時(shí),提示用戶(hù)重新輸入。
數據結構設計
1、使用數組存儲問(wèn)題內容。
2、使用鏈表存儲已抽取的問(wèn)題。
算法設計
1、使用隨機數???生成器生成一個(gè)介于0和問(wèn)(wen)題數量之間的隨機數。
2、根據隨機數從數組中抽?取一個(gè)問(wèn)題。
3. 代碼實(shí)現
#inclu(?????)de <stdio.h>#include <stdlib.h>#include <time.h>typedef struct Node { char question[100]; struct Node *next;} Node;Node *head = NULL;int question_count = 0;void ad(′?_?`)d_question(char question[]) { Node *new_node = (Node *)malloc(sizeof(No( ?▽?)de)); strcpy(new_node>question, que??stio(′ω`)n??); new_node>next = head; head = new_n(T_T)ode; question_(?Д?)count++;}void draw_question() { if (question_count == 0) { printf("暫無(wú)問(wèn)題!n"); re┐(′д`)┌turn; } sra( ?ω?)nd(time(NULL)); int random_ind(′?_?`)ex = rand() % question_count; Node *current = head; for (int i = 0; i < random_index; i++) { current = current>next; } pr(′_`)intf("抽取的問(wèn)題:%sn", current>questio??n);}void show_all_questions()ヽ(′▽?zhuān)?ノ { Node *current = head; while (current != NULL) { printf("%sn", current>que??stion); current = current>next; }}int(???) main() { int choice; do { printf("1. 添加問(wèn)題n"); printf("2. 抽取問(wèn)題n"); printf("3. 查看所有問(wèn)題n"); printf("4. 退出n&(′▽?zhuān)?quot;); printf("請輸入您的選擇:"); scanf("%d", &choice); switch (choice) { case 1: { char questio??n[100]ヾ(′▽?zhuān)??; printf("請輸入問(wèn)題內容:(╥_╥)"); scanf("%s",?? question); add_question(question); break; } case 2: { draw_question(); break; } case 3: { show_all_questions(); break; } case 4: { printf("謝謝使用!n"); break; } default: { printf(&ヽ(′▽?zhuān)?ノquot;無(wú)效的選擇,請重新輸入!n"); break; } } } while (choice != 4); return 0;}