您的位置首页百科问答

C语言根据随机数编写一个抽奖程序

C语言根据随机数编写一个抽奖程序

的有关信息介绍如下:

C语言根据随机数编写一个抽奖程序

#include#include #include #include #include #include #define AWARDER_NUM 10typedef struct tag_award { char ID[20]; char name[20]; char telNo[20]; char address[50];}AWARDER;AWARDER * awarder = new AWARDER[AWARDER_NUM];int first_award[1] = {-1};int second_award[2] = {-1,-1};int third_award[5] ={-1,-1,-1,-1,-1};int awarder_num = 0;void info_login(){ if(awarder_num >= AWARDER_NUM) { AWARDER * new_awarder = new AWARDER[awarder_num + AWARDER_NUM]; memcpy(new_awarder,awarder,awarder_num*sizeof(AWARDER)); delete awarder; awarder = new_awarder; } printf("身份证号:"); scanf("%s",awarder[awarder_num].ID); printf("姓名:"); scanf("%s",awarder[awarder_num].name); printf("电话号码:"); scanf("%s",awarder[awarder_num].telNo); printf("家庭住址:"); scanf("%s",awarder[awarder_num].address); awarder_num++;}void info_delete(){ char name[20]; printf("输入您要删颂闷氏除的抽奖者的姓名:"); scanf("%s",name); for(int i=0;i= awarder_num -1) memcpy(new_award,awarder,sizeof(AWARDER) * (awarder_num - 1)); else { memcpy(new_award,awarder,sizeof(AWARDER) * i); memcpy(new_award+i,awarder+i+1,sizeof(AWARDER) * (awarder_num - i - 1)); } awarder_num--; delete awarder; awarder = new_award; } } }void info_modify(){ char name[20]; printf("输入您要修改的抽奖者的姓名:"); scanf("%s",name); for(int i=0;i"); int operate; fflush(stdin); scanf("%d",&operate); switch(operate) { case 1: info_login(); break; case 2: info_delete(); break; case 3: info_modify(); break; case 4: award(); break; case 5: info_show(); break; case 6: return false; default: break; } printf("\n操作完成。\n"); return true;}void main(){ while(raise());}