Write a class declaration for a class called Library that has the following private members:
mBooks, a pointer to an array of Book structures.
mCapacity, the maximum number of books that can be stored in the library.
mNumBooks, the actual number of books in the library.
allocate, a void member function that allocates the array.
deallocate, a void member function that deallocates the array.
copy, a void member function that takes another Library object by constant reference, and copies the contents of its array into the array of the object it is called on.
Asked
Active
Viewed 54 times
-5

Remy Lebeau
- 555,201
- 31
- 458
- 770

user13118554
- 3
- 1
-
5it seems you were absent in class when functions and methods were taught :) – Nikos M. May 04 '20 at 22:10
-
First complete your exercises. SA is not for your homework. Complete your lessons first. – executable May 04 '20 at 22:15
-
It seems people are forgetting the title (which should be asked in the actual question), but if this is for school, I'd suggest asking the instructor for clarification because you can be sure you'll get the correct intent. – chris May 04 '20 at 22:17
-
The grammar on that last item is a mess. but is sounds like you want to assign the data in an object given as a parameter to the method to the object. Left to my own devices, I would implement this with a copy constructor, an assignment operator implemented with the [Copy and Swap idiom](https://stackoverflow.com/questions/3279543/what-is-the-copy-and-swap-idiom), and then use the assignment operator in the `copy` method. This will make the class far more useful in the long run as it has almost implemented the [Rule of Three](https://en.cppreference.com/w/cpp/language/rule_of_three) – user4581301 May 04 '20 at 22:25
1 Answers
0
Let's take the item 6
6 copy, a void member function that takes another Library object by constant reference, and copies the contents of its array into the array of the object it is called on.
and look at it piece by piece.
copy, a void member function
The function name is "copy" and returns void:
void copy()
{
}
that takes another Library object by constant reference
We'll deduce that the term "member" function means that the function is a member of some class. In the above phrase, the likely name is Library
.
Here is function thus far:
class Library
{
public:
void copy(const Library& other_library_to_copy);
};
The const Library&
denotes that the parameter will be passed by reference.
Hope this helps.

Thomas Matthews
- 56,849
- 17
- 98
- 154
-
"*However, we are missing the capacity of the array, which would tell us how much to copy ... Also, there is no type associated with the array*" - Those details are covered by items 1, 2, and 3 of the instructions. So, there is nothing to make up, the instructions tell you exactly what is present. So change `array_of_something` to `mBooks`, and change `ARRAY_CAPACITY` to `library_to_copy.mNumBooks`, and be sure to update `this->mNumBooks` after the copy is finished. Also, `copy()` will likely have to call `this->allocate()` if `this->mCapacity < library_to_copy.mNumBooks` – Remy Lebeau May 05 '20 at 00:26
-
-