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í)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- C++實(shí)現(xiàn)簡單的圖書管理系統(tǒng)
- C++實(shí)現(xiàn)圖書管理系統(tǒng)
- C++實(shí)現(xiàn)圖書管理系統(tǒng)課程設(shè)計(jì)
- C++實(shí)現(xiàn)圖書管理系統(tǒng)源碼
- C++編寫實(shí)現(xiàn)圖書管理系統(tǒng)
- C++實(shí)現(xiàn)圖書館管理系統(tǒng)
- C++實(shí)現(xiàn)圖書管理系統(tǒng)課程設(shè)計(jì)(面向?qū)ο?
- C++利用鏈表實(shí)現(xiàn)圖書信息管理系統(tǒng)
- C++順序表實(shí)現(xiàn)圖書管理系統(tǒng)
- C++實(shí)現(xiàn)簡單版圖書管理系統(tǒng)
相關(guān)文章
C++11新特性中auto 和 decltype 區(qū)別和聯(lián)系
這篇文章主要介紹了C++11新特性中auto 和 decltype 區(qū)別和聯(lián)系的相關(guān)資料,需要的朋友可以參考下2017-01-01一文詳解如何在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-03C語言實(shí)現(xiàn)最全自動(dòng)售貨機(jī)
這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)最全自動(dòng)售貨機(jī),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01