最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C++實現(xiàn)圖書管理系統(tǒng)最新版

 更新時間:2021年06月17日 15:36:51   作者:名名名名  
這篇文章主要為大家詳細(xì)介紹了C++實現(xiàn)圖書管理系統(tǒng)最新版,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

圖書管理系統(tǒng)設(shè)計,供大家參考,具體內(nèi)容如下

一、問題描述及功能要求

(1)圖書信息錄入功能(圖書信息用文件保存)

(2)圖書信息瀏覽功能

(3)查詢和排序功能:(至少一種查詢方式)

.按書名查詢
.按作者名查詢

(4)圖書信息的刪除與修改

二、代碼實現(xiàn) 帶有注釋

廢話不說,直接代碼,歡迎指正。
大家CV可能有不兼容的情況,可以滴滴,盡可能解決問題地回復(fù)。

#include<iostream>
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include <cstring>
#include<windows.h>
#include<vector>
#define BOOKMAXREPERTORY 99
using namespace std;
class Common{
public:
    int id;
    char title[66];
    char author[66];
    Common(){
    }
    Common(int _id,char _title[],char _author[]){
        id = _id;
        strcpy(title , _title);
        strcpy(author , _author);
    }
};

class Book:public Common{
public:
    char publisher[66];
    int pageNumber;
    Book(){}
    Book(int _id,char _title[],char _author[],char _publisher[],char _iSBNNumber[],int _pageNumber){
        Common(_id,_title,_author);
        strcpy(publisher,_publisher);
        pageNumber = _pageNumber;
    }
};

class MediaLibraryManageSystem{
public:

    MediaLibraryManageSystem(){
        nowBookTotal = 0;
    }

    void _run(){
        readDataByFile();
        printf("程序加載中");
        for (int i = 0; i < 10; i++) {
            Sleep(100);    /* windows 使用Sleep,參數(shù)為毫秒 */
            printf(".");
            fflush(stdout);//強(qiáng)制刷新緩存,輸出顯示
        }
        printf("\n");
        system("cls");
        int cmd;
        while(true){
            cout<<home_menu<<endl;
            cout<<"請輸入你需要執(zhí)行的命令序號:";cin>>cmd;
            if(cmd == 0){
                _exit();
            }
            system("cls");
            switch(cmd){
                case 1:
                    addBook();
                    break;
                case 2:
                    queryGoods();
                    break;
                case 3:
                    showGoods();
                    break;
                case 4:
                    updateGoods();
                    break;
                case 5:
                    deleteGoods();
                    break;
                default:
                    cout<<"輸入的指令有誤!請重新輸入!"<<endl;
            }
            system("pause");
            system("cls");

        }
    }





private:

    const string home_menu =
    "\n********************************** 圖書管理系統(tǒng) **********************************\n"
    "*                                                                                  *\n"
    "*                                                                                  *\n"
    "*                                     1.添加                                       *\n"
    "*                                                                                  *\n"
    "*                                     2.查詢                                       *\n"
    "*                                                                                  *\n"
    "*                                     3.顯示圖書庫                                 *\n"
    "*                                                                                  *\n"
    "*                                     4.修改圖書庫                                 *\n"
    "*                                                                                  *\n"
    "*                                     5.刪除                                       *\n"
    "*                                                                                  *\n"
    "*                                     0.退出                                       *\n"
    "*                                                                                  *\n"
    "*                                                                                  *\n"
    "************************************************************************************\n";

    const string query_goods_menu =
    "\n************************************ 圖書查詢 ************************************\n"
    "*                                                                                  *\n"
    "*                                                                                  *\n"
    "*                                    1.按標(biāo)題查詢                                  *\n"
    "*                                                                                  *\n"
    "*                                    2.按編號查詢                                  *\n"
    "*                                                                                  *\n"
    "*                                    0.退出                                        *\n"
    "*                                                                                  *\n"
    "*                                                                                  *\n"
    "************************************************************************************\n";

    Book bookList[BOOKMAXREPERTORY];

    int nowBookTotal;

    ///添加圖書
    void addBook(){
        Book book;
        cout<<"請輸入編號:";cin>>book.id;
        cout<<"請輸入標(biāo)題:";cin>>book.title;
        cout<<"請輸入作者:";cin>>book.author;
        cout<<"請輸入出版社:";cin>>book.publisher;
        cout<<"請輸入頁數(shù):";cin>>book.pageNumber;
        if(getBookById(book.id) != -1){
            cout<<"添加失敗! 添加編號重復(fù)! 請重新添加!"<<endl;
        }else if(nowBookTotal == BOOKMAXREPERTORY){
            cout<<"添加失敗! 圖書庫已滿!"<<endl;
        }else{
            bookList[nowBookTotal ++] = book;
        }
    }

    /*  查詢圖書  */
    void queryGoods(){
        int cmd;
        while(true){
            cout<<query_goods_menu<<endl;
            cout<<"請輸入你需要執(zhí)行的命令序號:";cin>>cmd;
            if(cmd == 0){
                break;
            }
            system("cls");
            switch(cmd){
                case 1:
                    queryByTitle();
                    break;
                case 2:
                    queryById();
                    break;
                default:
                    cout<<"輸入的指令有誤!請重新輸入!"<<endl;
            }
            system("pause");
            system("cls");

        }
    }


    ///按標(biāo)題查詢
    void queryByTitle(){
        int cmd;
        char title[66];
        cout<<"請輸入標(biāo)題:";cin>>title;
        getBookByTitle(title);
    }

    ///book
    void getBookByTitle(char title[]){
        bool flag = true;
        printf("%-6s%-10s%-10s%-10s%-10s%\n","編號","標(biāo)題","作者","出版社","頁數(shù)");
        for(int i = 0;i < nowBookTotal;i ++){
            if(strcmp(bookList[i].title,title) == 0){
                flag = false;
                printf("%-6d%-10s%-10s%-10s%-10d\n",bookList[i].id,bookList[i].title,bookList[i].author,bookList[i].publisher,bookList[i].pageNumber);
            }
        }
        if(flag){
            printf("\n\n空的!\n\n");
        }
    }


    ///按編號查詢
    void queryById(){
        int cmd,i,id;
        cout<<"請輸入Id:";cin>>id;
        i = getBookById(id);
        if(i == -1){
            printf("查找不到!\n");
        }else{
            printf("%-6s%-10s%-10s%-10s%-10s\n","編號","標(biāo)題","作者","評級","出版社","頁數(shù)");
            printf("%-6d%-10s%-10s%-10s%-10d\n",bookList[i].id,bookList[i].title,bookList[i].author,bookList[i].publisher,bookList[i].pageNumber);
        }
    }

    ///Book
    int getBookById(int id){
        int index = -1;
        for(int i = 0;i < nowBookTotal;i ++){
            if(bookList[i].id == id){
                index = i;
                break;
            }
        }
        return index;
    }

    /*  顯示圖書庫  */
    void showGoods(){
        if(nowBookTotal == 0){
            printf("空的!\n");
        }else{
            printf("%-6s%-10s%-10s%-10s%-10s\n","編號","標(biāo)題","作者","出版社","頁數(shù)");
            for(int i = 0;i < nowBookTotal;i ++){
                printf("%-6d%-10s%-10s%-10s%-10d\n",bookList[i].id,bookList[i].title,bookList[i].author,bookList[i].publisher,bookList[i].pageNumber);
            }
        }
    }

    /*  修改圖書  */
    void updateGoods(){
        int cmd,id,i;
        cout<<"請輸入你需要修改的圖書編號:";cin>>id;
        i = getBookById(id);
        if(i == -1){
                cout<<"圖書不存在!"<<endl;
        }else{
            cout<<"原圖書信息為:"<<endl;
            printf("%-6s%-10s%-10s%-10s%-10s\n","編號","標(biāo)題","作者","出版社","頁數(shù)");
            printf("%-6d%-10s%-10s%-10s%-10d\n",bookList[i].id,bookList[i].title,bookList[i].author,bookList[i].publisher,bookList[i].pageNumber);
            Book book;
            book.id = id;
            cout<<"請輸入修改后的標(biāo)題:";cin>>book.title;
            cout<<"請輸入修改后的作者:";cin>>book.author;
            cout<<"請輸入修改后的出版社:";cin>>book.publisher;
            cout<<"請輸入修改后的頁數(shù):";cin>>book.pageNumber;
            bookList[i] = book;
        }
    }

    /*  刪除圖書  */
    void deleteGoods(){
        int cmd,id,i;
        if(nowBookTotal == 0){
            cout<<"空的!"<<endl;
   return;
        }
        cout<<"請輸入你需要刪除的圖書編號:";cin>>id;
        deleteBook(id);
    }

    ///book
    void deleteBook(int id){
        int index = getBookById(id);
        if(index == -1){
            cout<<"沒有該圖書!"<<endl;
        }else{
            for(int i = index;i < nowBookTotal - 1;i ++){
                bookList[i] = bookList[i + 1];
            }
            nowBookTotal --;
            cout<<"刪除成功!"<<endl;
        }
    }

    /*  保存圖書  */
    void saveDataToFile(){
        ///book
        FILE *bookDB = fopen("bookList.txt", "wb");
        for (int i = 0; i < nowBookTotal; i++) {
            fwrite(&bookList[i], sizeof(Book), 1, bookDB);
        }
        fclose(bookDB);
    }

    /*  讀取圖書  */
    void readDataByFile(){
        ///Book
        FILE *bookDB = fopen("bookList.txt", "rb");
        nowBookTotal = 0;
        Book book;
        while (fread(&book, sizeof(Book), 1, bookDB) == 1) {
            bookList[nowBookTotal++] = book;
        }
        fclose(bookDB);
    }

    void _exit(){
        saveDataToFile();
        system("cls");
        printf("正在退出");
        for (int i = 0; i < 10; i++) {
            Sleep(100); 
            printf(".");
            fflush(stdout);//強(qiáng)制刷新緩存,輸出顯示
        }
        system("cls");
        printf("已退出!");
        exit(1);
    }

};

int main(){
    MediaLibraryManageSystem mediaLibraryManageSystem;
    mediaLibraryManageSystem._run();
    return 0;
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 一起來了解一下C++中的指針

    一起來了解一下C++中的指針

    這篇文章主要為大家詳細(xì)介紹了C++的指針,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-02-02
  • C語言超詳細(xì)講解排序算法上篇

    C語言超詳細(xì)講解排序算法上篇

    時間如流水,今天就到初階數(shù)據(jù)結(jié)構(gòu)最后一個知識章節(jié)了,常見的排序算法!在進(jìn)入這期之前,程愛打籃球的程序猿想說一句,如果有不懂的地方可以反復(fù)觀看我之前的內(nèi)容,再還有不懂可以直接找我,幫你安排的妥妥的
    2022-03-03
  • C語言在輸入輸出時遇到的常見問題總結(jié)

    C語言在輸入輸出時遇到的常見問題總結(jié)

    大家在平時的做題中是否會遇到和我一樣的煩惱,題目的代碼已經(jīng)基本完成,但是在輸出時候,總是和題目給出的樣例輸出格式不同?,導(dǎo)致題目不能通過。為了解決這一煩惱,我總結(jié)了以下幾點,需要的可以參考一下
    2022-09-09
  • Microsoft Visual Studio 2022的安裝與使用詳細(xì)教程

    Microsoft Visual Studio 2022的安裝與使用詳細(xì)教程

    Microsoft Visual Studio 2022是Microsoft Visual Studio軟件的一個高版本,能夠編寫和執(zhí)行C/C++代碼,具有強(qiáng)大的功能,是開發(fā)C/C++程序的主流軟件,這篇文章主要介紹了Microsoft Visual Studio 2022的安裝與使用詳細(xì)教程
    2024-01-01
  • 淺談C++中replace()方法

    淺談C++中replace()方法

    C++編程語言中的string應(yīng)用方式多樣化,每一種應(yīng)用方式都能幫助我們提實現(xiàn)特定的功能需求。在這里我們將會為大家詳細(xì)介紹一下其中一個比較重要的用法,有關(guān)C++ replace()函數(shù)的應(yīng)用方式,需要的朋友可以參考下
    2015-11-11
  • C語言的常量和字符串

    C語言的常量和字符串

    這篇文章主要為大家介紹了C語言常量和字符串,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2021-12-12
  • Qt 使用 canon edsdk 實現(xiàn)實時預(yù)覽的示例代碼

    Qt 使用 canon edsdk 實現(xiàn)實時預(yù)覽的示例代碼

    這篇文章主要介紹了Qt 使用 canon edsdk 實現(xiàn)實時預(yù)覽的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • C++實現(xiàn)獲取時間戳和計算運行時長

    C++實現(xiàn)獲取時間戳和計算運行時長

    這篇文章主要為大家詳細(xì)介紹了如何使用C++實現(xiàn)獲取時間戳和計算運行時長功能,文中的示例代碼講解詳細(xì),有需要的小伙伴可以參考一下
    2024-12-12
  • C++多線程之互斥鎖與死鎖

    C++多線程之互斥鎖與死鎖

    互斥鎖和死鎖是C++多線程中常見的情況,這篇文章就帶大家進(jìn)一步了解多線程中的互斥鎖與死鎖這兩個概念,文中的示例代碼介紹得很詳細(xì),快來跟隨小編一起學(xué)習(xí)吧
    2021-12-12
  • C語言完整實現(xiàn)12種排序算法(小結(jié))

    C語言完整實現(xiàn)12種排序算法(小結(jié))

    本文主要介紹了C語言完整實現(xiàn)12種排序算法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-05-05

最新評論

鹤峰县| 利川市| 兴山县| 常德市| 罗田县| 平遥县| 信丰县| 双鸭山市| 石景山区| 大姚县| 昌都县| 安新县| 文安县| 久治县| 东源县| 卓资县| 阳山县| 阳山县| 印江| 获嘉县| 柳河县| 山阳县| 咸宁市| 马龙县| 通化县| 眉山市| 荥经县| 灌阳县| 米易县| 广丰县| 岐山县| 应用必备| 正安县| 洞口县| 蛟河市| 河曲县| 合水县| 开平市| 南开区| 高邮市| 云安县|