c++ - 如何让用户创建/输入新书数据(使用 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;
}
解决方案
推荐阅读
- php - 无法将用户的 id 关联到任务 Laravel
- ios - How to record audio for a certain duration using AV Audio
- vuejs2 - Unit-testing VueJS component doesn't seem to register click() invocation
- python - 在其他函数中使用全局变量不起作用
- swift - Using SwiftNIO and SwiftNIOHTTP2 as an HTTP2 client
- javascript - Connect express with react application
- python - GCP:在哪里安排写入 BigQuery 的 PubSub 订阅者
- ruby-on-rails - 具有货币字段类型的 Searchkick 和 PostgreSQL
- android - MongoDB Mobile 是否构建在 SQLite 之上?
- r - 在 R 中使用聚合函数过滤特定值