本文实例为大家分享了C语言课程设计之抽奖系统的具体代码,供大家参考,具体内容如下
该程序的功能包括:
1、设置中奖人员
2、设置内幕人员
3、添加功能
4、删除功能
5、颜色设置
6、开发人员介绍
在使用该系统之前,请先在你程序保存的位置建一个17计科2.txt文档,里面填上学号和姓名,例如:25 贺志营。

建好txt文档后就可以直接运行了
运行截图及代码如下:
主界面:

功能介绍界面:

设置奖项界面:

开始抽奖界面不好演示,它是个动态的,下面有代码,可以自己运行下
程序代码:
#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];//内幕人员信息
int grade1=0,grade2=0,grade3=0;//内幕一等奖、二等奖、三等奖的人数
int ms=60;//初始滚动时间间隔
int count=0;//滚动人员总数
int people=0;//普通人员总数
int people1=0,people2=0,people3=0;//普通一等奖、二等奖、三等奖的人数
char strid[20];
void Function_introduction();//功能介绍
void Print_menu();//打印菜单
void Set_award();//设置奖项
void Read_information();//从文件中读取信息,放到普通人员信息中
void Read_information0();//从文件中读取信息,放到滚动人员信息中
void Roll_information0();//滚动信息,该信息是滚动人员的信息
void Set_speed();//设置滚动时间间隔
void Set_colour();//颜色设置
void Set_grade();//设置必中奖等级
void Set_winner1();//设置一等奖信息
void Set_winner2();//设置二等奖信息
void Set_winner3();//设置三等奖信息
void Set_awards();//设置奖项人数
void Delet_function();//删除功能
void Delet_number();//按学号删除
void Delet_name();//按姓名删除
void Delet_information();//删除普通人员的信息
void Delet_information0();//删除内幕人员信息
void Add_function();//添加功能
void Begin_luck();//开始抽奖
void Roll_speed(int ms);//滚动速度
void Developer();//开发人员介绍
int main()
{
Read_information();
Read_information0();
system("color 07");
Print_menu();
return 0;
}
void Function_introduction()//功能介绍
{
system("cls");
printf("ntt <-抽奖系统功能介绍->nn");
printf("ttt1、设置中奖人员n");
printf("ttt2、设置内幕人员n");
printf("ttt3、添加功能n");
printf("ttt4、删除功能n");
printf("ttt5、颜色设置n");
printf("ttt6、开发人员介绍n");
printf("ttt按任意键返回");
getch();
}
void Print_menu()//打印菜单
{
int choose;
while(1)
{
system("cls");
printf("nn");
printf("t*********************************************************n");
printf("t*t <-欢迎来到抽奖系统->ttt*n");
printf("t*ttttttt*n");
printf("t*tt开始抽奖请按1tttt*n");
printf("t*tt设置奖项请按2tttt*n");
printf("t*tt滚动设置请按3tttt*n");
printf("t*tt颜色设置请按4tttt*n");
printf("t*tt添加功能请按5tttt*n");
printf("t*tt删除功能请按6tttt*n");
printf("t*tt人员介绍请按7tttt*n");
printf("t*tt功能介绍请按8tttt*n");
printf("t*tt结束程序请按0tttt*n");
printf("t*ttttttt*n");
printf("t*********************************************************n");
printf("nnttt请输入选项:");
scanf("%d",&choose);
switch(choose)
{
case 0:
return;
case 1:
Begin_luck();//开始抽奖
break;
case 2:
Set_award();//设置奖项
break;
case 3:
Set_speed();//设置滚动时间间隔
break;
case 4:
Set_colour();//颜色设置
break;
case 5:
Add_function();//添加功能
break;
case 6:
Delet_function();//删除功能
break;
case 7:
Developer();//开发人员介绍
break;
case 8:
Function_introduction();//功能介绍
break;
}
}
}
void Set_award()//设置奖项
{
int choose;
while(1)
{
system("cls");
printf("nn");
printf("t*********************************************************n");
printf("t*ttttttt*n");
printf("t*tt设置奖项人数请按1ttt*n");
printf("t*tt设置内幕人员请按2ttt*n");
printf("t*tt返回上一层请按0tttt*n");
printf("t*ttttttt*n");
printf("t*********************************************************n");
printf("nnttt请输入选项:");
scanf("%d",&choose);
switch(choose)
{
case 0:
return;
case 1:
Set_awards();//设置奖项人数
break;
case 2:
Set_grade();//设置内幕人员
break;
}
}
}
void Set_colour()//颜色设置
{
char choose[20];
int i;
system("cls");
printf("nnt0 = 黑色 8 = 灰色n");
printf("t1 = 蓝色 9 = 淡蓝色n");
printf("t2 = 绿色 A = 淡绿色n");
printf("t3 = 浅绿色 B = 淡浅绿色n");
printf("t4 = 红色 C = 淡红色n");
printf("t5 = 紫色 D = 淡紫色n");
printf("t6 = 黄色 E = 淡黄色n");
printf("t7 = 白色 F = 亮白色nn");
printf("t请输入字体颜色对应的代码:");
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设置完毕按任意键返回");
getch();
}
void Delet_function()//删除功能
{
int choose;
while(1)
{
system("cls");
printf("nn");
printf("t*********************************************************n");
printf("t*ttttttt*n");
printf("t*tt按姓名删除请按1tttt*n");
printf("t*tt按学号删除请按2tttt*n");
printf("t*tt返回上一层请按0tttt*n");
printf("t*ttttttt*n");
printf("t*********************************************************n");
printf("nnttt请输入选项:");
scanf("%d",&choose);
switch(choose)
{
case 0:
return;
case 1:
Delet_name();//按姓名删除
break;
case 2:
Delet_number();//按学号删除
break;
}
}
}
void Read_information()//从文件中读取信息
{
FILE *fp=fopen("17计科2.txt","r");
while(!feof(fp))
{
//存储该信息到普通人员信息中,便于设置内幕人员
fscanf(fp,"%s%s",information[people].id,information[people].name);
people++;
}
fclose(fp);
}
void Read_information0()//读取滚动人员的信息
{
FILE *fp=fopen("17计科2.txt","r");
while(!feof(fp))
{
//存储信息到滚动人员信息中,用于滚动时打印在显示屏幕中
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:中国人民解放军军乐团-国际歌.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("请先设置奖项人数按任意键返回n");
getch();
return;
}
printf("下面开始抽取三等奖人员,按任意键继续n");
getch();
j=0;//代表各奖项人员的总数包括内幕人员
while(grade3--)//内幕三等奖人员
{
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("nnn");
//for(i=0;i<count;i++)
//printf("%s ",information0[i].name);
getch();
getch();
}
system("cls");
printf("以下是三等奖名单,按任意键继续n");
for(i=0;i<j;i++)
printf("%sn",prize[i].name);
getch();
system("cls");
printf("下面开始抽取二等奖人员,按任意键继续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("以下是二等奖名单,按任意键继续n");
for(i=0;i<j;i++)
printf("%sn",prize[i].name);
getch();
system("cls");
printf("下面开始抽取一等奖人员,按任意键继续n");
getch();
j=0;
while(grade1--)//内幕一等奖人员
{
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("以下是一等奖名单,按任意键继续n");
for(i=0;i<j;i++)
printf("%sn",prize[i].name);
printf("抽奖完毕按任意键返回n");
getch();
}
void Set_speed()//滚动速度
{
char choose[20];
int i,t=0;
system("cls");
printf("请输入滚动时间间隔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("设置完毕按任意键返回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()//设置奖项人数
{
int choose,t;
while(1)
{
system("cls");
printf("请输入三等奖人数(正整数):n");
scanf("%d",&t);
if(t<0||t>count)
{
printf("输入不合法,请输入1到%d之内的数字",count);
getch();
}
else
{
people3+=t;
break;
}
}
while(1)
{
system("cls");
printf("请输入二等奖人数:n");
scanf("%d",&t);
if(t<1||t>count)
{
printf("输入不合法,请输入1到%d之内的数字",count);
getch();
}
else
{
people2+=t;
break;
}
}
while(1)
{
system("cls");
printf("请输入一等奖人数:n");
scanf("%d",&t);
if(t<0||t>count)
{
printf("输入不合法,请输入1到%d之内的数字",count);
getch();
}
else
{
people1+=t;
break;
}
}
printf("设置完毕按任意键返回n");
getch();
return;
}
void Set_grade()//设置内幕中奖等级
{
char grade[20];
system("cls");
printf("请输入中奖等级,返回上一层请按0n");
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()//设置内幕一等奖信息
{
int i,j;
system("cls");
printf("请输入必中奖人员学号和姓名: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("设置成功按任意键继续");
getch();
strcpy(strid,winner1[grade1].id);
Delet_information();//普通总成员减1
grade1++;//内幕一等奖成员加1
people1--;//普通一等奖成员减1
return;
}
void Set_winner2()//设置内幕二等奖信息
{
int i,j;
system("cls");
printf("请输入必中奖人员学号和姓名: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("设置成功按任意键继续");
getch();
strcpy(strid,winner2[grade2].id);
Delet_information();//普通总人员减1
grade2++;//内幕二等奖人员加1
people2--;//普通二等奖人员减1
return;
}
void Set_winner3()//设置内幕三等奖信息
{
int i,j;
system("cls");
printf("请输入必中奖人员学号和姓名: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("设置成功按任意键继续");
getch();
strcpy(strid,winner3[grade3].id);
Delet_information();//普通总人员减1
grade3++;//内幕三等奖人员加1
people3--;//普通三等奖人员减1
return;
}
void Delet_number()//按学号删除
{
int i;
system("cls");
while(1)
{
printf("请输入要删除人的学号n");
scanf("%s",strid);
for(i=0;i<count;i++)
if(strcmp(strid,information[i].id)==0)
break;
if(i==count)
{
printf("未找到该学号,请重新输入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()//删除该学号人员在普通人员中的信息
{
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("nn*********%snn",strid);
for(i=0;i<count;i++)
if(strcmp(information0[i].id,strid)==0)
{
count--;
//printf("nn*********%snn",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("请输入添加人员的学号和姓名n");
scanf("%s%s",&id,&name);
for(i=0;i<count;i++)
if(strcmp(information0[i].id,id)==0)
{
printf("该学号已存在按任意键返回");
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("nnttt组长:贺志营");
printf("nnttt组员:刘欣鹏");
printf("nnttt组员:卢开伟");
printf("nntt 按任意键返回上一层");
getch();
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持靠谱客。
最后
以上就是傲娇小海豚最近收集整理的关于C语言课程设计之抽奖系统的全部内容,更多相关C语言课程设计之抽奖系统内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复