Zazabazulla 0 Newbie Poster
#include <iostream>
#include <list>
#include <string>
using namespace std;



// prototype for function template printList
template < typename T > void printList( const std::list< T > &listRef );

class NumberOfPersons
{
private:
	int numberOfPersons;
public:
	NumberOfPersons(int person);
	int getNumberOfPersons();
};
NumberOfPersons::NumberOfPersons(int person)
{
	numberOfPersons = person;
}
int NumberOfPersons::getNumberOfPersons()
{
	return numberOfPersons;
}

class Book
{
private:
	string bookTitle;
public:
	NumberOfPersons NumberOfPersons;
	Book(string enterTitle);
	string getBook();
	void setNumberOfPersons(NumberOfPersons setNumberOfPersons);
	NumberOfPersons getNumberOfPersons();
};
Book::Book(string enterTitle)
{
	bookTitle = enterTitle;
}

string Book::getBook()
{
	return BookTitle;
}
void Book::setNumberOfPersons(NumberOfPersons setNumberOfPersons)
{
	NumberOfPersons = setNumberOfPersons;
}
NumberOfPersons Book::getNumberOfPersons()
{
	return NumberOfPersons;
}

class Library
{
private:
	string LibraryName;
public:
    list <string> Books; // list container for string elements
    //Book Book;
	Library(string libRef);
	void addBook(string Book);
	void removeBook(string Book);
};

Library::Library()
{
	LibraryName = libRef;
}
void Library::addBook(string Book)
{
	Books.push_back(Book);
}
void Library::removeBook(string Book)
{
	Books.remove(Book);
}

class City
{
public:
	list<string> library;
	
	void popList();
	void addLib (string enterLib);
	void removeLib (string enterLib);
	void showLib();
	void setBook();
};
void City::addLib(string enterLib)
{
	library.push_back(enterLib);
}
void City::removeLib(string enterLib)
{
	library.remove(enterLib);
}
void City::popList()
{
	library.push_back("Library1");
	library.push_back("Library2");
	library.push_back("Library3");
}
void City::showLib()
{
	printList(library);
	//printList(Book.BookTitle);
}

Given the above classes and their respective attributes + methods; how can I use OOP concepts to add a book (& the number of persons in the book) in a selected library. I have already programmed how to add/remove a library and works fine.
Also I would like to – given the book name, will list the library in which the book is present.

Ex:

Enter a book: Peter & Jane

Book is available in the following libraries:
Library 1
Library 2
Library 3

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.