首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >书店管理系统

书店管理系统
EN

Code Review用户
提问于 2022-08-29 18:34:54
回答 1查看 966关注 0票数 3

我正在做一个初学者c++项目,在那里你可以添加书籍,展示书籍。我计划添加其他功能,比如搜索数据库和检查是否有一本书可供购买。我想知道代码是否实际上遵循了最佳实践。

代码语言:javascript
复制
#include 
#include 
#include 

class book
{
    unsigned int id;
    std::string title;
    std::string author;
    std::string publisher;
    int quantity;
public:
    void add();
    void display();
};

// -----------------
// Global Variables
// -----------------

std::vector books;



void book::add()
{
    std::cout << "Enter unique id for the book: ";
    std::cin >> id;
    std::cout << "Enter the title of the book: ";
    getline(std::cin, title);
    std::cout << "Enter the author of the book: ";
    getline(std::cin, author);
    std::cout << "Enter the publisher of the book: ";
    getline(std::cin, publisher);
    quantity = 1;
    std::cout << std::endl << std::endl << "Book Recorded Successfully" << std::endl << std::endl;
}

void book::display()
{
    for(auto b: books)
    {
        std::cout << "Name of book: " << b.title << std::endl;
        std::cout << "Name of author: " << b.author << std::endl;
        std::cout << "Quantity available: " << b.quantity << std::endl;
        std::cout << std::endl << std::endl << std::endl;
    }
}


// -------------------
// FUNCTIONS
// -------------------
void book_menu();

void main_menu()
{
    int c;
    std::cout << "********************************************************" << std::endl;
    std::cout << "              BOOKSHOP MANAGEMENT SYSTEM" << std::endl;
    std::cout << "********************************************************" << std::endl;
    std::cout << "      1.  BOOKS" << std::endl;
    std::cout << "      2.  EXIT" << std::endl << std::endl << std::endl;
    std::cout << "Enter your choice" << std::endl;
    std::cin >> c;
    switch (c)
    {
    case 1:
        book_menu();
        break;
    case 2:
        exit(1);
        break;
    default:
        std::cout << "Wrong Input" << std::endl << std::endl << "Invalid Input";
        break;
    }
    return;
}

void book_menu()
{
    int c;
    book b;
    std::cout << "***********************************************" << std::endl;
    std::cout << "              BOOK MENU" << std::endl;
    std::cout << "***********************************************" << std::endl;
    std::cout << "      1.  ADD" << std::endl;
    std::cout << "      2.  DISPLAY" << std::endl;
    std::cout << "      3.  BUY BOOKS" << std::endl << std::endl << std::endl;
    std::cin >> c;
    switch (c)
    {
    case 1:
        b.add();
        books.push_back(b);
        break;
    case 2:
        b.display();
        break;
    default:
        std::cout << "Wrong Input" << std::endl << std::endl << "Invalid Input";
        break;
    }
}

int main() 
{
    while(1)
    {
        main_menu();
    }
    return 0;
}
EN

回答 1

Code Review用户

发布于 2022-08-30 21:42:42

票数 2
EN
页面原文内容由Code Review提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://codereview.stackexchange.com/questions/279266

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档