亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

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

一、問題描述及功能要求

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

(2)圖書信息瀏覽功能

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

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

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

二、代碼實(shí)現(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<<"請(qǐng)輸入你需要執(zhí)行的命令序號(hào):";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<<"輸入的指令有誤!請(qǐng)重新輸入!"<<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.按編號(hào)查詢                                  *\n"
    "*                                                                                  *\n"
    "*                                    0.退出                                        *\n"
    "*                                                                                  *\n"
    "*                                                                                  *\n"
    "************************************************************************************\n";

    Book bookList[BOOKMAXREPERTORY];

    int nowBookTotal;

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

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

        }
    }


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

    ///book
    void getBookByTitle(char title[]){
        bool flag = true;
        printf("%-6s%-10s%-10s%-10s%-10s%\n","編號(hào)","標(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");
        }
    }


    ///按編號(hào)查詢
    void queryById(){
        int cmd,i,id;
        cout<<"請(qǐng)輸入Id:";cin>>id;
        i = getBookById(id);
        if(i == -1){
            printf("查找不到!\n");
        }else{
            printf("%-6s%-10s%-10s%-10s%-10s\n","編號(hào)","標(biāo)題","作者","評(píng)級(jí)","出版社","頁數(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","編號(hào)","標(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<<"請(qǐng)輸入你需要修改的圖書編號(hào):";cin>>id;
        i = getBookById(id);
        if(i == -1){
                cout<<"圖書不存在!"<<endl;
        }else{
            cout<<"原圖書信息為:"<<endl;
            printf("%-6s%-10s%-10s%-10s%-10s\n","編號(hào)","標(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<<"請(qǐng)輸入修改后的標(biāo)題:";cin>>book.title;
            cout<<"請(qǐng)輸入修改后的作者:";cin>>book.author;
            cout<<"請(qǐng)輸入修改后的出版社:";cin>>book.publisher;
            cout<<"請(qǐng)輸入修改后的頁數(shù):";cin>>book.pageNumber;
            bookList[i] = book;
        }
    }

    /*  刪除圖書  */
    void deleteGoods(){
        int cmd,id,i;
        if(nowBookTotal == 0){
            cout<<"空的!"<<endl;
   return;
        }
        cout<<"請(qǐng)輸入你需要?jiǎng)h除的圖書編號(hào):";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)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • c++并查集優(yōu)化(基于size和rank)

    c++并查集優(yōu)化(基于size和rank)

    這篇文章主要介紹了c++并查集優(yōu)化(基于size和rank),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-02-02
  • C++11新特性中auto 和 decltype 區(qū)別和聯(lián)系

    C++11新特性中auto 和 decltype 區(qū)別和聯(lián)系

    這篇文章主要介紹了C++11新特性中auto 和 decltype 區(qū)別和聯(lián)系的相關(guān)資料,需要的朋友可以參考下
    2017-01-01
  • C/C++獲取鍵盤事件的方法

    C/C++獲取鍵盤事件的方法

    今天小編就為大家分享一篇C/C++獲取鍵盤事件的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-07-07
  • C++中的數(shù)據(jù)對(duì)齊示例詳解

    C++中的數(shù)據(jù)對(duì)齊示例詳解

    這篇文章主要介紹了C++中數(shù)據(jù)對(duì)齊的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • C++中的volatile關(guān)鍵字及其作用

    C++中的volatile關(guān)鍵字及其作用

    本文介紹了C++中的volatile關(guān)鍵字,它用于標(biāo)識(shí)變量可能被意外修改,以及編譯器不應(yīng)進(jìn)行優(yōu)化。本文通過具體的代碼示例,闡述了volatile關(guān)鍵字的作用和使用方法,幫助讀者更好地了解該關(guān)鍵字在C++語言中的應(yīng)用場景和實(shí)現(xiàn)原理
    2023-04-04
  • 一文詳解如何在VS?Code上搭建C/C++開發(fā)環(huán)境

    一文詳解如何在VS?Code上搭建C/C++開發(fā)環(huán)境

    VSCode是由微軟開發(fā)的一款免費(fèi)、開源、跨平臺(tái)的文本編輯器,它具有許多強(qiáng)大的功能,這篇文章主要給大家介紹了關(guān)于如何在VS?Code上搭建C/C++開發(fā)環(huán)境的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下
    2024-03-03
  • C++ atoi()函數(shù)用法案例詳解

    C++ atoi()函數(shù)用法案例詳解

    這篇文章主要介紹了C++ atoi()函數(shù)用法案例詳解,本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-09-09
  • c語言5個(gè)常用的排序算法實(shí)例代碼

    c語言5個(gè)常用的排序算法實(shí)例代碼

    這篇文章主要介紹了c語言5個(gè)常用的排序算法實(shí)例代碼,分享了相關(guān)代碼示例,小編覺得還是挺不錯(cuò)的,具有一定借鑒價(jià)值,需要的朋友可以參考下
    2018-02-02
  • 講解C++中的枚舉類型以及聲明新類型的方法

    講解C++中的枚舉類型以及聲明新類型的方法

    這篇文章主要介紹了講解C++中的枚舉類型以及聲明新類型的方法,是C預(yù)言入門學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下
    2015-09-09
  • C語言實(shí)現(xiàn)最全自動(dòng)售貨機(jī)

    C語言實(shí)現(xiàn)最全自動(dòng)售貨機(jī)

    這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)最全自動(dòng)售貨機(jī),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-01-01

最新評(píng)論