rAgAv wrote:
[color=blue]
>
> Kai-Uwe Bux wrote:[color=green]
>> W Marsh wrote:
>>[color=darkred]
>> > On 26 Mar 2006 06:13:26 -0800,
ragav.payne@googlemail.com wrote:
>> >
>> >> Here's my problem, i need to do a c++ program for my project at
>> >>school using structures. All my friends have submitted theirs and no
>> >>two should have the same project. jus' gi mme an out of the box idea
>> >>please. i can do with writing the source code.
>> >
>> > Here's a good structure:
>> >
>> > struct empty
>> > {
>> > };[/color]
>>
>> In order to make this more useful, you should provide a better interface.
>> This is what I use:
>>
>> struct empty {};
>>
>> std::ostream & operator<< ( std::ostream & ostr, empty const & e ) {
>> return( ostr << '#' );
>> }
>>
>> std::istream & operator>> ( std::istream & istr, empty & e ) {
>> char chr;
>> istr >> chr;
>> if ( chr != '#' ) {
>> istr.setstate( std::ios_base::failbit );
>> }
>> return( istr );
>> }
>>
>> bool operator== ( empty a, empty b ) {
>> return( true );
>> }
>>
>> bool operator!= ( empty a, empty b ) {
>> return( false );
>> }
>>
>> bool operator< ( empty a, empty b ) {
>> return( false );
>> }
>>
>> bool operator<= ( empty a, empty b ) {
>> return( true );
>> }
>>
>> bool operator> ( empty a, empty b ) {
>> return( false );
>> }
>>
>> bool operator>= ( empty a, empty b ) {
>> return( true );
>> }
>>
>>
>> Best
>>
>> Kai-Uwe Bux[/color]
>
>
> nice try dude!
>
> Well a program with structure is something which everybody can do but,
> wat i need to do is a program which can be used in real life, not just
> something which returns true/ false[/color]
You may fail to see the significance, however, the code above is directly
copied from my library and has proved to be useful in the past. I leave it
up to your imagination (or your skillful use of Google) to figure out why
you may want a class like this.
As for something you might try: implement a box-container (also something
that proved useful in my library; and I know it can be done with a
reasonable amount of effort):
Specifications:
template < typename T >
class box;
A box can be empty or contain an element of type T. Boxes are default
constructible (yielding the empty box), copy-constructible, assignable.
Also, comparisons for boxes are defined:
the empty box is greater than any non-empty box.
non-empty boxes compare according to content.
Finally, box<T> has members:
bool empty () const; // returns true if the box is empty.
T & item (); // returns a handle to the contents.
T const & item () const; // returns a handle to the contents.
void clear(); // empties the box.
void put ( T const & t ); // puts a copy of t into the box.
box<T> ( T const & t ); // construct a box containing a copy of t.
Maybe that qualifies as an "out of the box idea".
Best
Kai-Uwe Bux