首页 > 解决方案 > 如何让用户创建/输入新书数据(使用 OOP)

问题描述

图书馆中的一本书有一些数据,即:书名、书号、副本数(假设同一本书可能不止一本)、出版年份以及这本书是否被借阅。假设图书馆里最多有 10 本书。用户应该能够“创建”一本新书并输入/修改其数据。用户应该能够得到关于图书馆所有图书、借阅图书数量和某一年出版图书数量的报告。(注意:您必须根据需要添加其他数据项才能完成此任务)我应该创建至少 2 个类,如何让用户创建/输入新的书籍数据(使用 OOP) PS:我不确定代码

#include <iostream>
using namespace std;
class book
{
    private:
    string title[10];
    int bookno[10];
    int copyno[20];
    int year[10];
    book () // constructor
    {
        booktitle = "";
        bookno = 0;
        copyno = 0;
        publishyear = 0;
    }
    public:
    void setTitle (string t) // setter
    {
        title = t;
    }
    string getTitle () // getter
    {
        return title;
    }
    void setBookno (int n) // setter
    {
        bookno = n;
    }
    int getBookno () // getter
    {
        return bookno;
    }
    void setCopyno (int c) // setter
    {
        copyno = c;
    }
    int getCopyno () // getter
    {
        return copyno;
    }
    void setYear (int y) // setter
    {
        year = y;
    }
    int getYear () //getter
    {
        return year;
    }

    void creat_book()
    {
        for(int i=1; i<=01;i++)
        {

        cout <<"Name of the book"<<title[]<<endl;
        cout <<"Book number is:"<<bookno[]<<endl;
        cout <<"published year is:"<<year[]<,endl;

        }
    }
int main()
{
    book b1;
    b1.get_booktitle ();
    b1.get_bookno ();
    b1.get_copyno ();
    b1.get_borrowed ();


    return 0;
}

标签: c++classoop

解决方案


推荐阅读