单项选择题管理系统 密码123456 界面优美 带声音 界面切换 底色。。。。。。
密码
123456
#include<stdio.h>#include<stdlib.h>#include<time.h>struct pro{ int num; char ques[500]; char ansA[100]; char ansB[100]; char ansC[100]; char ansD[100]; char ans; int flag; struct pro * next;};void menu(int voice){ printf("⊙☆⊙ ⊙☆⊙ ⊙☆⊙ ⊙☆⊙ 主菜单 ⊙☆⊙ ⊙☆⊙ ⊙☆⊙ ⊙☆⊙\n"); printf("⊙☆⊙ ⊙☆⊙ ⊙☆⊙ 请按№ 1:创建第一批试题 ⊙☆⊙ ⊙☆⊙ ⊙☆⊙\n"); printf("⊙☆⊙ ⊙☆⊙ ⊙☆⊙ 请按№ 2:将题目保存到试题库 ⊙☆⊙ ⊙☆⊙ ⊙☆⊙\n"); printf("⊙☆⊙ ⊙☆⊙ ⊙☆⊙ 请按№ 3:随即选择题目进行解答 ⊙☆⊙ ⊙☆⊙ ⊙☆⊙\n"); printf("⊙☆⊙ ⊙☆⊙ ⊙☆⊙ 请按№ 4:打开已经保存的试题库 ⊙☆⊙ ⊙☆⊙ ⊙☆⊙\n"); printf("⊙☆⊙ ⊙☆⊙ ⊙☆⊙ 请按№ 5:增加试题 ⊙☆⊙ ⊙☆⊙ ⊙☆⊙\n"); printf("⊙☆⊙ ⊙☆⊙ ⊙☆⊙ 请按№ 6:输出所有试题 ⊙☆⊙ ⊙☆⊙ ⊙☆⊙\n"); printf("⊙☆⊙ ⊙☆⊙ ⊙☆⊙ 请按№ 9:退出程序 ⊙☆⊙ ⊙☆⊙ ⊙☆⊙\n\n"); printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!注意事项!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); printf("⊙☆⊙ ⊙☆⊙ ⊙☆⊙ 使用3和5和6时请确保已使用了1或4 ⊙☆⊙ ⊙☆⊙ ⊙☆⊙\n"); if(voice) printf("\a");}//****************************************创建试题*********************************************//struct pro * creat(struct pro * head)//创建试题{ struct pro *p1,*p2; int num=1,k=1; char a='Y'; getchar();//过滤掉主函数中产生的影响 while(a=='Y') { printf("请依次输入 '题目' 'A' 'B' 'C' 'D' 四个选项的内容 以及'正确答案' 每个占一行\n"); p1=(struct pro *)malloc(sizeof(struct pro)); p1->num=num; p1->next=NULL; gets(p1->ques);gets(p1->ansA);gets(p1->ansB);gets(p1->ansC);gets(p1->ansD);// puts(p1->ansA);puts(p1->ansB);puts(p1->ansC);puts(p1->ansD); scanf("%c",&p1->ans); getchar(); if(head==NULL) head=p1; else p2->next=p1; p2=p1; printf("是否进行下一个题目的输入,是请输入'Y'否则请输入'N':\n"); num++; scanf("%c",&a); getchar(); }return head;}//*****************************************输出所有试题*******************************************//print(struct pro * head)//输出所有的试题{ struct pro * temp; int k=14; char a; getchar(); printf("是否将正确答案一起输出 是请按'Y',否则请按'N':\n"); scanf("%c",&a); temp=head; while(temp!=NULL) { printf("题目号:%d\n",temp->num);// getchar(); puts(temp->ques); puts(temp->ansA);puts(temp->ansB);puts(temp->ansC);puts(temp->ansD); if(a=='Y') printf("正确答案:%c\n",temp->ans); printf("%c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c\n", k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k,k); temp=temp->next; }}//***********************************************写进文件**********************************************************// void to_file(struct pro * head) { struct pro *p1; // int num; FILE *fp; if((fp=fopen("c:\\Problem.txt","w+"))==NULL) { printf("Error on open c:\\Problem.txt!"); } else { p1=head; while(p1!=NULL) { fwrite(p1,sizeof(struct pro),1,fp); // fprintf(fp,"%d %s %s %s %s %s %c",p1->num,p1->ques,p1->ansA,p1->ansB,p1->ansC,p1->ansD,p1->ans); p1=p1->next; } } fclose(fp); } //*********************************************************************************************************************// struct pro * from_file(struct pro *head) { struct pro *p1,*p2; FILE *fp; if((fp=fopen("c:\\Problem.txt","r+"))==NULL) { printf("Error on open c:\\Problem.txt!"); } else { p1=(struct pro *)malloc(sizeof(struct pro)); p1->next=NULL; // while(fscanf(fp,"%d %s %s %s %s %s %c",&p1->num,p1->ques,p1->ansA,p1->ansB,p1->ansC,p1->ansD,&p1->ans)!=NULL) /*用上面的会造成1个选项里如果出现空格就只读取一半 也就是说遇到空格就会赋值进一个变量 然后进行下一个变量的读取而下面 是对一个模块进行读取的 反正如果是结构体 最好就用块读取 */ while(fread(p1,sizeof(struct pro),1,fp)!=NULL) { if(head==NULL) head=p1; else p2->next=p1; p2=p1; p1=(struct pro *)malloc(sizeof(struct pro)); p1->next=NULL; } } fclose(fp); return head; } //*********************************************添加问题*******************************************************// struct pro * add_pro(struct pro *head) { struct pro * p1,*temp; int num; temp=head; while(temp->next!=NULL) {temp=temp->next;} num=temp->num; num++; printf("请依次输入 '题目' 'A' 'B' 'C' 'D' 四个选项的内容 以及'正确答案' 每个占一行\n"); p1=(struct pro *)malloc(sizeof(struct pro)); p1->num=num; p1->next=NULL; getchar(); gets(p1->ques);gets(p1->ansA);gets(p1->ansB);gets(p1->ansC);gets(p1->ansD); scanf("%c",&p1->ans); getchar(); temp->next=p1; return head; } //******************************************选择问题进行解答************************************************************//void answer(struct pro *head){ int k,n,num; char ans; struct pro * temp; srand(time(NULL));//初始化随机数种子 temp=head; while(temp->next!=NULL) {temp->flag=0;temp=temp->next;} num=temp->num; temp->flag=0; printf("请输入您想要解答的问题的个数\n"); scanf("%d",&n); if(n<=num) { while(n--) { k=rand()%(num+1);//k是个随机数 这里回寝室再修改 // printf("k=%d,num=%d",k,num); if(k==0) k=num; // printf("k=%d",k); temp=head; while(temp->num!=k) {temp=temp->next;} if(temp->flag!=1) { printf("题目号:%d\n",temp->num); puts(temp->ques); puts(temp->ansA);puts(temp->ansB);puts(temp->ansC);puts(temp->ansD);temp->flag=1; printf("请输入您的答案:\n"); getchar(); scanf("%c",&ans); if(ans==temp->ans) printf("好聪明的娃子啊 嘿嘿 你对了!\n\n"); else printf("呜呜 可怜的** 你还得努力啊!\n\n"); } else n++; } } else printf("对不起,您输入的范围好像有点大了 先扩充下题库吧 呵呵!");}//***********************************************主函数****************************************************************//int main(){ // FILE *fp; __int64 code=123456,n; int k=3,voice,num; struct pro *head; system("color 2e"); printf("%c %c %c请输入您的“阿拉伯版密码”%c %c %c\a\n",1,3,2,1,3,2); while(k--) { scanf("%I64d",&n); if(n!=code) printf("您的密码有误,您还有%d次机会输入密码\n",k); else break; if(k==0) return 0; } system("cls"); printf("**********输入0选择静音,否则请输入其它任意数字**********\n"); scanf("%d",&voice); system("cls"); menu(voice); head=NULL; while(1) { scanf("%d",&num); switch (num) { case 1: head=creat(head);system("cls");menu(voice);printf("请选择下一步!\n");break; case 2: to_file(head);system("cls");menu(voice);printf("保存成功!\n");break; case 3: system("cls");answer(head);menu(voice);printf("测试完毕!\n");break; case 4: head=from_file(head);system("cls");menu(voice);printf("载入成功!\n");break; case 5: head=add_pro(head);system("cls");menu(voice);printf("添加成功!\n");break; case 6: system("cls");print(head);menu(voice);printf("输出完毕!\n");break; case 9: return 0; } }}