Any c++ pros out there?

R

ragav.payne

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

W Marsh

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
{
};
 
R

Rolf Magnus

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

Kai-Uwe Bux

W said:
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
 
R

ragav.payne

Rolf said:
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!!!!
 
R

rAgAv

Kai-Uwe Bux said:
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
 
D

Daniel T.

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

Kai-Uwe Bux

rAgAv said:
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
 
?

=?ISO-8859-1?Q?Martin_J=F8rgensen?=

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
 
R

Richard Herring

Kai-Uwe Bux said:
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;

;-)
 
R

rAgAv

Martin said:
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.
 
A

Alex Buell

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;
}
 
R

REH

rAgAv said:
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
 
K

Kai-Uwe Bux

Alex said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top