溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

C語言如何實(shí)現(xiàn)會(huì)員管理系統(tǒng)

發(fā)布時(shí)間:2022-03-18 16:11:19 來源:億速云 閱讀:233 作者:iii 欄目:開發(fā)技術(shù)

本文小編為大家詳細(xì)介紹“C語言如何實(shí)現(xiàn)會(huì)員管理系統(tǒng)”,內(nèi)容詳細(xì),步驟清晰,細(xì)節(jié)處理妥當(dāng),希望這篇“C語言如何實(shí)現(xiàn)會(huì)員管理系統(tǒng)”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學(xué)習(xí)新知識(shí)吧。

會(huì)員信息包括:會(huì)員號(hào)(6位數(shù),唯一),姓名,身份證號(hào),聯(lián)系電話,狀態(tài)(1表示正常,0表示掛失)。

會(huì)員管理包括:會(huì)員的添加、刪除、修改(會(huì)員號(hào)不能修改)、掛失、查詢、接觸掛失。

先給大家看看效果:

C語言如何實(shí)現(xiàn)會(huì)員管理系統(tǒng)

C語言如何實(shí)現(xiàn)會(huì)員管理系統(tǒng)

C語言如何實(shí)現(xiàn)會(huì)員管理系統(tǒng)

C語言如何實(shí)現(xiàn)會(huì)員管理系統(tǒng)

C語言如何實(shí)現(xiàn)會(huì)員管理系統(tǒng)

C語言如何實(shí)現(xiàn)會(huì)員管理系統(tǒng)

C語言如何實(shí)現(xiàn)會(huì)員管理系統(tǒng)

上代碼:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct VIP             //定義結(jié)構(gòu)體,存儲(chǔ)會(huì)員賬號(hào)、姓名、身份證號(hào)、聯(lián)系方式、狀態(tài)、余額 
{
    long no;
    char name[20];    //姓名、身份證號(hào)含有字符,使用char定義 
    char IDcard[19];
    char phone[12];   //聯(lián)系電話有11位,超出了int的范圍,使用字符串定義 
    int zhuangtai;      //如果狀態(tài)為1,則正常,若為0,則狀態(tài)為掛失 
    int yue;
};
struct VIP s[50];     //定義結(jié)構(gòu)體數(shù)組 
int n=0;              //n表示存入的會(huì)員數(shù)量 
 
void init();          //含義見main主函數(shù) 
void print();           
struct VIP gete();
void add1();             
void findbyno();       
void findbyname();
void findbyIDcard();
void findbyphone();     
void mod();            
void del();             
void sort();  
void transaction();
 
         
void init()   //初始化(唯一的6位會(huì)員賬號(hào))
{
    int f=1; //1唯一   0不唯一 
    printf("請(qǐng)輸入會(huì)員的賬號(hào),姓名,身份證號(hào)碼,聯(lián)系電話,余額,狀態(tài)\n");
    printf("當(dāng)輸入會(huì)員號(hào)為0時(shí)停止輸入\n");
    while(n<=50)
    {
        printf("請(qǐng)輸入會(huì)員的賬號(hào):\n");
        scanf("%ld",&s[n].no);
        while(s[n].no!=0)
        {
            if(s[n].no/1000000==0 && s[n].no/100000!=0)
            {
                int i;
                for(i=0;i<n&&f==1;i++)
                {
                    if(s[n].no==s[i].no)
                    {
                        f=0;
                        printf("請(qǐng)輸入唯一的6位會(huì)員賬號(hào)\n"); 
                    }
            
                }   
                if(f==1) 
                    break;
            }
            else
            {
                printf("請(qǐng)輸入6位會(huì)員賬號(hào)\n");    
                printf("請(qǐng)重新輸入會(huì)員的賬號(hào):\n");
                scanf("%d",&s[n].no);
            }
        }
        if(s[n].no==0)   
            break;         //如果輸入的賬號(hào)為0,結(jié)束輸入
        printf("請(qǐng)輸入會(huì)員的姓名:\n");
        scanf("%s",s[n].name);
        printf("請(qǐng)輸入會(huì)員的身份證號(hào),聯(lián)系電話,余額,狀態(tài):\n");
        scanf("%s%s%d%d",s[n].IDcard,s[n].phone,&s[n].yue,&s[n].zhuangtai);
        n++;
    }
}
 
void print()  //輸出 
{
    //|和=組合起來,使輸出結(jié)果時(shí)有表格樣式
    //%t、空格使輸出時(shí)數(shù)據(jù)對(duì)其 
    int j;
    printf("會(huì)員信息記錄如下:\n");
    printf("     |===================================================================================|\n");
    printf("     |賬號(hào)\t姓名\t        身份證號(hào)      \t  聯(lián)系電話   \t余額\t  狀態(tài)           |\n");
    printf("     |-----------------------------------------------------------------------------------|\n");
    for(j=0;j<n;j++)        
    {
        printf("     |%ld\t%s\t  %s\t%s\t%d\t",s[j].no,s[j].name,s[j].IDcard,s[j].phone,s[j].yue);
        if(s[j].zhuangtai==1)
             printf("  正常           |\n");
        else
             printf("  掛失           |\n"); 
        if(j<(n-1))
        printf("     |-----------------------------------------------------------------------------------|\n");
    }
    printf("     |===================================================================================|\n");
}
 
struct VIP gete()       //輸入 
{
    struct VIP e;
    printf("請(qǐng)輸入賬號(hào):\n");
    scanf("%d",&e.no);
    int f=1;
    while(e.no)
    {    
        if(e.no/1000000==0 && e.no/100000!=0)
        {
            int i;
            for(i=0;i<n&&f==1;i++)
            {
                if(e.no==s[i].no)
                {
                    f=0;
                    printf("請(qǐng)輸入唯一的6位會(huì)員賬號(hào)\n"); 
                    scanf("%d",&e.no);
                }        
            }   
            if(f==1)   
                break;
        }
        else
        {
            printf("請(qǐng)輸入6位會(huì)員賬號(hào)\n");    
            printf("請(qǐng)重新輸入會(huì)員的賬號(hào):\n");
            scanf("%d",&e.no);
        }
    }
    printf("請(qǐng)輸入姓名:\n");
    scanf("%s",&e.name);
    printf("請(qǐng)輸入會(huì)員的身份證號(hào),聯(lián)系電話,余額,狀態(tài):\n");
    scanf("%s%s%d%d",&e.IDcard,&e.phone,&e.yue,&e.zhuangtai);
    return e;
 
}
 
void add1()   //添加新的會(huì)員信息 
{
    struct VIP e = gete();
    int i; 
       printf("請(qǐng)輸入要插入的位置(1-%d):\n",n);
    scanf("%d",&i); 
    while(i<1||i>n+1) 
    {
        printf("您輸入的位置有誤!\n");
        printf("請(qǐng)重新輸入要插入的位置(1-%d):\n",n);
        scanf("%d",&i);
    }
    for(int j=n-1;j>=i-1;j--) 
    {
        s[j+1]=s[j];
    }
    s[i-1]=e;
    n++; 
}
 
void findbyno()     //根據(jù)會(huì)員賬號(hào)查找會(huì)員信息 
{
    int num,i;
    int found=1;
    char choice;
    while(1)
    {
        printf("請(qǐng)輸入要查找的會(huì)員的賬號(hào):\n");
        scanf("%d",&num);
        getchar();
        for(i=0;i<n&&found==1;i++)
        {
            
            if(s[i].no==num)
            {
                    found=0;
                    printf("%ld\t%s\t%d\t%d\t%d\t",s[i].no,s[i].name,s[i].IDcard,s[i].phone,s[i].yue);
                    if(s[i].zhuangtai==1)
                       printf("正常\n");
                    else
                       printf("掛失!\n"); 
            }
        }
        if(found==1)
        {
            printf("未找到!\n");
        }
        found=1;    
        printf("是否繼續(xù)查詢(Y/N)\n");
        choice=getchar();
        if(choice=='N'|| choice=='n')
            break;
    }
}
 
void findbyname()    //根據(jù)會(huì)員姓名查找會(huì)員信息 
{
        char name[20];
        char choice;
        int found=1;
        int i;
        while(1)
        {
        printf("輸入要查詢會(huì)員的姓名:\n");
        scanf("%s",name);
        getchar();
        for(i=0;i<n&&found==1;i++)
        {
            if(strcmp(s[i].name,name)==0)
            {
                found=0;
                printf("%ld\t%s\t%d\t%d\t%d\t",s[i].no,s[i].name,s[i].IDcard,s[i].phone,s[i].yue);
                if(s[i].zhuangtai==1)
                    printf("正常\n");
                else
                    printf("掛失!\n"); 
            }
        }
        if(found==1)
        {
            printf("未找到!\n");
        }
        found=1;    
        printf("是否繼續(xù)查詢(Y/N)\n");
        choice=getchar();
        if(choice=='N'|| choice=='n')
            break;
    }
}
 
void findbyIDcard()   //根據(jù)身份證號(hào)查找會(huì)員信息 
{
    char num[19];
    int i;
    int found=1;
    char choice;
    while(1)
    {
        printf("請(qǐng)輸入要查找的會(huì)員的身份證號(hào):\n");
        scanf("%s",num);
        getchar();
        for(i=0;i<n&&found==1;i++)
        {
            if(strcmp(s[i].IDcard,num)==0)
            {
                    found=0;
                    printf("%ld\t%s\t%d\t%d\t%d\t",s[i].no,s[i].name,s[i].IDcard,s[i].phone,s[i].yue);
                    if(s[i].zhuangtai==1)
                       printf("正常\n");
                    else
                       printf("掛失!\n"); 
            }
        }
        if(found==1)
        {
            printf("未找到!\n");
        }
        found=1;    
        printf("是否繼續(xù)查詢(Y/N)\n");
        choice=getchar();
        if(choice=='N'|| choice=='n')
            break;
    }        
}
 
void findbyphone()    //根據(jù)聯(lián)系電話查找會(huì)員信息 
{
    char num[12];
    int i;
    int found=1;
    char choice;
    while(1)
    {
        printf("請(qǐng)輸入要查找的會(huì)員的聯(lián)系電話:\n");
        scanf("%s",num);
        getchar();
        for(i=0;i<n&&found==1;i++)
        {
            if(strcmp(s[i].phone,num)==0)
            {
                found=0;
                printf("%ld\t%s\t%d\t%d\t%d\t",s[i].no,s[i].name,s[i].IDcard,s[i].phone,s[i].yue);
                if(s[i].zhuangtai==1)
                    printf("正常\n");
                else
                    printf("掛失!\n"); 
            }
        }
        if(found==1)
        {
            printf("未找到!\n");
        }
        found=1;    
        printf("是否繼續(xù)查詢(Y/N)\n");
        choice=getchar();
        if(choice=='N'|| choice=='n')
            break;
    }        
}
 
void mod()     //修改已有的會(huì)員信息 
{
    int num,i;
    int found=1;
    char choice;
    int opt;
    while(1)
    {
        printf("請(qǐng)輸入要修改的會(huì)員的賬號(hào)(會(huì)員號(hào)無法修改):\n");
        scanf("%d",&num);
        getchar();
        for (i=0;i<n&&found==1;i++)
        {
            if(s[i].no==num)
            {
                found=0;
                printf("%ld\t%s\t%d\t%d\t%d\t",s[i].no,s[i].name,s[i].IDcard,s[i].phone,s[i].yue);
                if(s[i].zhuangtai==1)
                     printf("正常\n");
                else
                     printf("掛失\n"); 
                printf("--請(qǐng)選擇--1.修改身份證號(hào) 2.修改聯(lián)系電話 3.修改狀態(tài)\n");
                scanf("%d",&opt);
                getchar();
                switch(opt)
                {
                case 1:
                    printf("請(qǐng)輸入身份證號(hào)新值:\n");  
                    scanf("%s",s[i].IDcard);   
                    getchar(); 
                    break;
                case 2:
                    printf("請(qǐng)輸入聯(lián)系電話新值:\n");  
                    scanf("%s",s[i].phone);     
                    getchar(); 
                    break;
                case 3:
                    printf("請(qǐng)輸入狀態(tài)新值:\n");  
                    scanf("%d",&s[i].zhuangtai);   
                    getchar(); 
                    break;                
                }
            }
        }
        if(found==1)
        {
            printf("未找到!\n");
        }    
        found=1;
        printf("是否繼續(xù)修改(Y or N)\n");
        choice=getchar();
        getchar();
        if(choice=='N'|| choice=='n')
             break;
        }
}
 
void del()     //刪除已有會(huì)員信息 
{
    int num,i,j;
    int found=1;
    char choice;
    while(1)
    {
        printf("請(qǐng)輸入要?jiǎng)h除的會(huì)員的賬號(hào):\n");
        scanf("%d",&num);
        getchar();
        for(i=0;i<n&&found==1;i++)   //5  1-5      
        {
            if(s[i].no==num)
            {
                found=0;
                printf("你要?jiǎng)h除的會(huì)員信息為:\n");
                printf("會(huì)員賬號(hào)     姓名      身份證號(hào)      聯(lián)系電話       余額        狀態(tài)\n"); 
                printf("%ld\t%s\t%d\t%d\t%d\t",s[i].no,s[i].name,s[i].IDcard,s[i].phone,s[i].yue);
                if(s[i].zhuangtai==1)
                     printf("正常\n");
                else
                     printf("掛失!\n"); 
                for(j=i;j<n-1;j++)
                {
                    s[j]=s[j+1];
                }
                n--;                
            }
        }
        if(found==1)
        {
            printf("未找到!\n");
        }    
        found=1;
        printf("是否繼續(xù)(Y/N)\n");
        choice=getchar();
        getchar();
        if(choice=='N'|| choice=='n')
            break;
    }
}
void transaction()     //消費(fèi)或充值 
{
    int num,i,a,b;
    int found=1;
    char choice;
    while(1)
    {
        printf("請(qǐng)輸入會(huì)員的賬號(hào):\n");
        scanf("%d",&num);
        getchar();
        for(i=0;i<n&&found==1;i++)
            if(s[i].no==num)
            {
                found=0;
                printf("%ld\t%s\t%d\t%d\t%d\t",s[i].no,s[i].name,s[i].IDcard,s[i].phone,s[i].yue);
                if(s[i].zhuangtai==1)
                    printf("正常\n");
                else
                    printf("掛失!\n"); 
                printf("請(qǐng)選擇類型:1.消費(fèi)  2.充值\n");
                scanf("%d",&a);
                getchar();
                printf("請(qǐng)輸入金額:\n");
                scanf("%d",&b); 
                getchar();
                if(a==1)
                {
                    s[i].yue=s[i].yue-b;
                    printf("%ld\t%s\t%s\t%s\t%d\t",s[i].no,s[i].name,s[i].IDcard,s[i].phone,s[i].yue);
                    if(s[i].zhuangtai==1)
                       printf("正常\n");
                    else
                       printf("掛失!\n");
                }
                else
                {
                    s[i].yue=s[i].yue+b;
                    printf("%ld\t%s\t%s\t%s\t%d\t",s[i].no,s[i].name,s[i].IDcard,s[i].phone,s[i].yue); 
                    if(s[i].zhuangtai==1)
                       printf("正常\n");
                    else
                       printf("掛失!\n");
                }       
            }
        if(found==1)
        {
            printf("未找到!\n");
        }
        found=1;    
        printf("是否繼續(xù)(Y/N)\n");
        choice=getchar();
        getchar(); 
        if(choice=='N'|| choice=='n')
            break;
    }
}
 
void sort()     //根據(jù)會(huì)員賬號(hào)從小到大排序 
{
    int i,j;
    struct VIP temp;
    for(i=0;i<n;i++) 
    {
        for (j=i+1;j<n;j++) 
        {
            if (s[i].no>s[j].no) 
            { 
                temp=s[i]; 
                s[i]=s[j]; 
                s[j]=temp; 
            }
        }
    }
    printf("\n排序后的會(huì)員信息:\n");
}
    
int main()
{
    int opt;
    printf("     |*============================================*|\n");
    printf("     |*             歡迎使用會(huì)員管理系統(tǒng)           *|\n");
    printf("     |*============================================*|\n");
    printf("     |*    1.初始化                                *|\n");
    printf("     |*    2.添加新的會(huì)員記錄                      *|\n");
    printf("     |*    3.修改已有會(huì)員記錄/掛失                 *|\n");
    printf("     |*    4.根據(jù)賬號(hào)查詢已有會(huì)員記錄              *|\n");
    printf("     |*    5.根據(jù)姓名查詢已有會(huì)員記錄              *|\n");         
    printf("     |*    6.根據(jù)身份證號(hào)查詢已有會(huì)員記錄          *|\n");
    printf("     |*    7.根據(jù)聯(lián)系電話查詢已有會(huì)員記錄          *|\n");
    printf("     |*    8.刪除已有會(huì)員記錄                      *|\n");
    printf("     |*    9.根據(jù)會(huì)員賬號(hào)排序并顯示                *|\n");
    printf("     |*    10.會(huì)員消費(fèi)或充值                       *|\n"); 
    printf("     |*    0.退出會(huì)員信息管理系統(tǒng)                  *|\n");
    printf("     |*============================================*|\n");
    while(1)
    {
        printf("請(qǐng)輸入要完成的功能:0-10:");
        scanf("%d",&opt);
        getchar();    //吸收回車 
        switch(opt)
        {
            case 1:init();print();break;          //初始化 
            case 2:add1();print();break;          //添加 
            case 3:mod();print();break;           //修改 
            case 4:findbyno();print();break;      //根據(jù)賬號(hào)查詢 
            case 5:findbyname();print();break;    //根據(jù)姓名查詢 
            case 6:findbyIDcard();print();break;  //根據(jù)身份證號(hào)查詢 
            case 7:findbyphone();print();break;   //根據(jù)聯(lián)系電話查詢 
            case 8:del();print();break;           //刪除 
            case 9:sort();print();break;          //排序 
            case 10:transaction();print();break;  //消費(fèi)/充值 
            case 0:system("cls");exit(0);break;   //退出 
            default:printf("請(qǐng)輸入0-10中的數(shù)!\n");break;
        }
    }
}

讀到這里,這篇“C語言如何實(shí)現(xiàn)會(huì)員管理系統(tǒng)”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識(shí)點(diǎn)還需要大家自己動(dòng)手實(shí)踐使用過才能領(lǐng)會(huì),如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI