用C語言寫一個(gè)抽獎系統(tǒng)-創(chuàng)新互聯(lián)

本篇內(nèi)容主要講解“用C語言寫一個(gè)抽獎系統(tǒng)”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“用C語言寫一個(gè)抽獎系統(tǒng)”吧!

創(chuàng)新互聯(lián)公司自2013年起,先為延長等服務(wù)建站,延長等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為延長企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

該程序的功能包括:


1、設(shè)置中獎人員2、設(shè)置內(nèi)幕人員3、添加功能4、刪除功能5、顏色設(shè)置6、開發(fā)人員介紹

在使用該系統(tǒng)之前,請先在你程序保存的位置建一個(gè)17計(jì)科2.txt文檔,里面填上學(xué)號和姓名,例如:25 賀志營。

建好txt文檔后就可以直接運(yùn)行了

代碼如下:

開始抽獎界面不好演示,它是個(gè)動態(tài)的,下面有代碼,可以自己運(yùn)行下

程序代碼:

#include<stdio.h>#include<string.h>#include<stdlib.h>#include<conio.h>#include<time.h>#include <windows.h>//#pragma comment(lib, "winmm.lib") struct data{ char id[20]; char name[20];};  struct data information[110];//普通人員信息struct data information0[110];//滾動人員信息struct data prize[110];//總獲獎人員信息struct data winner1[110],winner2[110],winner3[110];//內(nèi)幕人員信息 int grade1=0,grade2=0,grade3=0;//內(nèi)幕一等獎、二等獎、三等獎的人數(shù)int ms=60;//初始滾動時(shí)間間隔int count=0;//滾動人員總數(shù)int people=0;//普通人員總數(shù)int people1=0,people2=0,people3=0;//普通一等獎、二等獎、三等獎的人數(shù)char strid[20]; void Function_introduction();//功能介紹void Print_menu();//打印菜單void Set_award();//設(shè)置獎項(xiàng)void Read_information();//從文件中讀取信息,放到普通人員信息中void Read_information0();//從文件中讀取信息,放到滾動人員信息中void Roll_information0();//滾動信息,該信息是滾動人員的信息  void Set_speed();//設(shè)置滾動時(shí)間間隔void Set_colour();//顏色設(shè)置void Set_grade();//設(shè)置必中獎等級void Set_winner1();//設(shè)置一等獎信息void Set_winner2();//設(shè)置二等獎信息void Set_winner3();//設(shè)置三等獎信息void Set_awards();//設(shè)置獎項(xiàng)人數(shù) void Delet_function();//刪除功能void Delet_number();//按學(xué)號刪除void Delet_name();//按姓名刪除void Delet_information();//刪除普通人員的信息void Delet_information0();//刪除內(nèi)幕人員信息void Add_function();//添加功能void Begin_luck();//開始抽獎void Roll_speed(int ms);//滾動速度void Developer();//開發(fā)人員介紹 int main(){  Read_information(); Read_information0(); system("color 07"); Print_menu();  return 0;} void Function_introduction()//功能介紹{ system("cls"); printf("\n\t\t  <-抽獎系統(tǒng)功能介紹->\n\n"); printf("\t\t\t1、設(shè)置中獎人員\n"); printf("\t\t\t2、設(shè)置內(nèi)幕人員\n"); printf("\t\t\t3、添加功能\n"); printf("\t\t\t4、刪除功能\n"); printf("\t\t\t5、顏色設(shè)置\n"); printf("\t\t\t6、開發(fā)人員介紹\n"); printf("\t\t\t按任意鍵返回"); getch(); } void Print_menu()//打印菜單{ int choose; while(1) { system("cls"); printf("\n\n"); printf("\t*********************************************************\n");  printf("\t*\t  <-歡迎來到抽獎系統(tǒng)->\t\t\t*\n"); printf("\t*\t\t\t\t\t\t\t*\n");  printf("\t*\t\t開始抽獎?wù)埌?\t\t\t\t*\n"); printf("\t*\t\t設(shè)置獎項(xiàng)請按2\t\t\t\t*\n"); printf("\t*\t\t滾動設(shè)置請按3\t\t\t\t*\n"); printf("\t*\t\t顏色設(shè)置請按4\t\t\t\t*\n"); printf("\t*\t\t添加功能請按5\t\t\t\t*\n"); printf("\t*\t\t刪除功能請按6\t\t\t\t*\n"); printf("\t*\t\t人員介紹請按7\t\t\t\t*\n"); printf("\t*\t\t功能介紹請按8\t\t\t\t*\n"); printf("\t*\t\t結(jié)束程序請按0\t\t\t\t*\n"); printf("\t*\t\t\t\t\t\t\t*\n"); printf("\t*********************************************************\n");  printf("\n\n\t\t\t請輸入選項(xiàng):"); scanf("%d",&choose);  switch(choose) { case 0: return; case 1: Begin_luck();//開始抽獎 break; case 2: Set_award();//設(shè)置獎項(xiàng) break; case 3: Set_speed();//設(shè)置滾動時(shí)間間隔 break; case 4: Set_colour();//顏色設(shè)置 break; case 5: Add_function();//添加功能  break; case 6: Delet_function();//刪除功能 break; case 7: Developer();//開發(fā)人員介紹 break; case 8: Function_introduction();//功能介紹 break; } }} void Set_award()//設(shè)置獎項(xiàng){ int choose; while(1) { system("cls"); printf("\n\n"); printf("\t*********************************************************\n"); printf("\t*\t\t\t\t\t\t\t*\n"); printf("\t*\t\t設(shè)置獎項(xiàng)人數(shù)請按1\t\t\t*\n"); printf("\t*\t\t設(shè)置內(nèi)幕人員請按2\t\t\t*\n"); printf("\t*\t\t返回上一層請按0\t\t\t\t*\n"); printf("\t*\t\t\t\t\t\t\t*\n"); printf("\t*********************************************************\n");  printf("\n\n\t\t\t請輸入選項(xiàng):"); scanf("%d",&choose); switch(choose) { case 0: return; case 1: Set_awards();//設(shè)置獎項(xiàng)人數(shù)  break; case 2: Set_grade();//設(shè)置內(nèi)幕人員 break; } }} void Set_colour()//顏色設(shè)置{ char choose[20]; int i; system("cls"); printf("\n\n\t0 = 黑色  8 = 灰色\n"); printf("\t1 = 藍(lán)色  9 = 淡藍(lán)色\n"); printf("\t2 = 綠色  A = 淡綠色\n"); printf("\t3 = 淺綠色  B = 淡淺綠色\n"); printf("\t4 = 紅色  C = 淡紅色\n"); printf("\t5 = 紫色  D = 淡紫色\n"); printf("\t6 = 黃色  E = 淡黃色\n"); printf("\t7 = 白色  F = 亮白色\n\n"); printf("\t請輸入字體顏色對應(yīng)的代碼:"); scanf("%s",choose); if(strcmp(choose,"0")==0) system("color 00"); else if(strcmp(choose,"1")==0) system("color 01"); else if(strcmp(choose,"2")==0) system("color 02"); else if(strcmp(choose,"3")==0) system("color 03"); else if(strcmp(choose,"4")==0) system("color 04"); else if(strcmp(choose,"5")==0) system("color 05"); else if(strcmp(choose,"6")==0) system("color 06"); else if(strcmp(choose,"7")==0) system("color 07"); else if(strcmp(choose,"8")==0) system("color 08"); else if(strcmp(choose,"9")==0) system("color 09"); else if(strcmp(choose,"A")==0) system("color 0A"); else if(strcmp(choose,"B")==0) system("color 0B"); else if(strcmp(choose,"C")==0) system("color 0C"); else if(strcmp(choose,"D")==0) system("color 0D"); else if(strcmp(choose,"E")==0) system("color 0E"); else if(strcmp(choose,"F")==0) system("color 0F"); else { printf("輸入錯誤按任意鍵返回上一層\n"); getch(); return; } printf("\t設(shè)置完畢按任意鍵返回"); getch(); } void Delet_function()//刪除功能{ int choose; while(1) { system("cls"); printf("\n\n"); printf("\t*********************************************************\n"); printf("\t*\t\t\t\t\t\t\t*\n"); printf("\t*\t\t按姓名刪除請按1\t\t\t\t*\n"); printf("\t*\t\t按學(xué)號刪除請按2\t\t\t\t*\n"); printf("\t*\t\t返回上一層請按0\t\t\t\t*\n"); printf("\t*\t\t\t\t\t\t\t*\n"); printf("\t*********************************************************\n");  printf("\n\n\t\t\t請輸入選項(xiàng):"); scanf("%d",&choose); switch(choose) { case 0: return; case 1: Delet_name();//按姓名刪除 break; case 2: Delet_number();//按學(xué)號刪除 break; } }} void Read_information()//從文件中讀取信息{ FILE *fp=fopen("17計(jì)科2.txt","r"); while(!feof(fp)) { //存儲該信息到普通人員信息中,便于設(shè)置內(nèi)幕人員 fscanf(fp,"%s%s",information[people].id,information[people].name); people++; } fclose(fp);} void Read_information0()//讀取滾動人員的信息{ FILE *fp=fopen("17計(jì)科2.txt","r"); while(!feof(fp)) { //存儲信息到滾動人員信息中,用于滾動時(shí)打印在顯示屏幕中 fscanf(fp,"%s%s",information0[count].id,information0[count].name); count++; } fclose(fp);} void Roll_information0()//滾動信息,該信息是滾動人員的信息{ int i=0; system("cls"); printf("按任意鍵開始抽獎,按任意鍵停止抽獎\n"); getch();// PlaySound (TEXT("C:中國人民解放軍軍樂團(tuán)-國際歌.wav"), NULL, SND_ASYNC | SND_NODEFAULT); while(1) { system("cls"); if(kbhit()!=0) break; i=rand()%count; printf("%s",information0[i].name);//顯示滾動信息 //i++; //if(i==count) //i=0; Roll_speed(ms); }// PlaySound (0, NULL, SND_ASYNC | SND_NODEFAULT);} void Begin_luck()//開始抽獎{ int i,j,choose,t; system("cls"); if(grade3==0&&grade2==0&&grade3==0&&people1==0&&people2==0&&people3==0) {  printf("請先設(shè)置獎項(xiàng)人數(shù)按任意鍵返回\n"); getch(); return; } printf("下面開始抽取三等獎人員,按任意鍵繼續(xù)\n"); getch(); j=0;//代表各獎項(xiàng)人員的總數(shù)包括內(nèi)幕人員 while(grade3--)//內(nèi)幕三等獎人員 { if(grade3<0) break; Roll_information0(); printf("%s",winner3[grade3].name); prize[j++]=winner3[grade3]; strcpy(strid,winner3[grade3].id); Delet_information0();//刪除該成員在滾動信息中的信息 getch(); getch(); } while(people3--)//普通三等獎人員 { if(people3<0) break; Roll_information0(); srand((unsigned)time(0)); t=rand()%people; printf("%s",information[t].name); prize[j++]=information[t];  strcpy(strid,information[t].id); Delet_information();//刪除該成員在普通信息中的信息 Delet_information0();//刪除該成員在滾動信息中的信息 //printf("\n\n\n"); //for(i=0;i<count;i++) //printf("%s ",information0[i].name); getch(); getch(); } system("cls"); printf("以下是三等獎名單,按任意鍵繼續(xù)\n"); for(i=0;i<j;i++) printf("%s\n",prize[i].name); getch();   system("cls"); printf("下面開始抽取二等獎人員,按任意鍵繼續(xù)\n"); getch(); j=0; while(grade2--) { if(grade2<0) break; Roll_information0();//顯示滾動人員信息 printf("%s",winner2[grade2].name); prize[j++]=winner2[grade2]; strcpy(strid,winner2[grade2].id); Delet_information0();//刪除該成員在滾動信息中的信息 getch(); getch(); }  while(people2--) { if(people2<0) break; Roll_information0(); srand((unsigned)time(0)); t=rand()%people; printf("%s",information[t].name); prize[j++]=information[t]; strcpy(strid,information[t].id); Delet_information();//刪除該成員在普通信息中的信息 Delet_information0();//刪除該成員在滾動信息中的信息 getch(); getch(); } system("cls"); printf("以下是二等獎名單,按任意鍵繼續(xù)\n"); for(i=0;i<j;i++) printf("%s\n",prize[i].name); getch();  system("cls"); printf("下面開始抽取一等獎人員,按任意鍵繼續(xù)\n"); getch(); j=0; while(grade1--)//內(nèi)幕一等獎人員 { if(grade1<0) break; Roll_information0(); printf("%s",winner1[grade1].name); prize[j++]=winner1[grade1]; strcpy(strid,winner1[grade1].id); Delet_information0();//刪除該成員在滾動信息中的信息 getch(); getch(); } while(people1--) { if(people1<0) break; Roll_information0(); srand((unsigned)time(0)); t=rand()%people; printf("%s",information[t].name); prize[j++]=information[t];  strcpy(strid,information[t].id); Delet_information();//刪除該成員在普通信息中的信息 Delet_information0();//刪除該成員在滾動信息中的信息 getch(); getch(); } system("cls"); printf("以下是一等獎名單,按任意鍵繼續(xù)\n"); for(i=0;i<j;i++) printf("%s\n",prize[i].name);  printf("抽獎完畢按任意鍵返回\n"); getch();}  void Set_speed()//滾動速度{ char choose[20]; int i,t=0; system("cls"); printf("請輸入滾動時(shí)間間隔\n"); scanf("%s",choose); for(i=0;choose[i]!='';i++) if(choose[i]<'0'||choose[i]>'9') { printf("輸入有誤按任意鍵返回"); getch(); return; } else t=10*t+choose[i]-'0'; ms=t; printf("設(shè)置完畢按任意鍵返回\n"); getch();} void Roll_speed(int ms){ clock_t t1,t2; t1=clock(); while(1) { t2=clock(); if(t2-t1>=ms) return; }} void Set_awards()//設(shè)置獎項(xiàng)人數(shù){ int choose,t; while(1) { system("cls"); printf("請輸入三等獎人數(shù)(正整數(shù)):\n"); scanf("%d",&t); if(t<0||t>count) { printf("輸入不合法,請輸入1到%d之內(nèi)的數(shù)字",count); getch(); } else { people3+=t; break; }  } while(1) { system("cls"); printf("請輸入二等獎人數(shù):\n"); scanf("%d",&t); if(t<1||t>count) { printf("輸入不合法,請輸入1到%d之內(nèi)的數(shù)字",count); getch();  } else { people2+=t; break; }   } while(1) { system("cls"); printf("請輸入一等獎人數(shù):\n"); scanf("%d",&t); if(t<0||t>count) { printf("輸入不合法,請輸入1到%d之內(nèi)的數(shù)字",count); getch(); } else { people1+=t; break; } } printf("設(shè)置完畢按任意鍵返回\n"); getch(); return;} void Set_grade()//設(shè)置內(nèi)幕中獎等級{ char grade[20]; system("cls"); printf("請輸入中獎等級,返回上一層請按0\n"); scanf("%s",grade); if(strcmp(grade,"0")==0) return;  else if(strcmp(grade,"1")==0) Set_winner1(); else if(strcmp(grade,"2")==0) Set_winner2(); else if(strcmp(grade,"3")==0) Set_winner3(); else { printf("請輸入1到3等級按任意鍵返回\n"); getch(); return; }} void Set_winner1()//設(shè)置內(nèi)幕一等獎信息{ int i,j; system("cls"); printf("請輸入必中獎人員學(xué)號和姓名:\n"); scanf("%s%s",winner1[grade1].id,winner1[grade1].name); for(i=0;i<count;i++) if(strcmp(winner1[grade1].id,information0[i].id)==0) break; for(j=0;j<count;j++) if(strcmp(winner1[grade1].name,information0[i].name)==0) break; if(i==count||j==count) { printf("抽獎名單中無此信息按任意鍵返回"); getch(); return;  } printf("設(shè)置成功按任意鍵繼續(xù)"); getch(); strcpy(strid,winner1[grade1].id); Delet_information();//普通總成員減1 grade1++;//內(nèi)幕一等獎成員加1 people1--;//普通一等獎成員減1 return;} void Set_winner2()//設(shè)置內(nèi)幕二等獎信息{ int i,j; system("cls"); printf("請輸入必中獎人員學(xué)號和姓名:\n"); scanf("%s%s",winner2[grade2].id,winner2[grade2].name); for(i=0;i<count;i++) if(strcmp(winner2[grade2].id,information0[i].id)==0) break; for(j=0;j<count;j++) if(strcmp(winner2[grade2].name,information0[i].name)==0) break; if(i==count||j==count) { printf("抽獎名單中無此信息按任意鍵返回"); getch(); return; } printf("設(shè)置成功按任意鍵繼續(xù)"); getch(); strcpy(strid,winner2[grade2].id); Delet_information();//普通總?cè)藛T減1 grade2++;//內(nèi)幕二等獎人員加1 people2--;//普通二等獎人員減1 return;} void Set_winner3()//設(shè)置內(nèi)幕三等獎信息{ int i,j; system("cls"); printf("請輸入必中獎人員學(xué)號和姓名:\n"); scanf("%s%s",winner3[grade3].id,winner3[grade3].name); for(i=0;i<count;i++) if(strcmp(winner3[grade3].id,information0[i].id)==0) break; for(j=0;j<count;j++) if(strcmp(winner3[grade3].name,information0[i].name)==0) break; if(i==count||j==count) { printf("抽獎名單中無此信息按任意鍵返回"); getch(); return; } printf("設(shè)置成功按任意鍵繼續(xù)"); getch(); strcpy(strid,winner3[grade3].id); Delet_information();//普通總?cè)藛T減1 grade3++;//內(nèi)幕三等獎人員加1 people3--;//普通三等獎人員減1 return;} void Delet_number()//按學(xué)號刪除{ int i; system("cls"); while(1) {  printf("請輸入要刪除人的學(xué)號\n"); scanf("%s",strid); for(i=0;i<count;i++) if(strcmp(strid,information[i].id)==0) break; if(i==count) { printf("未找到該學(xué)號,請重新輸入\n"); getch(); return; } else break; } Delet_information(); Delet_information0(); printf("刪除成功按任意鍵返回上一層\n"); getch();} void Delet_name()//按姓名刪除{ int i;  while(1) { system("cls"); printf("請輸入要刪除人的姓名\n"); scanf("%s",&strid); for(i=0;i<count;i++) if(strcmp(strid,information0[i].name)==0) { strcpy(strid,information0[i].id); break; } if(i==count) { printf("未找到該人員按任意鍵返回上一層\n"); getch(); return; } else break; }  Delet_information(); Delet_information0(); printf("刪除成功按任意鍵返回上一層\n"); getch();} void Delet_information()//刪除該學(xué)號人員在普通人員中的信息{ int i,j; for(i=0;i<people;i++) if(strcmp(information[i].id,strid)==0) { people--; for(j=i;j<people;j++) information[j]=information[j+1]; return; }} void Delet_information0()//刪除該成員在滾動信息中的信息{ int i,j; //printf("\n\n*********%s\n\n",strid); for(i=0;i<count;i++) if(strcmp(information0[i].id,strid)==0) { count--; //printf("\n\n*********%s\n\n",information0[i].name); for(j=i;j<count;j++) information0[j]=information0[j+1]; return; }}void Add_function()//添加功能{ int i; system("cls"); char id[20],name[20]; printf("請輸入添加人員的學(xué)號和姓名\n"); scanf("%s%s",&id,&name); for(i=0;i<count;i++) if(strcmp(information0[i].id,id)==0) { printf("該學(xué)號已存在按任意鍵返回"); getch(); return; } for(i=0;i<count;i++) if(strcmp(information0[i].name,name)==0) { printf("該姓名已存在按任意鍵返回"); getch(); return; } strcpy(information0[count].id,id); strcpy(information0[count].name,name); information[people]=information0[count]; count++; people++; printf("添加成功,按任意鍵返回"); getch();} void Developer(){  system("cls"); printf("\n\n\t\t\t組長:賀志營"); printf("\n\n\t\t\t組員:劉欣鵬"); printf("\n\n\t\t\t組員:盧開偉"); printf("\n\n\t\t  按任意鍵返回上一層"); getch(); }

到此,相信大家對“用C語言寫一個(gè)抽獎系統(tǒng)”有了更深的了解,不妨來實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)建站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

文章標(biāo)題:用C語言寫一個(gè)抽獎系統(tǒng)-創(chuàng)新互聯(lián)
當(dāng)前網(wǎng)址:http://muchs.cn/article10/hicdo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、做網(wǎng)站、ChatGPT、面包屑導(dǎo)航品牌網(wǎng)站建設(shè)、建站公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)