0

I've been trying to do this assignment where we want to build a library management system and we need to use classes, methods and attributes to do it. The problem is: I want to add a functionality where the user adds a book to the system, so he needs to input the details of the book. The name of the book can contain spaces and I want to use getline to let the user input the string attributes for the book but it's not working and each time i try something I get many errors. here is the code:

#include <iostream>
#include <cstring>

using namespace std;
class NewBook {
public:
string name;
string type;
string author;
string year;
int price;
auto getline(string) {
    cout << "name: \n";
    cin >> name;
    cout << "type: \n";
    cin >> type;
    cout << "author: \n";
    cin >> author;
    cout << "year: \n";
    cin >> year;
    cout << "price: \n";
    cin>>price;
    return ;
}
};
int main()
{
NewBook book1,book2,book3,book4,book5;
NewBook book6, book7, book8, book9, book10, book11, book12, book13, book14, book15, 
book16, book17, book18, book19, book20;
NewBook arr[15] = { book6, book7, book8, book9, book10, book11, book12, book13, book14, 
book15, book16, book17, book18, book19, book20 };
book1.mybook("a short history of nearly everything", "educational", "02/04/2003","Bill 
Bryson",10);
book2.mybook("sapiens","educational","2011", "Yuval Noah Harari",12);
book3.mybook("The 4-hour work week","self-improvement","2007","Tim Ferris",15);
book4.mybook("atomic habits","self-improvement","10/16/2018","James Clear",13);
book5.mybook("Harry Potter Collection", "Novel", "2001-2009", "J.K Rowling", 35);
...
case 2:
        cout << "to add a new book, just enter it's name, type , the author, the year 
and it's price"<<endl;
        cout << "this is a small library so it can only hold 20 books so far, we only 
have 5 so don't go overboard ok?"<<endl;
        arr[0].getline("");

0 Answers0