欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C語言實現簡單的抽獎系統

 更新時間:2022年04月01日 09:11:26   作者:fastjson_  
這篇文章主要為大家詳細介紹了C語言實現簡單的抽獎系統,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了C語言實現簡單的抽獎系統的具體代碼,供大家參考,具體內容如下

效果圖

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#include<time.h>
#include <windows.h>
?
struct data{
?? ?char id[20];
?? ?char name[20];
};
?
int t1,t2,t3;
struct data information[110]; ? ? ? ? ? ? ?//普通人員信息
struct data prize1[110]; ? ? ? ? ? ? ? ? ? ?//總獲獎人員信息
struct data prize2[110]; ? ? ? ? ? ? ? ? ? ?//總獲獎人員信息
struct data prize3[110]; ? ? ? ? ? ? ? ? ? ?//總獲獎人員信息
?
int people=0; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//參與抽獎總人數
int people1=0,people2=0,people3=0; ? ? ? ? //普通一等獎、二等獎、三等獎的人數
char strid[20];
?
//從文件中讀取信息,放到普通人員信息中
void Read_information(); ??
?
//打印菜單
void Print_menu(); ? ? ?
?
//設置獎項人數
void Set_awards();?
?
//開始抽獎 ? ?
void Begin_luck(); ?
?
//刪除該學號人員在普通人員中的信息
void Delet_information();
?
void main()
{
?? ?Read_information();
?? ?Print_menu();
}
?
void Read_information()//從文件中讀取信息
{
?? ?FILE *fp=fopen("抽獎人員名單.txt","r");
?? ?while(!feof(fp))
?? ?{
?? ??? ?//存儲該信息到普通人員信息中,便于設置內幕人員
?? ??? ?fscanf(fp,"%s%s",information[people].id,information[people].name);
?? ??? ?people++;
?? ?}
?? ?fclose(fp);
}
?
?
void Print_menu()
{
?? ?int choose;
?? ?while(1)
?? ?{
?? ??? ?system("cls");
?? ??? ?printf("\n\n");
?? ??? ?printf("\t\t\t*********************************************************\n");
?
?? ??? ?printf("\t\t\t*\t?? ?<-歡迎來到抽獎系統->\t\t\t*\n");
?? ??? ?printf("\t\t\t*\t?? ?<-目前參與抽獎的總人數為%d人->\t\t*\n", people);
?? ??? ?printf("\t\t\t*\t?? ?< ?一等獎設置為%d人 ?>\t\t\t*\n",people1);
?? ??? ?printf("\t\t\t*\t?? ?< ?二等獎設置為%d人 ?>\t\t\t*\n",people2);
?? ??? ?printf("\t\t\t*\t?? ?< ?三等獎設置為%d人 ?>\t\t\t*\n",people3);
?? ??? ?printf("\t\t\t*\t\t\t\t\t\t\t*\n");
?
?? ??? ?printf("\t\t\t*\t\t開始抽獎請按1\t\t\t\t*\n");
?? ??? ?printf("\t\t\t*\t\t設置獎項人數2\t\t\t\t*\n");
?? ??? ?printf("\t\t\t*\t\t結束程序請按0\t\t\t\t*\n");
?? ??? ?printf("\t\t\t*\t\t\t\t\t\t\t*\n");
?? ??? ?printf("\t\t\t*********************************************************\n");
?
?? ??? ?printf("\n\n\t\t\t\t\t請輸入選項:");
?? ??? ?scanf("%d",&choose);
?? ??? ?
?? ??? ?switch(choose)
?? ??? ?{
?? ??? ??? ?case 0:
?? ??? ??? ??? ?return;
?
?? ??? ??? ?case 1:
?? ??? ??? ??? ?Begin_luck();?
?? ??? ??? ??? ?break;
?
?? ??? ??? ?case 2:
?? ??? ??? ??? ?Set_awards();
?? ??? ??? ??? ?break;
?? ??? ?}?? ?
?? ?}
}
?
?
//設置獎項人數
void Set_awards()
{
?? ?int choose;
?? ?while(1)
?? ?{
?? ??? ?system("cls");
?? ??? ?printf("請輸入三等獎人數(正整數):\n");
?? ??? ?scanf("%d",&t3);
?? ??? ?if( t3<0 || t3>people)
?? ??? ?{
?? ??? ??? ?printf("輸入不合法,請輸入1到%d之內的數字",people);
?? ??? ??? ?getch();
?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?people3=t3;
?? ??? ??? ?break;
?? ??? ?}
?
?? ?}
?? ?while(1)
?? ?{
?? ??? ?system("cls");
?? ??? ??? ?printf("請輸入二等獎人數:\n");
?? ??? ??? ?scanf("%d",&t2);
?? ??? ??? ?if( t2<0 || t2>people)
?? ??? ??? ?{
?? ??? ??? ??? ?printf("輸入不合法,請輸入1到%d之內的數字",people);
?? ??? ??? ??? ?getch();
?
?? ??? ??? ?}
?? ??? ??? ?else
?? ??? ??? ?{
?? ??? ??? ??? ?people2=t2;
?? ??? ??? ??? ?break;
?? ??? ??? ?}
?
?
?? ?}
?? ?while(1)
?? ?{
?? ??? ?system("cls");
?? ??? ?printf("請輸入一等獎人數:\n");
?? ??? ?scanf("%d",&t1);
?? ??? ?if( t1<0 || t1>people)
?? ??? ?{
?? ??? ??? ?printf("輸入不合法,請輸入1到%d之內的數字",people);
?? ??? ??? ?getch();
?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?people1=t1;
?? ??? ??? ?break;
?? ??? ?}
?? ?}
?? ?printf("設置完畢按任意鍵返回\n");
?? ?getch();
?? ?return;
}
?
?
void Begin_luck() ? //開始抽獎
{
?? ?if(people1==0 || people2==0 || people3==0)
?? ?{
?? ??? ?printf("請設置獎項人數!!!!\n");
?? ??? ?printf("按任意鍵返回\n");
?? ??? ?getch();
?? ??? ?return;
?? ?}
?
?? ?if( (people1+people2+people3) > people )
?? ?{
?? ??? ?printf("中獎人數超過總人數,請重新設置!!!!\n");
?? ??? ?printf("按任意鍵返回\n");
?? ??? ?getch();
?? ??? ?return;
?? ?}
?
?? ?int i,j=0,choose,t;
?? ?system("cls");?? ? ?
?
/*******************三等獎人員****************************/
?? ?printf("下面開始抽取三等獎人員,按任意鍵繼續(xù)\n");
?? ?getch();
?? ?while(people3--)
?? ?{
?? ??? ?if(people3<0)
?? ??? ??? ?break;
?? ??? ?srand((unsigned)time(0));
?? ??? ?t=rand()%people;
?? ??? ?prize3[j++]=information[t];
?? ??? ?strcpy(strid,information[t].id);
?? ??? ?Delet_information();
?? ?}
?? ?printf("以下是三等獎名單,按任意鍵繼續(xù)\n");
?? ?for(i=0;i<j;i++)
?? ??? ?printf("%s\n",prize3[i].name);
?? ?getch();
?
/*******************二等獎人員****************************/
?? ?printf("下面開始抽取二等獎人員,按任意鍵繼續(xù)\n");
?? ?getch();
?? ?while(people2--)
?? ?{
?? ??? ?if(people2<0)
?? ??? ??? ?break;
?? ??? ?srand((unsigned)time(0));
?? ??? ?t=rand()%people;
?? ??? ?prize2[j++]=information[t];
?? ??? ?strcpy(strid,information[t].id);
?? ??? ?Delet_information();
?? ?}
?? ?printf("以下是二等獎名單,按任意鍵繼續(xù)\n");
?? ?for(;i<j;i++)
?? ??? ?printf("%s\n",prize2[i].name);
?? ?getch();
?
/*******************一等獎人員****************************/
?? ?printf("下面開始抽取一等獎人員,按任意鍵繼續(xù)\n");
?? ?getch();
?? ?while(people1--)
?? ?{
?? ??? ?if(people1<0)
?? ??? ??? ?break;
?? ??? ?srand((unsigned)time(0));
?? ??? ?t=rand()%people;
?? ??? ?prize1[j++]=information[t];
?? ??? ?strcpy(strid,information[t].id);
?? ??? ?Delet_information();
?? ?}
?? ?printf("以下是一等獎名單,按任意鍵繼續(xù)\n");
?? ?for(;i<j;i++)
?? ??? ?printf("%s\n",prize1[i].name);
?? ?getch();
?
?? ?people=0;
?? ?Read_information();
?? ?people1=t1,people2=t2,people3=t3;
}
?
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;
?? ??? ?}
}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • 詳解C語言的void*空指針

    詳解C語言的void*空指針

    這篇文章主要為大家詳細介紹了C語言的void*空指針,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-03-03
  • C語言實現爆炸展開的掃雷詳解

    C語言實現爆炸展開的掃雷詳解

    windows自帶的游戲《掃雷》是陪伴了無數人的經典游戲,本文將利用C語言實現這一經典的游戲,文中的示例代碼講解詳細,感興趣的可以學習一下,這篇文章主要介紹了C語言實現爆炸展開的掃雷游戲
    2022-07-07
  • C/C++練習題之合并k個已排序的鏈表

    C/C++練習題之合并k個已排序的鏈表

    這篇文章主要給大家介紹了關于C/C++練習題之合并k個已排序的鏈表的相關資料,文中通過圖文以及實例代碼介紹的非常詳細,對大家學習或者使用C/C++具有一定的參考學習價值,需要的朋友可以參考下
    2023-06-06
  • C++內存對齊的實現

    C++內存對齊的實現

    本文主要介紹了C++內存對齊的實現,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-02-02
  • vscode配置遠程開發(fā)環(huán)境并遠程調試運行C++代碼的教程

    vscode配置遠程開發(fā)環(huán)境并遠程調試運行C++代碼的教程

    這篇文章主要介紹了vscode配置遠程開發(fā)環(huán)境并遠程調試運行C++代碼的教程,本文通過截圖實例相結合給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-04-04
  • C++ namespace命名空間解析

    C++ namespace命名空間解析

    考慮一種情況,當我們有兩個同名的人,Zara,在同一個班里。當我們需要對它們進行區(qū)分我們必須使用一些額外的信息和它們的名字,比如它們生活在不同的區(qū)域或者興趣愛好什么的,在C++程序中也會遇到同樣的情況,所以命名空間就此產生
    2021-11-11
  • 淺談C語言的字符串分割

    淺談C語言的字符串分割

    下面小編就為大家?guī)硪黄獪\談C語言的字符串分割。小編覺得挺不錯的,現在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-05-05
  • C++深入淺出講解函數重載

    C++深入淺出講解函數重載

    C++允許多個函數擁有相同的名字,只要它們的參數列表不同就可以,這就是函數的重載(Function?Overloading),借助重載,一個函數名可以有多種用途
    2022-05-05
  • C語言中花式退出程序的方式總結

    C語言中花式退出程序的方式總結

    在本篇文章當中主要給大家介紹C語言當中一些不常用的特性,比如在main函數之前和之后設置我們想要執(zhí)行的函數,以及各種花式退出程序的方式,需要的可以參考一下
    2022-10-10
  • Qt QTreeWidget 樹形結構實現代碼

    Qt QTreeWidget 樹形結構實現代碼

    Qt中實現樹形結構可以使用QTreeWidget類,也可以使用QTreeView類,QTreeWidget繼承自QTreeView類,接下來通過本文給大家介紹Qt QTreeWidget 樹形結構實現代碼,需要的朋友可以參考下
    2021-11-11

最新評論