wrote:
> The apvector.h is what we use for vectors because it has some checking
> in it (I'm not sure exactly what, the teacher said it was used for the
> pre-2004 AP computer Science course and the checks prevented a program
> from deleting the hard drive if you wrote an array wrong.) I am not
> using other functions because we have not learned how to make them (I
> do know how though), and the only libraries we have learned in class is
> iostream.h and the math.h and we just started vectors using the
> apvector.h.
>
> Thanks for the help though.
OK, your welcome.
Let me point out a few issues if you'll allow me.
issue #1 - length()
If the container has 5 elements then:
numbers[0] <- zero based index
numbers[1]
numbers[2]
numbers[3]
numbers[4] <- is the fifth element, count them, C++ is not VB
for( int i = 0; i < numbers.length(); ++i)
{
std::cout << numbers[i]; // <- from 0 to 4 = 5 elements
}
So the length() of the container is used as an upper limit. No length()
+1 or length() -1 should be seen in the code at all.
issue #2
Teaching iostream.h, amongst other ancient libraries, should be
strongly discouraged if not outlawed!
There is no excuse. None whatsoever. The header iostream.h is_not and
was_not ever part of C++.
issue#3
Considering the safety that a std::vector has its probably
nuclear-proof when compared to the apvector.h container. The std
containers are used in real, everyday commercial code because of their
safety, amongst other benefits.
Instead of:
std::cout << numbers[i];
you can have the std::vector carry out a range-check with:
std::cout << numbers.at(i);
Anyways, its so that you know. The above does implicate exception
checking.
I'ld kindly suggest reading the faq and consider getting a real book,
not any book.
http://www.parashift.com/c++-faq-lite/newbie.html