Apparently I've forgotten how to use classes. I am trying to input 5 different book names into a class along with each of the book's pages. I can't figure out how to put the values into the class. Please help.
#include<iostream>
#include<string>
usingnamespace std;
class Book
{private:
string book;
int pages;
public:
void setBook(string b[5])
{book = b[5];}
void setPages(int p)
{pages=p;}
string getBook();
int getPages();
void displayData();
};
string Book::getBook(){return book;}
int Book::getPages(){return pages;}
int main()
{
Book book[5];
string bk;
for(int x=0; x<5; x++)
{
cout<<"Please enter the name of the book: ";
cin>>bk;
book[x].setBook;
cout<<"Please enter the number of pages: ";
book[x].setPages;
cout<<endl<<endl;
}
return 0;
}
#include<iostream>
#include<string>
usingnamespace std;
class Book
{private:
string book;
int pages;
public:
void setBook(string b)
{book = b;}
void setPages(int p)
{pages=p;}
string getBook();
int getPages();
void displayData();
};
string Book::getBook(){return book;}
int Book::getPages(){return pages;}
int main()
{
Book book[5];
string bk;
int pg;
for(int x=0; x<5; x++)
{
cout<<"Please enter the name of the book: ";
cin>>bk;
book[x].setBook(bk);
cout<<"Please enter the number of pages: ";
book[x].setPages(pg);
cout<<endl<<endl;
}
return 0;
}