C++实现图书管理系统最新版

图书管理系统设计,供大家参考,具体内容如下

一、问题描述及功能要求

(1)图书信息录入功能(图书信息用文件保存)

(2)图书信息浏览功能

(3)查询和排序功能:(至少一种查询方式)

.按书名查询
.按作者名查询

(4)图书信息的删除与修改

二、代码实现 带有注释

废话不说,直接代码,欢迎指正。
大家CV可能有不兼容的情况,可以滴滴,尽可能解决问题地回复。

#include
#include
#include 
#include
#include 
#include
#include
#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,参数为毫秒 */
            printf(".");
            fflush(stdout);//强制刷新缓存,输出显示
        }
        printf("\n");
        system("cls");
        int cmd;
        while(true){
            cout<>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<<"输入的指令有误!请重新输入!"<>book.id;
        cout<<"请输入标题:";cin>>book.title;
        cout<<"请输入作者:";cin>>book.author;
        cout<<"请输入出版社:";cin>>book.publisher;
        cout<<"请输入页数:";cin>>book.pageNumber;
        if(getBookById(book.id) != -1){
            cout<<"添加失败! 添加编号重复! 请重新添加!"<>cmd;
            if(cmd == 0){
                break;
            }
            system("cls");
            switch(cmd){
                case 1:
                    queryByTitle();
                    break;
                case 2:
                    queryById();
                    break;
                default:
                    cout<<"输入的指令有误!请重新输入!"<>title;
        getBookByTitle(title);
    }

    ///book
    void getBookByTitle(char title[]){
        bool flag = true;
        printf("%-6s%-10s%-10s%-10s%-10s%\n","编号","标题","作者","出版社","页数");
        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","编号","标题","作者","评级","出版社","页数");
            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","编号","标题","作者","出版社","页数");
            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<<"图书不存在!"<>book.title;
            cout<<"请输入修改后的作者:";cin>>book.author;
            cout<<"请输入修改后的出版社:";cin>>book.publisher;
            cout<<"请输入修改后的页数:";cin>>book.pageNumber;
            bookList[i] = book;
        }
    }

    /*  删除图书  */
    void deleteGoods(){
        int cmd,id,i;
        if(nowBookTotal == 0){
            cout<<"空的!"<>id;
        deleteBook(id);
    }

    ///book
    void deleteBook(int id){
        int index = getBookById(id);
        if(index == -1){
            cout<<"没有该图书!"< 
 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

你可能感兴趣的:(C++实现图书管理系统最新版)