SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,kenrick Mock
Chapter:
Standard Template Library
Exercise:
Programming Projects
Question:1 | ISBN:9780132846813 | Edition: 5

Question

The point of this exercise is to demonstrate that an object that behaves like an iterator is an iterator. More precisely, if an object accesses some container and behaves like an iterator of a particular strength, then that object can be used as an iterator to manipulate the container with any of the generic functions that require an iterator having that strength. However, while the generic algorithms can be used with this container, the member functions, such as begin and end, will (of course) not be present (for example, in an array) unless they have been explicitly coded for that container. We will restrict this exercise to arrays of double, but the same message would hold true for any base type.

a. Argue from the properties of random-access iterators that a pointer that points to an element of an array behaves exactly as a random-access iterator.

b. Argue further that

i) the name of the array is a pointer to double that points to the first

element and so the array name can serve as a “begin” iterator and

ii) (the array’s name) + (the size of the array) can serve as an “end”

pointer. (Of course, this points one past the end, as it should.)

c. Write a short program in which you declare an array of double of size 10, and populate this array with 10 double s. Then call the sort generic algorithm with these pointer values as arguments and display the results.


TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Sorry the answer is not available at the moment…

If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.

Spread the 'tradition of sharing'.