Any c++ pros out there? 
March 26th, 2006, 02:25 PM
| | | |
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. | 
March 26th, 2006, 02:35 PM
| | | | 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
{
}; | 
March 26th, 2006, 02:55 PM
| | | | 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. | 
March 26th, 2006, 03:05 PM
| | | | 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!!!! | 
March 26th, 2006, 03:15 PM
| | | | 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 | 
March 26th, 2006, 03:15 PM
| | | | 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 | 
March 26th, 2006, 05:55 PM
| | | | 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. | 
March 26th, 2006, 07:25 PM
| | | | 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 | 
March 26th, 2006, 11:55 PM
| | | | 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 | 
March 27th, 2006, 11:05 AM
| | | | 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... | 
March 27th, 2006, 11:35 AM
| | | | 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 | 
March 29th, 2006, 12:55 PM
| | | | 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 | 
April 6th, 2006, 03:15 PM
| | | | 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. | 
April 6th, 2006, 03:45 PM
| | | | re: Any c++ pros out there?
My god, I found this thread VERY funny. I apologize for that. =) | 
April 6th, 2006, 04:55 PM
| | | | 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. | 
April 6th, 2006, 05:35 PM
| | | | 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 | 
April 6th, 2006, 06:45 PM
| | | | 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 | 
April 6th, 2006, 07:05 PM
| | | | 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 | 
April 7th, 2006, 04:45 AM
| | | | 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 | 
April 7th, 2006, 05:05 AM
| | | | 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!!! | 
April 7th, 2006, 05:25 AM
| | | | 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 | 
April 7th, 2006, 10:45 AM
| | | | 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!!!! |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,689 network members.
|