Please help with classes

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<iostream>
#include<string>
using namespace 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;
}
1
2
	void setBook(string b[5])
	{book = b[5];}


1
2
book[x].setBook; //What are you setting it to?
book[x].setBook(bk);


Set pages are handled similary: you read int into temporary variable and pass it to setPages member function.
I got a fatal error after making the changes. this is my code.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<iostream>
#include<string>
using namespace 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;
}
Post exact error here.
Also you didn't set pg anywhere.
Topic archived. No new replies allowed.