Sorry mate, I can't give you the entire program... for 2 reasons: 1. I haven't written it, and 2: it's for your homework - you have to do it to learn!
But to help you in your learning... use this site! :) There are examples on most pages which can help you learn.
std::list is a doubly linked list:
http://www.cplusplus.com/reference/stl/list/
to add items to your list, call push_back:
http://www.cplusplus.com/reference/stl/list/push_back/
how to sort your list once you've populated it:
http://www.cplusplus.com/reference/stl/list/sort/
to search for values in a sorted range (which is what your list becomes once you've sorted it), use the algorithm std::equal_range:
http://www.cplusplus.com/reference/algorithm/equal_range/
note: equal range will return a pair of iterators delimiting a range of values which match your search criteria. If you have only 1 item whose value matches, the 2 iterators in the returned pair will be the same.
to print the items matching your search criteria, use std::for_each with a function/functor that prints the members of your graphics as you wish:
http://www.cplusplus.com/reference/algorithm/for_each/
note: you will have to sort twice - once by area, and again by shape. Once it's sorted by shape you can then call equal_range and for_each to print the items which match the searched for shape.
If you don't want to sort by shape, you could just combine two algorithms, for_each and find_if.
http://www.cplusplus.com/reference/algorithm/find_if/
something like this will get you each graphics item which matches a shape:
1 2 3 4 5
|
std::for_each(std::find_if(graphics_list.begin(),
graphics_list.end(),
shape_is("SQUARE")),
graphics_list.end(),
print_graphics_item());
| |
shape_is is a functor whose constructor takes a parameter (the shape you want to search for) and has:
bool operator()(const graphics& item)
which checks to see if the item's shape matches the one you passed to the constructor
print_graphics_item is a functor which has:
void operator()(const graphics& item)
which prints your item
There is a forum post on here relating to functors:
http://www.cplusplus.com/forum/general/12793/
If you want more information about the stl, a very general overview can be found on wikipedia:
http://en.wikipedia.org/wiki/C%2B%2B_Standard_Library