Last visit was: It is currently Fri Apr 19, 2024 4:51 pm


All times are UTC-05:00




Post new topic Reply to topic  [39 posts ] 
Author Message
 Post subject:Idea for a first project?
PostPosted:Tue Mar 11, 2008 5:03 pm 
User avatar
 

Joined:Thu Mar 06, 2008 4:32 am
Posts:53
Yahoo Messenger:sfericz
Location:Tennessee
I'm wanting to write my first complete C++ program, without veiwing any source. I know VB 6 very well and Im learning C++ to be able to edit my Uplink DevCD, and maybe create my own Game from scratch if I can catch on down the road.

What kind of program should i start with? Giving what I want to use C++ for.

_________________
start a riot...


Top
Offline  
 Post subject:Re: Idea for a first project?
PostPosted:Tue Mar 11, 2008 5:51 pm 
 

Joined:Sun Jun 10, 2007 11:41 am
Posts:344
Location:Ninjaville
An interesting (although rather difficult) program is to try and make a four function calculator.


Top
Offline  
 Post subject:Re: Idea for a first project?
PostPosted:Tue Mar 11, 2008 6:32 pm 
User avatar
 

Joined:Sun Feb 12, 2006 8:56 pm
Posts:1019
Website:http://eddieringle.com
Location:Detroit, MI
Or if you are into game programming, make a simple guessing game or small text adventure/rp game.

_________________
-- Eddie Ringle

Check out Elysian Shadows and consider backing us on Kickstarter!

====================================

Image


Top
Offline  
 Post subject:Re: Idea for a first project?
PostPosted:Tue Mar 11, 2008 8:06 pm 
Literally Nine
User avatar
 

Joined:Sat Apr 02, 2005 3:31 pm
Posts:1171
Location:The vicinity of an area adjacent to a location.
Well, I think the "Hello World" program nonsense is just bullshit. Don't bother with something so rudimentary. What I recommend is trying to write a prime number finder in whatever language you're intent on learning. I wrote a few versions of GenPrime in various languages (C, Perl, Java, Ada, PHP, Ruby). Not only is it a great start to learn the semantics of the language and so forth, but you also learn which languages generate faster-executing code.

Speaking of which, I was impressed with the speed of Ruby. It's much slower than C, but compared to PHP, Perl or Java, Ruby is fast.

_________________
- Tycho

Image


Top
Offline  
 Post subject:Re: Idea for a first project?
PostPosted:Tue Mar 11, 2008 8:35 pm 
User avatar
 

Joined:Thu Mar 06, 2008 4:32 am
Posts:53
Yahoo Messenger:sfericz
Location:Tennessee
Gwanky: Thanks for the suggestion, I'm researching some ways of doing that.

cpu5594: I remembered a game I made when i was 12 with Qbasic on my 386 computer. Im writting it right now in C++, and see if i can pull it off,I will post it and the source later tonight on my site if anyone wants to take a look at it.

Tycho: Would using switches be the fastest way to approach doing that, or just plain and simple endif's? (sadly I do not have much schooling, but I think i remember 2 is a prime, and only even, I think :? ..thats a start atleast, eh?

Also, I herd someone talk about Ruby that got me into VB, dont know anything about it really. I herd C++ Turbo is a good compiler to use. But im content with VS express, im getting use to how to do stuff in it.

_________________
start a riot...


Last edited by cOde.ZRY on Tue Mar 11, 2008 8:40 pm, edited 1 time in total.

Top
Offline  
 Post subject:Re: Idea for a first project?
PostPosted:Tue Mar 11, 2008 8:37 pm 
User avatar
 

Joined:Sun Feb 12, 2006 8:56 pm
Posts:1019
Website:http://eddieringle.com
Location:Detroit, MI
Tycho might not like this, but there's an entry in IO.IN's wiki about GenPrime.
http://www.ferrousmoon.com/wiki/index.php/GenPrime

_________________
-- Eddie Ringle

Check out Elysian Shadows and consider backing us on Kickstarter!

====================================

Image


Top
Offline  
 Post subject:Re: Idea for a first project?
PostPosted:Tue Mar 11, 2008 9:13 pm 
Literally Nine
User avatar
 

Joined:Sat Apr 02, 2005 3:31 pm
Posts:1171
Location:The vicinity of an area adjacent to a location.
Quote:
Tycho might not like this, but there's an entry in IO.IN's wiki about GenPrime.
http://www.ferrousmoon.com/wiki/index.php/GenPrime
I recommend against using the algorithms that article mentions. I've since improved the algorithm I used.

Here are the current versions (Ruby, C, and PHP listed here only, for now):

C
Code:
/* * GenPrime * * (c) 2006-2008 Steven Noonan. * Licensed under the New BSD License. * */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <memory.h> #include <sys/time.h> int isPrime ( unsigned long _candidate ) { unsigned long i, limit; /* 0 and 1 aren't prime. */ if ( _candidate < 2 ) return 0; /* All numbers less than 4 are prime, except '1' */ if ( _candidate < 4 ) return -1; /* Other than 2, even numbers are not prime */ if ( _candidate % 2 == 0 ) return 0; /* All primes are of the form 6k+i (where i = -1 or 1), except for 2 or 3. */ if ( ( _candidate + 1 ) % 6 != 0 && ( _candidate - 1 ) % 6 != 0 ) return 0; /* if n is composite then it can be factored into two values, at least one of which is less than or equal to sqrt(n) */ limit = (unsigned long)sqrt ((double)_candidate); /* Now test all other odd numbers up to sqrt(n) */ for ( i = 3; i <= limit; i += 2 ) if ( _candidate % i == 0 ) return 0; return 1; } unsigned long genPrime ( unsigned long _maxToFind ) { unsigned long count = 0, num; for ( num = 1; count < _maxToFind; num++ ) { if ( isPrime ( num ) ) { count++; } } /* Returning 'count' prevents the compiler from optimizing this function out as worthless */ return count; } int main ( int argc, char **argv ) { struct timeval start; struct timeval finish; unsigned long i; for ( i = 100000; i <= 500000; i += 100000 ) { gettimeofday ( &start, NULL ); genPrime ( i ); gettimeofday ( &finish, NULL ); double secondsElapsed = (double)( finish.tv_sec - start.tv_sec ) + ( (double)finish.tv_usec - (double)start.tv_usec ) / 1000000.0; printf ( "Time for %9lu primes: %6.3lf seconds (%lu PPS)\n", i, secondsElapsed, (unsigned long)((double)i / secondsElapsed) ); } return 0; }
Ruby
Code:
#!/usr/bin/ruby -w # # GenPrime # # (c) 2006-2008 Steven Noonan. # Licensed under the New BSD License. # # def isPrime ( _candidate ) # 0 and 1 aren't prime. if _candidate < 2 return 0 end # All numbers less than 4 are prime, except '1' if _candidate < 4 return -1 end # Other than 2, even numbers are not prime if _candidate % 2 == 0 return 0 end # All primes are of the form 6k+i (where i = -1 or 1), except for 2 or 3. if ( _candidate + 1 ) % 6 != 0 and ( _candidate - 1 ) % 6 != 0 return 0 end # if n is composite then it can be factored into two values, # at least one of which is less than or equal to sqrt(n) limit = Math.sqrt( _candidate ) # Now test all other odd numbers up to sqrt(n) i = 3 while i <= limit if ( _candidate % i == 0 ) return 0 end i += 2 end return 1 end def genPrime ( _maxToFind ) num = 1 count = 0 while count < _maxToFind if isPrime( num ) count += 1 end num += 1 end # Returning 'count' prevents the compiler from optimizing this function out as worthless return count end i = 100000 while i <= 500000 start = Time.now genPrime( i ) finish = Time.now secondsElapsed = finish.to_f - start.to_f printf( "Time for %9u primes: %6.3f seconds (%u PPS)\n", i, secondsElapsed, i / secondsElapsed ); i += 100000 end
PHP
Code:
<?php /* * GenPrime * * (c) 2006-2008 Steven Noonan. * Licensed under the New BSD License. * */ function isPrime ( $_candidate ) { /* 0 and 1 aren't prime. */ if ( $_candidate < 2 ) return 0; /* All numbers less than 4 are prime, except '1' */ if ( $_candidate < 4 ) return -1; /* Other than 2, even numbers are not prime */ if ( $_candidate % 2 == 0 ) return 0; /* All primes are of the form 6k+i (where i = -1 or 1), except for 2 or 3. */ if ( ( $_candidate + 1 ) % 6 != 0 && ( $_candidate - 1 ) % 6 != 0 ) return 0; /* if n is composite then it can be factored into two values, at least one of which is less than or equal to sqrt(n) */ $limit = sqrt ( $_candidate ); /* Now test all other odd numbers up to sqrt(n) */ for ( $i = 3; $i <= $limit; $i += 2 ) if ( $_candidate % $i == 0 ) return 0; return 1; } function genPrime ( $_maxToFind ) { $count = 0; for ( $num = 1; $count < $_maxToFind; $num++ ) { if ( isPrime ( $num ) ) { $count++; } } return $count; } for ( $i = 100000; $i <= 500000; $i += 100000 ) { $start = microtime(true); genPrime ( $i ); $finish = microtime(true); $secondsElapsed = $finish - $start; printf ( "Time for %9lu primes: %6.3lf seconds (%lu PPS)\n", $i, $secondsElapsed, $i / $secondsElapsed ); } ?>

_________________
- Tycho

Image


Top
Offline  
 Post subject:Re: Idea for a first project?
PostPosted:Wed Mar 12, 2008 5:25 am 
External Project Staff
User avatar
 

Joined:Sun Oct 30, 2005 3:40 pm
Posts:371
Website:http://idlesoft.net
Location:~/
yuk, printf on PHP.

_________________
-- ChaosR

Image


Top
Offline  
 Post subject:Re: Idea for a first project?
PostPosted:Wed Mar 12, 2008 6:08 am 
Literally Nine
User avatar
 

Joined:Sat Apr 02, 2005 3:31 pm
Posts:1171
Location:The vicinity of an area adjacent to a location.
Quote:
yuk, printf on PHP.
yuk, PHP.

_________________
- Tycho

Image


Top
Offline  
 Post subject:Re: Idea for a first project?
PostPosted:Wed Mar 12, 2008 11:04 am 
External Project Staff
User avatar
 

Joined:Sun Oct 30, 2005 3:40 pm
Posts:371
Website:http://idlesoft.net
Location:~/
Also, amazingly, your C program does not compile if I don't optimize (-O[<num>]) it.

Besides that, I personally like PHP a lot. It might be really (well, about 10-50 times) slow compared to languages like C, but for most simple scripts you don't even need speed. PHP has the advantage of being much simpler than C when coding, because you don't have to worry about everything.

_________________
-- ChaosR

Image


Top
Offline  
 Post subject:Re: Idea for a first project?
PostPosted:Wed Mar 12, 2008 1:32 pm 
Literally Nine
User avatar
 

Joined:Sat Apr 02, 2005 3:31 pm
Posts:1171
Location:The vicinity of an area adjacent to a location.
Doesn't compile with what compiler? What errors do you get?

And PHP is great for web pages, but as a general use language, it's terrible.

_________________
- Tycho

Image


Top
Offline  
 Post subject:Re: Idea for a first project?
PostPosted:Wed Mar 12, 2008 1:44 pm 
Connoisseur of the Godawful
User avatar
 

Joined:Tue Mar 01, 2005 9:00 am
Posts:456
ICQ:286315965
Website:http://rabidtinker.mine.nu/
Yahoo Messenger:alistair_lynn
AOL:Agent_Vast@mac.com
Location:127.0.0.1
I'd love to see how Lua performs in the GenPrime benchmarks.

_________________
Alastair Lynn / Alumnus / Onlink Team


Top
Offline  
 Post subject:Re: Idea for a first project?
PostPosted:Wed Mar 12, 2008 1:47 pm 
External Project Staff
User avatar
 

Joined:Sun Oct 30, 2005 3:40 pm
Posts:371
Website:http://idlesoft.net
Location:~/
gcc, sqrt is not a function

Also, aabout 75% of all my code here is written in PHP. This includes 3 IRC bot (one minimalist (only 1 line of code :O:O), one without classes, one with classes) and an MSN chatterbot. PHP is really good in doing one thing, processing really sketchy, ugly code. It also has perl-like regex, which I use a _LOT_.

_________________
-- ChaosR

Image


Top
Offline  
 Post subject:Re: Idea for a first project?
PostPosted:Wed Mar 12, 2008 2:06 pm 
Organ Donor
User avatar
 

Joined:Mon Aug 13, 2007 1:47 pm
Posts:529
Location:Jawjuh
Make the Cloak of Darkness game.
Of course that's usually intended more for IF languages, but whatever.

(But seriously guys, does every topic in the programming section have to become a this language v. that language argument?)

_________________
Creative people must be stopped! (Latest Entry 7/31/11: "Fishsticks (18+))

Pleasantville by Night, a humorous horror web RPG


Top
Offline  
 Post subject:Re: Idea for a first project?
PostPosted:Wed Mar 12, 2008 4:59 pm 
User avatar
 

Joined:Thu Mar 06, 2008 4:32 am
Posts:53
Yahoo Messenger:sfericz
Location:Tennessee
Rickton: Thanks for the link, im looking into it now. I've also obtained the source for Wolfenstien, Quake, and Doom. I thought it might be a good source to teach me about mapping and using game engines.
Quote:
And PHP is great for web pages, but as a general use language, it's terrible.
Im using XML, and some Flash for my site, im don't know much about the php language, would it be better to switch to PHP for my main site?

_________________
start a riot...


Top
Offline  
Display posts from previous: Sort by 
Post new topic Reply to topic

All times are UTC-05:00


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created by Miah with assistance from hyprnova