Re: Help needed with class BookType
Quote:
Originally Posted by
owllie
Hi Lindley,
I wrote the requirements for the question in a separate post.
"Customer lists are stored using a vector class. Book lists are also stored using a vector class. You must write your own vector class to be used in exercise 7. There must be only one vector class. Note that means you can have as many vector object as you need but there is only one vector class. STL data strctures cannot be used in this assignment."
thanks
Okay, so basically they're asking you to reinvent the std::vector class rather than using the existing one, so that you learn how it works internally.
Therefore, your class should have an interface which is largely similar to std::vector. Take a look at the interface here:
http://www.cplusplus.com/reference/stl/vector/
Of course you do not need to support every method shown there, but a decent subset of them will be necessary.
For the purposes of creating this vector class, you can forget all about Book objects; they aren't relevant.
Re: Help needed with class BookType
Sorry for being blunt.. In order to store the data how should I go about it?
Using the insert method?
Re: Help needed with class BookType
Quote:
Originally Posted by
owllie
Sorry for being blunt.. In order to store the data how should I go about it?
Using the insert method?
Objects are usually copied into a vector using either insert() or push_back(). You can implement one of these or both. The push_back method is simpler but less flexible.
Re: Help needed with class BookType
How to write the code for both insert and push back method.? Any examples?
Thanks
Re: Help needed with class BookType
Your teacher wouldn't have assigned a project to create a vector class without first introducing you to the basics of dynamic array handling. Check your book and notes.
In general, the pseudocode will look like:
Code:
IF the array is full (size == capacity)
REALLOCATE and COPY existing items
COPY new item to end of array
INCREASE array size by 1
Re: Help needed with class BookType
Quote:
Originally Posted by
Lindley
Your teacher wouldn't have assigned a project to create a vector class without first introducing you to the basics of dynamic array handling. Check your book and notes.
In general, the pseudocode will look like:
Code:
IF the array is full (size == capacity)
REALLOCATE and COPY existing items
COPY new item to end of array
INCREASE array size by 1
we have yet to touch on dynamic array.. so everything is kinda rush.
what you meant by the capacity?
I need to declare another variable for capacity?
I know the copy I can use the copy constructor right?
for reallocating, does that mean i will be using the assignment constructor?
thanks.
Re: Help needed with class BookType
Quote:
Originally Posted by
owllie
we have yet to touch on dynamic array.. so everything is kinda rush.
what you meant by the capacity?
I need to declare another variable for capacity?
I know the copy I can use the copy constructor right?
for reallocating, does that mean i will be using the assignment constructor?
thanks.
First of all, this site can help with places you get stuck, but it can't take the place of a good book or class.
Second of all, you're not ready to even think about coding till you understand in your head what your "vector" is, what functionality it has to have and how you would go about implementing that functionality. Write the steps down and understand them in English or pseudocode before you even think about C++.
Third, I don't believe that you have shared with us all your project requirements. It's not likely your prof would just tell you to use a vector without explaining what they are and how they work. It's not even clear from what you've said if he wants you to implement the basic functionality of an STL vector or he's using the term to mean something similar or even unrelated.