您的位置:

c语言抽奖源码,c语言抽奖代码

本文目录一览:

怎样用C语言编写抽奖程序

自己看着修改一下就ok了, 。。。

/*

预先将参加抽奖者的资料输入存储起来,主要用结构体数组实现,用结构体表示每项记录,包括身份证号码、姓名、电话、住址等信息。开始抽奖时,屏幕上快速闪动参与者的身份证号码,按任意键停止闪动,把中奖人的信息用显示在屏幕上。可反复抽出一、二、三等奖若干名。

设计实现以下功能:

(1)录入:完成抽奖者信息的输入;

(2)删除:完成抽奖者信息的删除;

(3)修改:允许对已经录入的数据重新进行编辑、修改;

(4)显示:显示所有中奖者的信息;

(5)抽奖:

a. 抽出一等奖 1 名,如果抽过就不能再抽;

b. 抽出二等奖 2 名,如果抽完就不能再抽;

c. 抽出三等奖 5 名,如果抽完就不能再抽;

(6)退出程序。*/

#include

#include

#include

#include

#include

#include

#define AWARDER_NUM 10

typedef 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;iawarder_num;i++)

{

if (strcmp(awarder[i].name,name) == 0)

{

printf("您选择删除的抽奖者的信息如下:\n");

printf("身份证号:%s\n",awarder[i].ID);

printf("姓名:%s\n",awarder[i].name);

printf("电话号码:%s\n",awarder[i].telNo);

printf("家庭住址:%s\n",awarder[i].address);

break;

}

}

if(i == awarder_num)

{

printf("没有找到您输入的抽奖者!\n");

}

else

{

char c;

printf("您确定要删除吗?(Y//N)");

fflush(stdin);

scanf("%c",c);

if(c == 'Y' || c == 'y')

{

AWARDER * new_award = new AWARDER[awarder_num-1];

if(i = 0)

memcpy(new_award,awarder+1,sizeof(AWARDER) * (awarder_num - 1));

else if( 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;iawarder_num;i++)

{

if (strcmp(awarder[i].name,name) == 0)

{

printf("您选择的抽奖者的信息如下:\n");

printf("身份证号:%s\n",awarder[i].ID);

printf("姓名:%s\n",awarder[i].name);

printf("电话号码:%s\n",awarder[i].telNo);

printf("家庭住址:%s\n",awarder[i].address);

break;

}

}

if(i == awarder_num)

{

printf("没有找到您输入的抽奖者!\n");

}

else

{

printf("请输入该抽奖者的新信息:\n");

printf("身份证号:");

scanf("%s",awarder[i].ID);

printf("姓名:");

scanf("%s",awarder[i].name);

printf("电话号码:");

scanf("%s",awarder[i].telNo);

printf("家庭住址:");

scanf("%s",awarder[i].address);

}

}

bool check_over(int cur_award,int awarderNo)

{

if(awarderNo == 1)

{

if(cur_award == first_award[0])

return true;

}

else if(awarderNo = 3)

{

if(cur_award == first_award[0])

return true;

for(int i=0;iawarderNo-1;i++)

if(cur_award == second_award[i])

return true;

}

else if(awarderNo = 8)

{

if(cur_award == first_award[0])

return true;

for(int i=0;i2;i++)

if(cur_award == second_award[i])

return true;

for(i=0;iawarderNo-3;i++)

if(cur_award == third_award[i])

return true;

}

return false;

}

void award()

{

if(awarder_num 8)

{

printf("人数太少,请添加足够的人再抽奖!\n");

return;

}

srand((long)time(0));

char hit_id[20];

printf("\n开始抽第一等奖(1名),按任意键开始...\n");

getch();

while(!kbhit())

{

first_award[0] = rand() % awarder_num;

memcpy(hit_id,awarder[first_award[0]].ID,18);

printf("\r ");

printf("\r %s",hit_id);

}

printf("\n\n开始抽第二等奖(2名)");

for (int i=0;i2;i++)

{

printf("\n第%d个二等奖,按任意键开始...\n",i+1);

getch();

while(!kbhit())

{

second_award[i] = rand() % awarder_num;

while(check_over(second_award[i],1+i))

second_award[i] = rand() % awarder_num;

memcpy(hit_id,awarder[second_award[i]].ID,18);

printf("\r ");

printf("\r %s",hit_id);

}

}

printf("\n\n开始抽第三等奖(5名)");

for (i=0;i5;i++)

{

printf("\n第%d个三等奖,按任意键开始...\n",i+1);

getch();

while(!kbhit())

{

third_award[i] = rand() % awarder_num;

while(check_over(third_award[i],3+i))

third_award[i] = rand() % awarder_num;

memcpy(hit_id,awarder[third_award[i]].ID,20);

printf("\r ");

printf("\r %s",hit_id);

}

}

}

void info_show()

{

printf("一等奖获得者:\n");

printf("\t身份证号:%s\n",awarder[first_award[0]].ID);

printf("\t姓名:%s\n",awarder[first_award[0]].name);

printf("\t电话号码:%s\n",awarder[first_award[0]].telNo);

printf("\t家庭住址:%s\n",awarder[first_award[0]].address);

printf("二等奖获得者:\n");

for (int i=0;i2;i++)

{

printf("第%d个二等奖获得者:\n");

printf("\t身份证号:%s\n",awarder[second_award[i]].ID);

printf("\t姓名:%s\n",awarder[second_award[i]].name);

printf("\t电话号码:%s\n",awarder[second_award[i]].telNo);

printf("\t家庭住址:%s\n",awarder[second_award[i]].address);

}

printf("三等奖获得者:\n");

for (int i=0;i5;i++)

{

printf("第%d个三等奖获得者:\n");

printf("\t身份证号:%s\n",awarder[third_award[i]].ID);

printf("\t姓名:%s\n",awarder[third_award[i]].name);

printf("\t电话号码:%s\n",awarder[third_award[i]].telNo);

printf("\t家庭住址:%s\n",awarder[third_award[i]].address);

}

}

/*提示信息*/

bool raise()

{

printf("\n请输入你需要的操作代号:\n");

printf("\t1.录入:完成抽奖者信息的输入;\n");

printf("\t2.删除:完成抽奖者信息的删除;\n");

printf("\t3.修改:允许对已经录入的数据重新进行编辑、修改;\n");

printf("\t4.抽奖:开始抽奖!\n");

printf("\t5.显示:显示所有中奖者的信息;\n");

printf("\t6.退出。\n");

printf("==");

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());

}

用c语言编写一个简易的抽奖程序,

用data.txt文件保存以下内容:

13725528132 李桂荣

13725528131 李二来

13725528133 张荣刚

13725528130 荣南

13725528137 王三

13725528138 吴立

13725528139 郭德纲

13725528140 周星驰

13725528141 张曼玉

13725528142 张艺谋

13725528152 秦香莲

13725528162 潘金莲

13725528172 李大嘴

13725528182 展堂

//源代码如下

#include stdio.h

#include stdlib.h

#include time.h

#define MAX_NUM 9999

//定义保存人名和电话的数据结构

struct Person

{

char name[20];

char telno[15];

char award;

};

int num = 0; //统计人数

FILE *fp; //文件指针

Person persons[MAX_NUM]; //定义数组

int awarder_1[1] = {-1}; //一等奖

int awarder_2[2] = {-1, -1}; //二等奖

int awarder_3[5] = {-1, -1, -1, -1, -1};//三等奖

//读取文件

void readdata()

{

int i = 0; //数组下标

Person person;

//文件打开

fp = fopen("data.txt", "r");

if (fp == NULL)

{

printf("打开文件data.txt失败!\n");

return;

}

//当文件不为空

while (!feof(fp))

{

num ++;

fscanf(fp, "%s", person.telno);

fscanf(fp, "%s", person.name);

person.award = 'F';

persons[i++] = person;

}

}

//初始化标识

void init()

{

for(int i = 0; i num; i++)

{

persons[i].award = 'F';

}

}

//显示单个中奖信息

void info( int i)

{

printf("手机号码: %s 姓名: %s\n", persons[i].telno, persons[i].name);

}

void main()

{

char again = 'Y';

//读取文件

readdata();

printf("简单抽奖程序\n");

srand((long)time(0));

while(again == 'Y' || again == 'y')

{

//初始化标识

init();

printf("\n开始抽第一等奖(1名),按任意键开始...\n");

getchar();

awarder_1[0] = abs(rand() % num);

while (persons[awarder_1[0]].award == 'T')

{

awarder_1[0] = rand() % num;

}

persons[awarder_1[0]].award = 'T';

info(awarder_1[0]);

printf("\n开始抽第二等奖(2名)\n");

for (int i = 0; i 2; i++)

{

printf("\n第%d个二等奖,按任意键开始...\n", i+1);

getchar();

awarder_2[i] = rand() % num;

while (persons[awarder_2[i]].award == 'T')

{

awarder_2[i] = rand() % num;

}

persons[awarder_2[i]].award = 'T';

info(awarder_2[i]);

}

printf("\n\n开始抽第三等奖(5名)\n");

for (i = 0; i 5; i++)

{

printf("\n第%d个三等奖,按任意键开始...\n", i + 1);

getchar();

awarder_3[i] = rand() % num;

while (persons[awarder_3[i]].award == 'T')

{

awarder_3[i] = rand() % num;

}

persons[awarder_3[i]].award = 'T';

info(awarder_3[i]);

}

printf("\n是否重新开始抽奖?(Y or N)...\n");

again = getchar();

}

getchar();

return;

}

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

#includestdio.h

#include conio.h

#include stdlib.h

#include memory.h

#include string.h

#include time.h

#define AWARDER_NUM 10

typedef 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;iawarder_num;i++)

{

if (strcmp(awarder[i].name,name) == 0)

{

printf("您选择删除的抽奖者的信息如下:\n");

printf("身份证号:%s\n",awarder[i].ID);

printf("姓名:%s\n",awarder[i].name);

printf("电话号码:%s\n",awarder[i].telNo);

printf("家庭住址:%s\n",awarder[i].address);

break;

}

}

if(i == awarder_num)

{

printf("没有找到您输入的抽奖者!\n");

}

else

{

char c;

printf("您确定要删除吗?(Y//N)");

fflush(stdin);

scanf("%c",c);

if(c == 'Y' || c == 'y')

{

AWARDER * new_award = new AWARDER[awarder_num-1];

if(i = 0)

memcpy(new_award,awarder+1,sizeof(AWARDER) * (awarder_num - 1));

else if( 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;iawarder_num;i++)

{

if (strcmp(awarder[i].name,name) == 0)

{

printf("您选择的抽奖者的信息如下:\n");

printf("身份证号:%s\n",awarder[i].ID);

printf("姓名:%s\n",awarder[i].name);

printf("电话号码:%s\n",awarder[i].telNo);

printf("家庭住址:%s\n",awarder[i].address);

break;

}

}

if(i == awarder_num)

{

printf("没有找到您输入的抽奖者!\n");

}

else

{

printf("请输入该抽奖者的新信息:\n");

printf("身份证号:");

scanf("%s",awarder[i].ID);

printf("姓名:");

scanf("%s",awarder[i].name);

printf("电话号码:");

scanf("%s",awarder[i].telNo);

printf("家庭住址:");

scanf("%s",awarder[i].address);

}

}

bool check_over(int cur_award,int awarderNo)

{

if(awarderNo == 1)

{

if(cur_award == first_award[0])

return true;

}

else if(awarderNo = 3)

{

if(cur_award == first_award[0])

return true;

for(int i=0;iawarderNo-1;i++)

if(cur_award == second_award[i])

return true;

}

else if(awarderNo = 8)

{

if(cur_award == first_award[0])

return true;

for(int i=0;i2;i++)

if(cur_award == second_award[i])

return true;

for(i=0;iawarderNo-3;i++)

if(cur_award == third_award[i])

return true;

}

return false;

}

void award()

{

if(awarder_num 8)

{

printf("人数太少,请添加足够的人再抽奖!\n");

return;

}

srand((long)time(0));

char hit_id[20];

printf("\n开始抽第一等奖(1名),按任意键开始...\n");

getch();

while(!kbhit())

{

first_award[0] = rand() % awarder_num;

memcpy(hit_id,awarder[first_award[0]].ID,18);

printf("\r ");

printf("\r %s",hit_id);

}

printf("\n\n开始抽第二等奖(2名)");

for (int i=0;i2;i++)

{

printf("\n第%d个二等奖,按任意键开始...\n",i+1);

getch();

while(!kbhit())

{

second_award[i] = rand() % awarder_num;

while(check_over(second_award[i],1+i))

second_award[i] = rand() % awarder_num;

memcpy(hit_id,awarder[second_award[i]].ID,18);

printf("\r ");

printf("\r %s",hit_id);

}

}

printf("\n\n开始抽第三等奖(5名)");

for (i=0;i5;i++)

{

printf("\n第%d个三等奖,按任意键开始...\n",i+1);

getch();

while(!kbhit())

{

third_award[i] = rand() % awarder_num;

while(check_over(third_award[i],3+i))

third_award[i] = rand() % awarder_num;

memcpy(hit_id,awarder[third_award[i]].ID,20);

printf("\r ");

printf("\r %s",hit_id);

}

}

}

void info_show()

{

printf("一等奖获得者:\n");

printf("\t身份证号:%s\n",awarder[first_award[0]].ID);

printf("\t姓名:%s\n",awarder[first_award[0]].name);

printf("\t电话号码:%s\n",awarder[first_award[0]].telNo);

printf("\t家庭住址:%s\n",awarder[first_award[0]].address);

printf("二等奖获得者:\n");

for (int i=0;i2;i++)

{

printf("第%d个二等奖获得者:\n");

printf("\t身份证号:%s\n",awarder[second_award[i]].ID);

printf("\t姓名:%s\n",awarder[second_award[i]].name);

printf("\t电话号码:%s\n",awarder[second_award[i]].telNo);

printf("\t家庭住址:%s\n",awarder[second_award[i]].address);

}

printf("三等奖获得者:\n");

for (int i=0;i5;i++)

{

printf("第%d个三等奖获得者:\n");

printf("\t身份证号:%s\n",awarder[third_award[i]].ID);

printf("\t姓名:%s\n",awarder[third_award[i]].name);

printf("\t电话号码:%s\n",awarder[third_award[i]].telNo);

printf("\t家庭住址:%s\n",awarder[third_award[i]].address);

}

}

/*提示信息*/

bool raise()

{

printf("\n请输入你需要的操作代号:\n");

printf("\t1.录入:完成抽奖者信息的输入;\n");

printf("\t2.删除:完成抽奖者信息的删除;\n");

printf("\t3.修改:允许对已经录入的数据重新进行编辑、修改;\n");

printf("\t4.抽奖:开始抽奖!\n");

printf("\t5.显示:显示所有中奖者的信息;\n");

printf("\t6.退出。\n");

printf("==");

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());

}

C语言设计由猜数游戏模仿编写简单抽奖游戏,全班100名同学抽奖,一等奖1名,二等奖3

#includetime.h

#include stdio.h

#include stdlib.h

int main(){

srand(time(0));

int one;

int two[3];

printf("一等奖:%d\n",one=rand()%100+1);

int i;

for(i=0;i3;i++){

    two[i]=rand()%100+1;

    if(two[i]==one){i--;continue;}

    if(i==0)continue;

    if(i==1){

        if(two[1]==two[0]) {i--;continue;}

        else continue;

    }

    if(i==2){

        if(two[2]==two[1]||two[2]==two[0]){i--;continue;}

        else continue;

    }

}

printf("二等奖:");

for(i=0;i3;i++){

   printf("%d ",two[i]);

}

return 0;

}

C语言抽奖程序

单用C标准里的东西,可能无法做;得借助于操作系统或其他第三方库提供的多线程。单用C++2003及其以前的标准也无法实现,原因同C,如果依据C++2011标准(2011年刚出台的C++标准)到是可以——C++2011标准加入了多线程,要求C++编译器支持多线程,但是现在的编译器估计都还没有支持。

C语言程序设计——编写一个抽奖程序,生成0-9之间的随机数,猜对了奖励10块钱,没中奖显示中奖号码

代码如下,已测试通过:

int main()

{

int no,ret;

printf("请输入你猜测的号码:\n");

scanf("%d",no);

ret=rand()%10;

printf("本次开奖结果=[%d]:\n",ret);

if(no==ret)

{

printf("恭喜你猜中了,中奖10元!\n");

}

else

{

printf("很遗憾,再来一次吧!\n");

}

return 0;

}

可以把上面代码改成多次输入,即将输入和取随机数都放在while循环中。自己修改下吧

c语言抽奖源码,c语言抽奖代码

2022-11-29
c语言自制抽奖,抽奖C语言

2023-01-05
c语言抽奖方法,C语言抽奖程序

2022-11-25
c语言抽名源码,c语言抽卡代码

2023-01-07
c语言奖池,C语言计算奖金

2022-11-29
php九宫格抽奖源码,PHP抽奖源码

2022-11-30
js抽奖机代码,js九宫格抽奖代码

本文目录一览: 1、js随机抽奖一二三等奖不重复的抽奖逻辑怎么设置 2、js实现可键盘控制的简单抽奖程序 3、寻一个js抽奖代码~ 4、使用JavaScript完成一个抽奖程序,当单击页面上开始抽奖按

2023-12-08
javascript抽奖代码,jquery抽奖的代码

2022-11-30
java抽奖,java抽奖程序代码

2022-11-29
js摇奖器代码,js转盘抽奖代码

本文目录一览: 1、js实现可键盘控制的简单抽奖程序 2、用js做一个简单的摇奖程序,用javascript让三张图片快速切换,一个按钮控制开始和停止,具体如下 3、使用JavaScript完成一个抽

2023-12-08
php砸金蛋抽奖源码,抽奖源码php最新的

2022-11-18
java抽奖,Java抽奖

2022-11-28
大转盘抽奖源码,下载抽奖大转盘

2023-01-03
php转盘抽奖思路,php抽奖转盘网站源码

2022-12-02
h5大转盘抽奖源码php,html抽奖转盘

2022-11-17
奖金利润c语言,c语言奖金提成

2023-01-06
js图片抽奖网页,js 抽奖

本文目录一览: 1、你好,我网站有一个纯js抽奖页面,我已经实现了可抽奖初始次数等于会员金币数(问题里的php代码) 2、使用JavaScript完成一个抽奖程序,当单击页面上开始抽奖按钮时,在1~3

2023-12-08
java抽奖程序,java实现概率抽奖

2023-01-03
抽奖jsp代码,html随机抽奖代码

本文目录一览: 1、jsp随机抽题代码,随机抽取题目的代码,我不知道怎么写啊 2、jsp调用flash转盘实现抽奖功能 3、jsp怎么获取抽奖数据的名字 jsp随机抽题代码,随机抽取题目的代码,我不知

2023-12-08
php微信抽奖源码,抽奖源码php最新的

2022-11-28