Connecting Tech Pros Worldwide Help | Site Map

Any c++ pros out there?

  #1  
Old March 26th, 2006, 02:25 PM
ragav.payne@googlemail.com
Guest
 
Posts: n/a
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.

  #2  
Old March 26th, 2006, 02:35 PM
W Marsh
Guest
 
Posts: n/a

re: Any c++ pros out there?


On 26 Mar 2006 06:13:26 -0800, ragav.payne@googlemail.com wrote:
[color=blue]
> 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.[/color]

Here's a good structure:

struct empty
{
};
  #3  
Old March 26th, 2006, 02:55 PM
Rolf Magnus
Guest
 
Posts: n/a

re: Any c++ pros out there?


ragav.payne@googlemail.com wrote:
[color=blue]
> 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.[/color]

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.

  #4  
Old March 26th, 2006, 03:05 PM
ragav.payne@googlemail.com
Guest
 
Posts: n/a

re: Any c++ pros out there?



Rolf Magnus wrote:[color=blue]
> ragav.payne@googlemail.com wrote:
>[color=green]
> > 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.[/color]
>
> 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[/color]

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

  #5  
Old March 26th, 2006, 03:15 PM
Kai-Uwe Bux
Guest
 
Posts: n/a

re: Any c++ pros out there?


W Marsh wrote:
[color=blue]
> On 26 Mar 2006 06:13:26 -0800, ragav.payne@googlemail.com wrote:
>[color=green]
>> 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.[/color]
>
> 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
  #6  
Old March 26th, 2006, 03:15 PM
rAgAv
Guest
 
Posts: n/a

re: Any c++ pros out there?



Kai-Uwe Bux wrote:[color=blue]
> W Marsh wrote:
>[color=green]
> > On 26 Mar 2006 06:13:26 -0800, ragav.payne@googlemail.com wrote:
> >[color=darkred]
> >> 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.[/color]
> >
> > 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

  #7  
Old March 26th, 2006, 05:55 PM
Daniel T.
Guest
 
Posts: n/a

re: Any c++ pros out there?


In article <1143382406.685507.320880@z34g2000cwc.googlegroups .com>,
ragav.payne@googlemail.com wrote:
[color=blue]
> 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.[/color]

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.
  #8  
Old March 26th, 2006, 07:25 PM
Kai-Uwe Bux
Guest
 
Posts: n/a

re: Any c++ pros out there?


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
  #9  
Old March 26th, 2006, 11:55 PM
Martin Jørgensen
Guest
 
Posts: n/a

re: Any c++ pros out there?


ragav.payne@googlemail.com wrote:
-snip-
[color=blue]
> 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!!!![/color]

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
  #10  
Old March 27th, 2006, 11:05 AM
Ben Pope
Guest
 
Posts: n/a

re: Any c++ pros out there?


Daniel T. wrote:[color=blue]
>
> How about one of the exorcises from Bjarne Stroustrup's book?[/color]

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

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
  #11  
Old March 27th, 2006, 11:35 AM
Patrick Kowalzick
Guest
 
Posts: n/a

re: Any c++ pros out there?


>> How about one of the exorcises from Bjarne Stroustrup's book?[color=blue]
>
> Do you think C++ could save Emily Rose? ;)[/color]

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

Patrick


  #12  
Old March 29th, 2006, 12:55 PM
Richard Herring
Guest
 
Posts: n/a

re: Any c++ pros out there?


In message <e069s6$48e$1@murdoch.acc.Virginia.EDU>, Kai-Uwe Bux
<jkherciueh@gmx.net> writes[color=blue]
>W Marsh wrote:
>[color=green]
>> On 26 Mar 2006 06:13:26 -0800, ragav.payne@googlemail.com wrote:
>>[color=darkred]
>>> 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.[/color]
>>
>> 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 );
> }
>[/color]
You could remove the need for a few of the above by judicious use of

#include <utility>
using namespace rel_ops;

;-)

--
Richard Herring
  #13  
Old April 6th, 2006, 03:15 PM
rAgAv
Guest
 
Posts: n/a

re: Any c++ pros out there?



Martin Jørgensen wrote:[color=blue]
> ragav.payne@googlemail.com wrote:
> -snip-
>[color=green]
> > 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!!!![/color]
>
> Then make a program that converts morse code back again to something
> understandable.[/color]

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.

  #14  
Old April 6th, 2006, 03:45 PM
Marco Costa
Guest
 
Posts: n/a

re: Any c++ pros out there?


My god, I found this thread VERY funny. I apologize for that. =)

  #15  
Old April 6th, 2006, 04:55 PM
Alex Buell
Guest
 
Posts: n/a

re: Any c++ pros out there?


On Sun, 26 Mar 2006 14:00:41 -0500 Kai-Uwe Bux <jkherciueh@gmx.net>
waved a wand and this message magically appeared:
[color=blue]
> 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".[/color]

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.
  #16  
Old April 6th, 2006, 05:35 PM
REH
Guest
 
Posts: n/a

re: Any c++ pros out there?



rAgAv wrote:[color=blue]
> 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.[/color]

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


REH

  #17  
Old April 6th, 2006, 06:45 PM
Victor Bazarov
Guest
 
Posts: n/a

re: Any c++ pros out there?


REH wrote:[color=blue]
> rAgAv wrote:[color=green]
>> 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.[/color]
>
> di-di-di-dah-dah-dah-di-di-dit[/color]

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


  #18  
Old April 6th, 2006, 07:05 PM
Marcus Kwok
Guest
 
Posts: n/a

re: Any c++ pros out there?


Victor Bazarov <v.Abazarov@comacast.net> wrote:[color=blue]
> REH wrote:[color=green]
>> rAgAv wrote:[color=darkred]
>>> 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.[/color]
>>
>> di-di-di-dah-dah-dah-di-di-dit[/color]
>
> I thought it was
>
> pip-pip-pip-PEEP-PEEP-PEEP-pip-pip-pip[/color]

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
  #19  
Old April 6th, 2006, 08:15 PM
REH
Guest
 
Posts: n/a

re: Any c++ pros out there?



Marcus Kwok wrote:[color=blue]
> 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.
>
> Marcus Kwok[/color]

Only at the end of a sequence.

http://home.clara.net/rod.beavon/morse.htm

REH

  #20  
Old April 7th, 2006, 04:45 AM
Kai-Uwe Bux
Guest
 
Posts: n/a

re: Any c++ pros out there?


Alex Buell wrote:
[color=blue]
> On Sun, 26 Mar 2006 14:00:41 -0500 Kai-Uwe Bux <jkherciueh@gmx.net>
> waved a wand and this message magically appeared:
>[color=green]
>> 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".[/color]
>
> 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;
> }[/color]

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
  #21  
Old April 7th, 2006, 05:05 AM
Phlip
Guest
 
Posts: n/a

re: Any c++ pros out there?


Kai-Uwe Bux wrote:
[color=blue]
> 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.[/color]

I just tuned in. Are you guys reinventing Barton & Nackman's Fallible<T>
from their Scientific and Engineering Something C++ book?

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!


  #22  
Old April 7th, 2006, 05:25 AM
Kai-Uwe Bux
Guest
 
Posts: n/a

re: Any c++ pros out there?


Phlip wrote:
[color=blue]
> Kai-Uwe Bux wrote:
>[color=green]
>> 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.[/color]
>
> I just tuned in. Are you guys reinventing Barton & Nackman's Fallible<T>
> from their Scientific and Engineering Something C++ book?[/color]

I don't know. What does that thing do?


Best

Kai-Uwe Bux
  #23  
Old April 7th, 2006, 10:45 AM
rAgAv
Guest
 
Posts: n/a

re: Any c++ pros out there?



Marco Costa wrote:[color=blue]
> My god, I found this thread VERY funny. I apologize for that. =)[/color]

Not ur mistake. It IS funny!!!!

Closed Thread