• Advertisement
Sign in to follow this  

Programming Practice

This topic is 4226 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm going through the 'Learn C++ in 21 Days' book (although I've already read most of it, am reading again to really understand C++). The problem is there aren't really any of those great problems you find in other texts like: Susie needs a program that will take two int's and return the product and difference. Anyone know a website with problems like this? If not, anyone have any easy ones? lol

Share this post


Link to post
Share on other sites
Advertisement
After you are done with those 'simple' problems and exercises, try to making some 'difficult' and more interesting programs like simple calculators. You immediatly have to put all your knowledge to work, which is a great learning way.

After I created multiple calculators, I continued with a fantasy name generator, followed by a very simple file editor. Once you get the hang of it you can do bigger programs.

When you start with bigger programs, you should first make a flow chart to gain overhead.

You will also encounter a lot of frustrations trying to compile your source codes, believe me this is normal, as long you don't give up. Once you get a year or two experience with the language, syntax error become more rare.

Well, this might all seems so far away or way to difficult, but it are small steps to greater wisdom.

Hope this helps,

Regards,

Xeile

Share this post


Link to post
Share on other sites
Quote:
Original post by Xeile
After you are done with those 'simple' problems and exercises, try to making some 'difficult' and more interesting programs like simple calculators. You immediatly have to put all your knowledge to work, which is a great learning way.

After I created multiple calculators, I continued with a fantasy name generator, followed by a very simple file editor. Once you get the hang of it you can do bigger programs.

When you start with bigger programs, you should first make a flow chart to gain overhead.

You will also encounter a lot of frustrations trying to compile your source codes, believe me this is normal, as long you don't give up. Once you get a year or two experience with the language, syntax error become more rare.

Well, this might all seems so far away or way to difficult, but it are small steps to greater wisdom.

Hope this helps,

Regards,

Xeile


This is about the same way I started. But, calculators may not be your real interest. Think back to several of the times when you were programming or learning, and you thought, "Hey, wouldn't be really helpful just to make this function/small program to do this task?" Start off with that. Add on to it, make it cool. Then move onto something else. I find that you get a lot more motivation and tend to stick to coding more if you do something YOU want to do.

Share this post


Link to post
Share on other sites
I went up-north this last weekend and wanted to try my hand at one of those fancy text based adventure games. I never realized there really isn't a built-in String function. I'm used to C# and Java and the like already having them. To me it seemed like C++ needed you to build one for it. Is this idea wrong? (I had a start menu that would do different things depending on an int that was pressed ex(1 - New Game, 2-About, 3-Exit)

Share this post


Link to post
Share on other sites
Quote:
Original post by programmermattc
I went up-north this last weekend and wanted to try my hand at one of those fancy text based adventure games. I never realized there really isn't a built-in String function. I'm used to C# and Java and the like already having them. To me it seemed like C++ needed you to build one for it. Is this idea wrong? (I had a start menu that would do different things depending on an int that was pressed ex(1 - New Game, 2-About, 3-Exit)


You mean string /type/? See C++'s std::string, part of the standard library. Associations are simple enough with std::map, and stored actions with boost::function (which if not officially part of the standard, is it's spiritual extension for me and others)

class some_menu {
typedef std::map< int , boost::function< void () > > actions_map_type;
actions_map_type actions;
public:
some_menu() {
actions[ 1 ] = boost::bind( & some_menu::do_new_game , this );
actions[ 2 ] = boost::bind( & some_menu::do_about , this );
actions[ 3 ] = boost::bind( & some_menu::do_exit , this );
}
private:
void run( int menu_item ) {
actions_map_type::iterator action = actions.find( menu_item );
if ( action == actions.end() ) throw std::runtime_error( "Menu item dosn't exist" );
else (*action)();
}

void do_new_game() { ... }
void do_about() { ... }
void do_exit() { ... }

...
};




Further reading:

[boost] website: http://boost.org/
MSDN standard library reference: http://msdn2.microsoft.com/en-us/library/cscc687y.aspx

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement