91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

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

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

C語言如何實現圖書管理系統開發

發布時間:2022-08-04 10:25:32 來源:億速云 閱讀:164 作者:iii 欄目:開發技術

本文小編為大家詳細介紹“C語言如何實現圖書管理系統開發”,內容詳細,步驟清晰,細節處理妥當,希望這篇“C語言如何實現圖書管理系統開發”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學習新知識吧。

程序介紹

圖書管理系統主要有以下功能:

1、錄入圖書信息。
2、實現刪除功能,即輸入圖書號刪除相應的記錄。
3、實現查找功能,即輸入圖書號或圖書名查詢該書相關信息
4、實現修改功能,即輸入圖書號或圖書名修改相應信息。
5、添加會員信息,只有會員才可借書。
6、實現借書功能,即輸入圖書號及會員號進行借書。
7、實現還書功能,還書時也同樣需輸入圖書號及會員號。
8、保存添加的圖書信息。
9、保存添加的會員信息。

C語言如何實現圖書管理系統開發

代碼

#include <stdio.h>
#include <windows.h>
#include <mysql.h>
#pragma  comment(lib,"libmysql.lib")

/*定義數據庫相關操作變量*/
MYSQL mysql;          //
MYSQL_RES *result;    //定義結果集變量
MYSQL_ROW row;        //定義行變量
char ch[2];


void ShowAll();       /*顯示所有的圖書信息*/
void AddBook();       /*添加圖書信息*/
void ModifyBook();    /*修改圖書信息*/
void DeleteBook();    /*刪除圖書信息*/
void QueryBook();     /*查詢圖書信息*/


/*顯示菜單*/
void showmenu()
{
    system("cls");
    printf("\n\n\n\n\n");
    printf("\t╔═══════════════════════════╗\n");
    printf("\t║            Welcome To Lemon Books System             ║\n");
    printf("\t╠═══════════════════════════╣\n");
    printf("\t║\t\t 1 - 顯示所有圖書信息                   ║\n");
    printf("\t║\t\t 2 - 添加圖書信息                       ║\n");
    printf("\t║\t\t 3 - 修改圖書信息                       ║\n");
    printf("\t║\t\t 4 - 刪除圖書信息                       ║\n");
    printf("\t║\t\t 5 - 查詢圖書信息                       ║\n");
    printf("\t║\t\t 6 - 退出                               ║\n");
    printf("\t╚═══════════════════════════╝\n");
    printf("\n              ENTER YOUR CHOICE(1-6):");
    
}

void inquire()  /*詢問用戶是否顯示主菜單*/
{
    printf("\t 顯示主菜單?(y/n):");
    scanf("%s",ch);
    if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)/*判斷是否要顯示查找到的信息*/
    {
        showmenu();   /*顯示菜單*/ 
    }
    else
    {
        exit(0);
    }
}

/*顯示主菜單,連接數據庫*/
int main()
{
    int n ;   //定義變量  存儲用戶輸入的編號
    
    mysql_init(&mysql);  //初始化mysql結構
    
    showmenu();   /*顯示菜單*/ 
    
    scanf("%d",&n);/*輸入選擇功能的編號*/
    
    while(n)
    { 
        switch(n)
        {
            case 1: 
                ShowAll();    /*調用顯示所有圖書數據的過程*/
                break;
            case 2: 
                AddBook();   /*添加圖書信息*/
                break;
            case 3: 
                ModifyBook();     /*修改圖書信息*/
                break;
            case 4:
                DeleteBook();   /*刪除圖書信息*/
                break;
            case 5:
                QueryBook();   /*查詢圖書信息*/
                break;
            case 6:
                exit(0);       /*退出*/
            default:break;
        }
        scanf("%d",&n);
    }
}

void ShowAll()    /*調用顯示所有圖書數據的過程*/
{
    
    /*連接數據庫*/
    if(!mysql_real_connect(&mysql,"localhost","root","root","db_books",3306,NULL,0))
    { 
        printf("\n\t 不能連接數據庫!\n");
    }
    else
    {
        /*數據庫連接成功*/
        if(mysql_query(&mysql,"select * from tb_book"))
        {   //如果查詢失敗
            printf("\n\t 查詢 tb_book 數據表失敗!\n");
        }
        else
        {
            result=mysql_store_result(&mysql); //獲得結果集
            if(mysql_num_rows(result)!=NULL)
            {  //有記錄的情況,只有有記錄取數據才有意義
                printf("\t ════════════════════════════ \n");
                printf("\t                 顯 示 所 有 圖 書 信 息                  \n");
                printf("\t ════════════════════════════ \n");
                printf("\t  圖書編號       圖書名         作者        出版社      \n");
                printf("\t -------------------------------------------------------- \n");
                while((row=mysql_fetch_row(result)))
                {   //取出結果集中記錄
                    fprintf(stdout,"\t     %s             %s            %s         %s   \n",row[0],row[1],row[2],row[3]);  //輸出這行記錄
                }
                printf("\t ════════════════════════════ \n");
            }
            else
            {
                printf("\n\t 沒有記錄信息 !\n");
            }
            mysql_free_result(result);    //釋放結果集
        }
        mysql_close(&mysql);          //釋放連接
    }
    inquire();   /*詢問是否顯示主菜單*/
    
}
void AddBook()    /*添加圖書信息*/
{
    int rowcount;   /*結果集中的行數*/

    char id[10];       /*編號*/
    char *bookname;
    char *author;
    char *bookconcern;
    
    char *sql;    
    char dest[500] ={"  "};    
    
    /*連接數據庫*/
    if(!mysql_real_connect(&mysql,"127.0.0.1","root","root","db_books",0,NULL,0))
    { 
        printf("\n\t 不能連接數據庫!\n");
    }
    else
    {
        /*數據庫連接成功,插入數據*/   
        printf("\t ════════════════════════════ \n");
        printf("\t                     添 加 圖 書 信 息                    \n");
        printf("\t ════════════════════════════ \n");
        if(mysql_query(&mysql,"select * from tb_book"))
        {   //如果查詢失敗
            printf("\n\t 查詢 tb_book 數據表失敗!\n");
        }
        else
        {
            result=mysql_store_result(&mysql); //獲得結果集
            rowcount=mysql_num_rows(result) ;  //獲得行數
            row=mysql_fetch_row(result);       //獲取結果集的行  
            
            printf("\t 圖書編號:");
            scanf("%s",id);   /*輸入圖書編號*/    
            
            sql="insert into tb_book (ID,bookname,author,bookconcern) values (";
            strcat(dest,sql);
            strcat(dest,"'");
            strcat(dest,id);
            strcat(dest,"', '");


            if(mysql_num_rows(result)!=NULL)
            {                
                /*判斷輸入的編號是否存在*/
                do
                {   //存在相同編號
                    if(!strcmp(id,row[0]))
                    {
                      //  printf("%s",row[0]);
                        printf("\n\t 記錄存在,按任意鍵繼續!\n");
                        getch();
                        mysql_free_result(result);   /*釋放結果集*/ 
                        mysql_close(&mysql);         /*釋放連接*/  
                        inquire();   /*詢問是否顯示主菜單*/
                        return;
                    }
                }while(row=mysql_fetch_row(result));  
            }
            
            bookname = (char*)malloc(50);
            author = (char*)malloc(50);
            bookconcern = (char*)malloc(50);

            
            //不存在相同的編號            
            printf("\t 圖書名:");
            scanf("%s",bookname);   /*輸入圖書名*/
            strcat(dest,bookname);    /*將圖書編號追加到sql語句后面*/
            
            printf("\t 作者:");
            scanf("%s",author);    /*輸入作者*/
            strcat(dest,"', '");
            strcat(dest,author);
            
            printf("\t 出版社:");
            scanf("%s",bookconcern);    /*輸入出版社*/
            strcat(dest,"', '");
            strcat(dest,bookconcern);
            strcat(dest,"')");
            //printf("%s",dest);
            
            if ( mysql_query(&mysql,dest)!=0)   
            {
                fprintf(stderr,"\t 不能插入記錄!",mysql_error(&mysql));
            }
            else
            {
                printf("\t 插入成功!\n");                
            }
            mysql_free_result(result);    //釋放結果集
        }
        mysql_close(&mysql);          //釋放連接
    }
    exit(0);
}   


void ModifyBook()   /*修改圖書信息*/
{
    char id[10];   /*結果集中的行數*/
    char *sql;    
    char dest[500] ={"  "};
    char dest1[500] ={"  "};
    
    char *bookname;
    char *author;
    char *bookconcern;
    
    if (!mysql_real_connect(&mysql,"127.0.0.1","root","root","db_books",0,NULL,0))
    {
        printf("\t 不能連接數據庫!\n");
    }
    else
    {
        /*數據庫連接成功*/
        // printf("連接成功");
        printf("\t 請輸入您想要修改的圖書編號.");
        
        scanf("%s",id);   /*輸入圖書編號*/
        sql = "select * from tb_book where id=";
        strcat(dest,sql);
        strcat(dest,id);    /*將圖書編號追加到sql語句后面*/
        
        //printf("%s\n",dest);
        
        /*查詢該圖書信息是否存在*/
        if(mysql_query(&mysql,dest))
        {   //如果查詢失敗
            printf("\n  查詢 tb_book 數據表失敗! \n");
        }
        else
        {
            result=mysql_store_result(&mysql); //獲得結果集
            if(mysql_num_rows(result)!=NULL)
            {
                //有記錄的情況,只有有記錄取數據才有意義
                printf("\t 發現記錄信息,是否顯示?(y/n) ");
                scanf("%s",ch);
                if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)/*判斷是否要顯示查找到的信息*/
                {
                    printf("\t ════════════════════════════ \n");
                    printf("\t               ***** 顯示圖書信息 *****                   \n");
                    printf("\t ════════════════════════════ \n");
                    printf("\t圖書編號       圖書名         作者        出版社      \n");
                    printf("\t -------------------------------------------------------- \n");
                    while((row=mysql_fetch_row(result)))
                    {   //取出結果集中記錄
                        fprintf(stdout,"\t   %s             %s             %s          %s   \n",row[0],row[1],row[2],row[3]);  //輸出這行記錄
                    }
                    printf("\t ════════════════════════════ \n");
                }
                
                
                printf("\t Modify?(y/n)");
                scanf("%s",ch);
                if (strcmp(ch,"Y")==0||strcmp(ch,"y")==0)    /*判斷是否需要錄入*/
                {

 
                    sql = "update tb_book set bookname= '";
                    strcat(dest1,sql);
                    //   printf("%s",sql);
                    bookname = (char*)malloc(20);
                    author = (char*)malloc(20);
                    bookconcern = (char*)malloc(20);

                    printf("\t 圖書名:");
                    scanf("%s",bookname);   /*輸入圖書名*/
                    
                    strcat(dest1,bookname); 
                    //  printf("%s",&bookname);

                    printf("\t 作者:");
                    scanf("%s",author);    /*輸入作者*/
                    strcat(dest1,"', author= '");
                    strcat(dest1,author);    /*追加sql語句*/                        
                    
                    printf("\t 出版社:");
                    scanf("%s",bookconcern);    /*輸入出版社*/
                    strcat(dest1,"', bookconcern = '");
                    strcat(dest1,bookconcern);    /*追加sql語句*/
                    
                    strcat(dest1,"' where id= ");
                    strcat(dest1,id);                        
                    
                    //printf("%s",dest1);

                    if(mysql_query(&mysql,dest1)!=0)
                    {   
                        fprintf(stderr,"\t 不能修改記錄!\n",mysql_error(&mysql));                            
                    }
                    else
                    {
                        printf("\t 修改成功!\n");
                    }
                }
                
            }
            else
            {
                printf("\t 沒有發現要修改的信息!\n");
            }
        }
        mysql_free_result(result);          //釋放結果集
    }
    mysql_close(&mysql);     //釋放連接
    exit(0);
}

void DeleteBook()   /*刪除圖書信息*/
{
    char id[10];   /*結果集中的行數*/
    char *sql;
    char dest[100] ={"  "};
    char dest1[100] ={"  "};
    if(!mysql_real_connect(&mysql,"127.0.0.1","root","root","db_books",0,NULL,0))
    {
        printf("\t 不能連接數據庫!\n");
    }
    else
    {
        printf("\t 請輸入您想要刪除的圖書編號. ");        
        scanf("%s",id);   /*輸入圖書編號*/
        sql = "select * from tb_book where id=";
        strcat(dest,sql);
        strcat(dest,id);    /*將圖書編號追加到sql語句后面*/        
        //printf("%s\n",dest);
        
        /*查詢該圖書信息是否存在*/
        if(mysql_query(&mysql,dest))
        {   //如果查詢失敗
            printf("\n 查詢 tb_book 數據表失敗! \n");
        }
        else
        { 
            result=mysql_store_result(&mysql); //獲得結果集
            if(mysql_num_rows(result)!=NULL)
            {  //有記錄的情況,只有有記錄取數據才有意義
                printf("\t 發現記錄信息,是否顯示?(y/n) ");
                scanf("%s",ch);
                if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)/*判斷是否要顯示查找到的信息*/
                {
                    printf("\t ════════════════════════════ \n");
                    printf("\t               ***** 顯示圖書信息 *****                   \n");
                    printf("\t ════════════════════════════ \n");
                    printf("\t圖書編號       圖書名         作者        出版社      \n");
                    printf("\t -------------------------------------------------------- \n");
                    while((row=mysql_fetch_row(result)))
                    {   //取出結果集中記錄
                        fprintf(stdout,"\t   %s             %s             %s          %s   \n",row[0],row[1],row[2],row[3]);  //輸出這行記錄
                    }
                    printf("\t ════════════════════════════ \n");
                }
                                    
                    printf("\t 是否刪除?(y/n) ");
                    scanf("%s",ch);
                    if (strcmp(ch,"Y")==0||strcmp(ch,"y")==0)    /*判斷是否需要錄入*/
                    {
                        sql = "delete from tb_book where ID= ";
                        printf("%s",dest1);
                        strcat(dest1,sql);
                        strcat(dest1,id);
                       // printf("%s",dest1);
                        
                        if(mysql_query(&mysql,dest1)!=0)
                        {
                            fprintf(stderr,"\t 不能刪除記錄! \n",mysql_error(&mysql));
                        }
                        else
                        {
                            printf("\t 刪除成功!\n");
                        }
                    }
            }
            else
            {
                printf("\t 沒有發現要刪除的信息!\n");
            }
        }
        mysql_free_result(result);    //釋放結果集
    }
    mysql_close(&mysql);
   exit(0);   
}

void QueryBook()   /*查詢圖書信息*/
{     
    char id[10];   /*結果集中的行數*/
    char *sql;
    char dest[100] ={"  "};
    
    if(!mysql_real_connect(&mysql,"127.0.0.1","root","root","db_books",0,NULL,0))
    {
        printf("\t 不能連接數據庫!\n");
    }
    else
    {  
        printf("\t 請輸入您想要查詢的圖書編號:");        
        scanf("%s",id);   /*輸入圖書編號*/
        sql = "select * from tb_book where id=";
        strcat(dest,sql);
        strcat(dest,id);    /*將圖書編號追加到sql語句后面*/        
        
        if(mysql_query(&mysql,dest))
        {   //如果查詢失敗
            printf("\n 查詢 tb_book 數據表失敗!\n");
        }
        else
        {
            result=mysql_store_result(&mysql); //獲得結果集
            if(mysql_num_rows(result)!=NULL)
            {  //有記錄的情況,只有有記錄取數據才有意義
                printf("\t ════════════════════════════ \n");
                printf("\t                          顯示圖書信息                      \n");
                printf("\t ════════════════════════════ \n");
                printf("\t圖書編號       圖書名         作者        出版社      \n");
                printf("\t -------------------------------------------------------- \n");
                while((row=mysql_fetch_row(result)))
                {   //取出結果集中記錄
                    fprintf(stdout,"\t   %s             %s             %s          %s   \n",row[0],row[1],row[2],row[3]);  //輸出這行記錄
                }
                printf("\t ════════════════════════════ \n");                
            }
            else
            {
                printf("\t 沒有發現要查詢的信息!\n");
            }
            mysql_free_result(result);    //釋放結果集
        }
        mysql_close(&mysql);          //釋放連接
    }
    exit(0);
}

讀到這里,這篇“C語言如何實現圖書管理系統開發”文章已經介紹完畢,想要掌握這篇文章的知識點還需要大家自己動手實踐使用過才能領會,如果想了解更多相關內容的文章,歡迎關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

鄂托克旗| 彰化县| 博乐市| 肇庆市| 嘉禾县| 朝阳县| 疏附县| 南城县| 临清市| 安西县| 佳木斯市| 巴里| 淮阳县| 泸西县| 白山市| 日照市| 常德市| 泾川县| 墨玉县| 扬中市| 冷水江市| 礼泉县| 涿州市| 东平县| 德州市| 博兴县| 根河市| 靖宇县| 东乡| 合阳县| 谷城县| 方正县| 达日县| 黄平县| 山东省| 神池县| 安龙县| 勃利县| 德格县| 松原市| 濮阳市|