Click here to Skip to main content
15,905,028 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Accelerated C++ --Exercise 8-5:

Re-implement the gen_sentence and xref functions from Chapter 7 to use output iterators rather than putting their output in one data structure. Test these new versions by writing programs that attach the output iterator directly to the standard output, and by storing the results in a list and a map, respectively.


not looking for the solutions, but struggling with the wording of this exercise, extending/correcting my to-do-list would be helpful..the use of the word respectively is the confusing part


to-do-list:

Modify gen_sentence() to use a output iterator instead of returning a data struct.
Modify xref() to use a output iterator instead of returning a data struct.
Test driver that attaches gen_sentence()-->Out to std::cout.
Test driver that attaches xref()-->Out to std::cout.
....
....
....
....
....
Posted

1 solution

>>the use of the word respectively is the confusing part
Create several solutions/programs leveraging your output iterator:
1. program uses output iterator to write directly to the standard output
2. program uses output iterator to store the results in a list
3. program uses output iterator to store the results in a map

Hope this clarifies what is meant by respectively

Regards
Espen Harlinn
 
Share this answer
 
Comments
tukbriz 10-Apr-11 7:18am    
thanks for reply Espen, but can you be more specific, results from which function? ..or is it both?

have a look at the usage examples here first:
dictionary.reference.com/browse/respectively
Espen Harlinn 10-Apr-11 7:33am    
Pretty hard to answer without looking at the book :) - but this is what you usually are expected to do when working on exercises. Things are often kept simple and to the point. When you have created three separete programs, using a similar structure, combining them into a single solution/program should be quite simple ...
tukbriz 10-Apr-11 7:32am    
edit: link to page in book bbqsrc.net/acceleratedc++/48.htm ..go with the question wording in my post as the errata has been updated since..but the link provides context good enough

is this what you mean?:

Modify gen_sentence() to use a output iterator instead of returning a data struct.
Test driver: gen_sentence()-->Out-->std::cout.
Test driver: gen_sentence()-->Out-->List.
Test driver: gen_sentence()-->Out-->Map.

Modify xref() to use a output iterator instead of returning a data struct.
Test driver: xref()-->Out-->std::cout.
Test driver: xref()-->Out-->List.
Test driver: xref()-->Out-->Map.
Espen Harlinn 10-Apr-11 7:47am    
Assuming gen_sentence() returns an output_iterator_t:

std::out << gen_sentence();
myMapType map;
map << gen_sentence();
myListType list;
list << gen_sentence();

ostream &operator<<( std::ostream &out, output_iterator_t &it ) {
// do you stuff - i.e.
output_iterator_t::value_type& v = *it;
out << v;
return out;
}

myMapType& operator<<( myMapType& map, output_iterator& it ) {
// do you stuff
return map;
}

or something similar :) as I don't have the book, I'm kind of guessing at what you want/need.
Sandeep Mewara 10-Apr-11 11:57am    
My 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900