Any c++ pros out there?

Discussion in 'C++' started by ragav.payne@googlemail.com, Mar 26, 2006.

  1. Guest

    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.
    , Mar 26, 2006
    #1
    1. Advertising

  2. W Marsh Guest

    On 26 Mar 2006 06:13:26 -0800, 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
    {
    };
    W Marsh, Mar 26, 2006
    #2
    1. Advertising

  3. Rolf Magnus Guest

    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.


    Maybe you should go to your professor to get some inspiration. From my
    experience they are usually willing to give you that kind of help.
    For people in the newsgroup, it's a bit hard to give you some suggestions,
    because you didn't say how much time is planned, if you're doing it alone
    or in a group and whether you may (or even must?) use some external
    libraries.
    Rolf Magnus, Mar 26, 2006
    #3
  4. Kai-Uwe Bux Guest

    W Marsh wrote:

    > On 26 Mar 2006 06:13:26 -0800, 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
    > {
    > };


    In order to make this more useful, you should provide a better interface.
    This is what I use:

    struct empty {};

    std::eek:stream & operator<< ( std::eek:stream & 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
    Kai-Uwe Bux, Mar 26, 2006
    #4
  5. Guest

    Rolf Magnus wrote:
    > 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.

    >
    > Maybe you should go to your professor to get some inspiration. From my
    > experience they are usually willing to give you that kind of help.
    > For people in the newsgroup, it's a bit hard to give you some suggestions,
    > because you didn't say how much time is planned, if you're doing it alone
    > or in a group and whether you may (or even must?) use some external
    > libraries


    Actually this is a group(max 4) project and has to be completed within
    end of may.
    all my friends have already proposed their ideas to the prof. and as
    there should'nt be any repetition everybody has to get an unusual idea.

    i did my part really well. i went to her and told about a program which
    would accept a sentence and give an output of the same sentence in
    morse code(using different delay times in the frequencies) but
    unfortunately someone had proposed the idea earlier, that just kept me
    wondering whether i could get another idea such as that.
    please help!!!!
    , Mar 26, 2006
    #5
  6. rAgAv Guest

    Kai-Uwe Bux wrote:
    > W Marsh wrote:
    >
    > > On 26 Mar 2006 06:13:26 -0800, 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
    > > {
    > > };

    >
    > In order to make this more useful, you should provide a better interface.
    > This is what I use:
    >
    > struct empty {};
    >
    > std::eek:stream & operator<< ( std::eek:stream & 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



    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
    rAgAv, Mar 26, 2006
    #6
  7. Daniel T. Guest

    In article <>,
    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.


    So you need an interesting problem that can be done in about a month by
    four beginners?

    How about one of the exorcises from Bjarne Stroustrup's book?

    Exorcise 2 from section 12.7 should be quite interesting.


    --
    Magic depends on tradition and belief. It does not welcome observation,
    nor does it profit by experiment. On the other hand, science is based
    on experience; it is open to correction by observation and experiment.
    Daniel T., Mar 26, 2006
    #7
  8. Kai-Uwe Bux Guest

    rAgAv wrote:

    >
    > Kai-Uwe Bux wrote:
    >> W Marsh wrote:
    >>
    >> > On 26 Mar 2006 06:13:26 -0800, 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
    >> > {
    >> > };

    >>
    >> In order to make this more useful, you should provide a better interface.
    >> This is what I use:
    >>
    >> struct empty {};
    >>
    >> std::eek:stream & operator<< ( std::eek:stream & 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

    >
    >
    > 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


    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
    Kai-Uwe Bux, Mar 26, 2006
    #8
  9. wrote:
    -snip-

    > i did my part really well. i went to her and told about a program which
    > would accept a sentence and give an output of the same sentence in
    > morse code(using different delay times in the frequencies) but
    > unfortunately someone had proposed the idea earlier, that just kept me
    > wondering whether i could get another idea such as that.
    > please help!!!!


    Then make a program that converts morse code back again to something
    understandable.


    Best regards / Med venlig hilsen
    Martin Jørgensen

    --
    ---------------------------------------------------------------------------
    Home of Martin Jørgensen - http://www.martinjoergensen.dk
    =?ISO-8859-1?Q?Martin_J=F8rgensen?=, Mar 27, 2006
    #9
  10. Ben Pope Guest

    Daniel T. wrote:
    >
    > How about one of the exorcises from Bjarne Stroustrup's book?


    Do you think C++ could save Emily Rose? ;)

    Ben Pope
    --
    I'm not just a number. To many, I'm known as a string...
    Ben Pope, Mar 27, 2006
    #10
  11. >> How about one of the exorcises from Bjarne Stroustrup's book?
    >
    > Do you think C++ could save Emily Rose? ;)


    #define EXORCISM(x) ((void)0)

    Patrick
    Patrick Kowalzick, Mar 27, 2006
    #11
  12. In message <e069s6$48e$>, Kai-Uwe Bux
    <> writes
    >W Marsh wrote:
    >
    >> On 26 Mar 2006 06:13:26 -0800, 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
    >> {
    >> };

    >
    >In order to make this more useful, you should provide a better interface.
    >This is what I use:
    >
    > struct empty {};
    >
    > std::eek:stream & operator<< ( std::eek:stream & 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 );
    > }
    >

    You could remove the need for a few of the above by judicious use of

    #include <utility>
    using namespace rel_ops;

    ;-)

    --
    Richard Herring
    Richard Herring, Mar 29, 2006
    #12
  13. rAgAv Guest

    Martin Jørgensen wrote:
    > wrote:
    > -snip-
    >
    > > i did my part really well. i went to her and told about a program which
    > > would accept a sentence and give an output of the same sentence in
    > > morse code(using different delay times in the frequencies) but
    > > unfortunately someone had proposed the idea earlier, that just kept me
    > > wondering whether i could get another idea such as that.
    > > please help!!!!

    >
    > Then make a program that converts morse code back again to something
    > understandable.


    C'mon man how will you ever input a *morse code* in ur black screen,
    gone crazy or wat!!!!!!?
    I'd recommand a tutorial in c++ for u.
    rAgAv, Apr 6, 2006
    #13
  14. Marco Costa Guest

    My god, I found this thread VERY funny. I apologize for that. =)
    Marco Costa, Apr 6, 2006
    #14
  15. Alex Buell Guest

    On Sun, 26 Mar 2006 14:00:41 -0500 Kai-Uwe Bux <>
    waved a wand and this message magically appeared:

    > 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".


    Out of sheer boredom, I put this one together:
    #include <iostream>

    template <typename T>
    class Box
    {
    public:
    Box();

    bool empty() const;
    T& item();
    T const& item() const;
    void clear();
    void put(T const& t);

    private:
    T object;
    };

    template <typename T>
    Box<T>::Box()
    {
    object = T();
    }

    template <typename T>
    bool Box<T>::empty() const
    {
    if (object.size() > 0)
    return false;

    return true;
    }

    template <typename T>
    T& Box<T>::item()
    {
    return object;
    }

    template <typename T>
    T const& Box<T>::item() const
    {
    return object;
    }

    template <typename T>
    void Box<T>::clear()
    {
    object = T();
    }

    template <typename T>
    void Box<T>::put(T const& t)
    {
    object = t;
    }

    int main()
    {
    Box<std::string> box;

    box.put("cat");

    if (box.empty())
    std::cout << "Box is empty!" << std::endl;
    else
    std::cout << "Cat scratches you on the arm!" <<
    std::endl;

    return 0;
    }



    --
    http://www.munted.org.uk

    Take a nap, it saves lives.
    Alex Buell, Apr 6, 2006
    #15
  16. REH Guest

    rAgAv wrote:
    > C'mon man how will you ever input a *morse code* in ur black screen,
    > gone crazy or wat!!!!!!?
    > I'd recommand a tutorial in c++ for u.


    di-di-di-dah-dah-dah-di-di-dit


    REH
    REH, Apr 6, 2006
    #16
  17. REH wrote:
    > rAgAv wrote:
    >> C'mon man how will you ever input a *morse code* in ur black screen,
    >> gone crazy or wat!!!!!!?
    >> I'd recommand a tutorial in c++ for u.

    >
    > di-di-di-dah-dah-dah-di-di-dit


    I thought it was

    pip-pip-pip-PEEP-PEEP-PEEP-pip-pip-pip

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Apr 6, 2006
    #17
  18. Marcus Kwok Guest

    Victor Bazarov <> wrote:
    > REH wrote:
    >> rAgAv wrote:
    >>> C'mon man how will you ever input a *morse code* in ur black screen,
    >>> gone crazy or wat!!!!!!?
    >>> I'd recommand a tutorial in c++ for u.

    >>
    >> di-di-di-dah-dah-dah-di-di-dit

    >
    > I thought it was
    >
    > pip-pip-pip-PEEP-PEEP-PEEP-pip-pip-pip


    Well, according to http://en.wikipedia.org/wiki/Morse_code , it's dit's
    and dah's, but now we're starting to get OT.

    A little bit closer to topicality, there is an obfuscated C program that
    can translate both to and from Morse code on the IOCCC page (look for
    the 1998 entry by dorssel: http://www.ioccc.org/years-spoiler.html#1998 )

    --
    Marcus Kwok
    Marcus Kwok, Apr 6, 2006
    #18
  19. REH Guest

    REH, Apr 6, 2006
    #19
  20. Kai-Uwe Bux Guest

    Alex Buell wrote:

    > On Sun, 26 Mar 2006 14:00:41 -0500 Kai-Uwe Bux <>
    > waved a wand and this message magically appeared:
    >
    >> 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".

    >
    > Out of sheer boredom, I put this one together:
    > #include <iostream>
    >
    > template <typename T>
    > class Box
    > {
    > public:
    > Box();
    >
    > bool empty() const;
    > T& item();
    > T const& item() const;
    > void clear();
    > void put(T const& t);
    >
    > private:
    > T object;
    > };
    >
    > template <typename T>
    > Box<T>::Box()
    > {
    > object = T();
    > }
    >
    > template <typename T>
    > bool Box<T>::empty() const
    > {
    > if (object.size() > 0)
    > return false;
    >
    > return true;
    > }
    >
    > template <typename T>
    > T& Box<T>::item()
    > {
    > return object;
    > }
    >
    > template <typename T>
    > T const& Box<T>::item() const
    > {
    > return object;
    > }
    >
    > template <typename T>
    > void Box<T>::clear()
    > {
    > object = T();
    > }
    >
    > template <typename T>
    > void Box<T>::put(T const& t)
    > {
    > object = t;
    > }
    >
    > int main()
    > {
    > Box<std::string> box;
    >
    > box.put("cat");
    >
    > if (box.empty())
    > std::cout << "Box is empty!" << std::endl;
    > else
    > std::cout << "Cat scratches you on the arm!" <<
    > std::endl;
    >
    > return 0;
    > }


    Your solution does not distinguish an empty box<T> from a box that contains
    the default value for T, i.e., a box<int> that contains 0 is considered
    empty.


    Best

    Kai-Uwe Bux
    Kai-Uwe Bux, Apr 7, 2006
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Danno
    Replies:
    2
    Views:
    1,084
    Danno
    Apr 26, 2006
  2. David Stockwell
    Replies:
    2
    Views:
    543
    Grant Edwards
    Jun 8, 2004
  3. Stef Mientki
    Replies:
    4
    Views:
    929
    Dennis Lee Bieber
    Sep 9, 2010
  4. Eric Danstron

    Are there ANY good forums out there anymore???

    Eric Danstron, Sep 21, 2005, in forum: ASP General
    Replies:
    1
    Views:
    147
    Immediacy
    Sep 22, 2005
  5. Gennady
    Replies:
    0
    Views:
    86
    Gennady
    Jul 31, 2003
Loading...

Share This Page