is there good c++ tutorial or ebook free???

Discussion in 'Mac Programming' started by xwk88, May 22, 2005.

  1. xwk88 macrumors regular

    Joined:
    May 3, 2005
    #1
    I know java quite well but I want to learn one more language before the next year of school and thought c++ would be the best one to learn. I looked all over the forums and found lots of references to books but I don't really want a book I want something I can get free on the net.


    I saw a couple of threads on something called cocoa is the a language and if it is, is it better for me to learn that than c++ if programing o a mac.
     
  2. cube macrumors G4

    Joined:
    May 10, 2004
  3. GeeYouEye macrumors 68000

    GeeYouEye

    Joined:
    Dec 9, 2001
    Location:
    State of Denial
    #3
    Scheme (and Lisp) are impossible. Learn Python.

    Better yet, take a look at Objective-C. C++, for higher-level programming, is very little different from Java, except for the following:
    • Not everything is an object. The primitives are int, char, float, double, short, long, long long, and the unsigned versions of each (except float and double, IIRC).
    • main is just a function, living outside of any class.
    • classes are generally split between a .h header file which just has the instance variables and prototypes for the member functions, and .cpp files which contain the function definitions.

    Other than that (for high level programming only, mind you), C++ and Java are basically the same. Low-level is much different which takes up more space and time to post than I have.

    But seriously, learn Objective-C.
     
  4. Grover macrumors member

    Joined:
    May 14, 2004
    #4
  5. mj_1903 macrumors 6502a

    mj_1903

    Joined:
    Feb 3, 2003
    Location:
    Sydney, Australia
    #5
    I would highly advise learning C over C++ and I would advise learning Objective-C over C. :)

    And now for a slice of really nasty code that I am optimising today:

    Code:
    - (NSString *)formatStringToProperCasing
    {
    	NSMutableString *intern = [[NSMutableString alloc] initWithString:[self smartLowercaseString]];
    	int _length = [self length];
    	int i; for (i = 0; i < _length; i++)
    	{
    		if (i == 0)
    		{
    			[intern replaceCharactersInRange:NSMakeRange(0, 1) withString:[[intern substringWithRange:NSMakeRange(0, 1)] uppercaseString]];
    		}
    		else if (i > 2) 
    		{
    			if ([[intern substringWithRange:NSMakeRange(i - 2, 2)] isEqualToString:@". "] || [[intern substringWithRange:NSMakeRange(i - 2, 2)] isEqualToString:@"! "] || [[intern substringWithRange:NSMakeRange(i - 2, 2)] isEqualToString:@"? "])
    			{
    				[intern replaceCharactersInRange:NSMakeRange(i, 1) withString:[[intern substringWithRange:NSMakeRange(i, 1)] uppercaseString]];
    			}
    			else if ([[intern substringWithRange:NSMakeRange(i - 2, 2)] isEqualToString:@"."] || [[intern substringWithRange:NSMakeRange(i - 2, 2)] isEqualToString:@"!"] || [[intern substringWithRange:NSMakeRange(i - 2, 2)] isEqualToString:@"?"])
    			{
    				[intern replaceCharactersInRange:NSMakeRange(i, 1) withString:[NSString stringWithFormat:@" %@", [[intern substringWithRange:NSMakeRange(i, 1)] uppercaseString]]];
    			}
    		}
    	}
    	return [intern autorelease];
    }
     
  6. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    How about this:
    Code:
    char upperCase(char c)
     {
    	if (c >= 97 && c <= 122)
    		return c - 32;
    	return c;
    }
    
    char lowerCase(char c)
    {
    	if (c >= 65 && c <= 90)
    		return c + 32;
    	return c;
    }
    
    - (NSString *)formatStringToProperCasing
    {
    	NSString *theStr = [self smartLowercaseString];
    	int l = [theStr length], i;
    	char newString[l];
    	for (i=0; i<l; i++)
    	{
    		if (i == 0)
    		{
    			newString[i] = upperCase(newString[i]);
    		}
    		else if (i > 2) 
    		{
    			if ((newString[i-2] == '.' || newString[i-2] == '!' || newString[i-2] == '?')  && newString[i-1] == ' ') 
    			{
    				newString[i] = upperCase(newString[i]);
    			}
    			else if ((newString[i-2] == '.' || newString[i-2] == '!' || newString[i-2] == '?')  && newString[i-1] != ' ') 
    			{
    				// hmm not sure how to do this one in straight C......
    				//[intern replaceCharactersInRange:NSMakeRange(i, 1) withString:[NSString stringWithFormat:@" %@", [[intern substringWithRange:NSMakeRange(i, 1)] uppercaseString]]];
    			}
    		}
    	}
    	return [NSString stringWithUTF8String:(const)newString];
    }
    :confused: :)
     
  7. jared_kipe macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #7
    How about a good Objective-C for dummies then?
     
  8. mj_1903 macrumors 6502a

    mj_1903

    Joined:
    Feb 3, 2003
    Location:
    Sydney, Australia
    #8
    Basically what I ended up doing. :)
     
  9. mj_1903 macrumors 6502a

    mj_1903

    Joined:
    Feb 3, 2003
    Location:
    Sydney, Australia
    #9
  10. GeeYouEye macrumors 68000

    GeeYouEye

    Joined:
    Dec 9, 2001
    Location:
    State of Denial
    #10
    Avoid using substringWithRange: (and subdataWithRange: additionally) in a for loop. It creates something like 3 autoreleased objects; if you don't have NSAutoreleasePool alloc/inits and releases inside the for loop (which have a bit of overhead, but not too much), the amount of memory consumed goes through the roof, hugely slowing down the program.
     
  11. rinseout macrumors regular

    Joined:
    Jan 20, 2004
    #11
    big up Bruce Eckel!

    Just wanted to reprise this suggestion. Bruce Eckel rocks my world.

    Don't let people talk you out of C++. It's great.
     
  12. Abstract macrumors Penryn

    Abstract

    Joined:
    Dec 27, 2002
    Location:
    Location Location Location
    #12
    Learn C++ in 21 Days

    Believe it or not, its decent. ;)

    No wait, its decent if you don't know how to program, like me. :eek:
     
  13. Mechcozmo macrumors 603

    Mechcozmo

    Joined:
    Jul 17, 2004
    #13
    Learn AppleScript. Works on ANY Mac since like, System 7 if you do it right. Or if you use OS X specific codes, 2000 and up. And they are small. And the programming editor is free.

    :p

    But seriously, if you are getting used to concepts and stuff in programing AppleScript isn't too shabby.
     
  14. superbovine macrumors 68030

    superbovine

    Joined:
    Nov 7, 2003
    #14
    nuk nuk nuk
     
  15. cube macrumors G4

    Joined:
    May 10, 2004
    #15
    It's only impossible for people who haven't bothered enough to get it.
     
  16. xwk88 thread starter macrumors regular

    Joined:
    May 3, 2005
    #16
    how do I compile a cpp file from terminal I'm having too many problems creating a c++ project in xcode so I'm going to use terminal which might be easier, but if you guys have any idea on how to create a simple project on xcode or a better free ide for c++ I thouth about dev but found no versions for mac.
     
  17. therevolution macrumors 6502

    Joined:
    May 12, 2003
    #17
    To compile:

    Code:
    g++ filename
    This will create your program under the name a.out . To run it:

    Code:
    ./a.out
     
  18. csubear macrumors 6502a

    csubear

    Joined:
    Aug 22, 2003
    #18
    Ug... C++ is a very solid intro for obect oriented programing.
     
  19. cube macrumors G4

    Joined:
    May 10, 2004
    #19
    For subject-oriented programming it might be an intro (and not a good one anyway, as the language is a POS). If you want real object-oriented programming, you have to look at CLOS, tyniclos, Cecil to name some. Although if you consider encapsulation to be a mandatory feature of object-oriented programmimng, the only alternative is Cecil.
     
  20. superbovine macrumors 68030

    superbovine

    Joined:
    Nov 7, 2003
    #20
    the other way is: g++ <filename> -o <executable name>
    without <>

    or make a script. generally when i had to do homework for class project i usually made a small script not a formal make file. the file name was only 1 character long so i could just type "./c" and compile and test my program.
     
  21. GeeYouEye macrumors 68000

    GeeYouEye

    Joined:
    Dec 9, 2001
    Location:
    State of Denial
    #21
    Oh I bothered to get it, and I still found it impossible to work with. It is, in short, a read-eval()-print loop which has some nice features (lexical closures, anonymous functions, super-easy recursion), obscured in a syntax so convoluted (what do you expect with a single data type?) only an expert can read the code: just look at macros. For most of the power at a fraction of the cost, plus access to system calls and C libraries, look at Ruby (via irb) or Python. Includes all the magic of the end of an eval()-print, but stored in a variable you can actually do something with, because not everyone wants to write thirty line expressions with a dozen ')' at the end, only to find that you didn't close one somewhere resulting in an error trying to execute it. And Lisp users wonder why anyone would use C! Hah!
     
  22. Davito macrumors member

    Joined:
    Jun 16, 2004
    Location:
    Zurich, Switzerland
    #22
    If you want to program under OS X only, I strongly recommend you learn objective-c and cocoa. If you are already familiar with object-orientaded programming, the book of Aaron Hillegass is great for learning cocoa, together with the online-documentation for developers from apple you should have no problem learning objective-c at the same time. Good luck :)
     
  23. cube macrumors G4

    Joined:
    May 10, 2004
    #23
    - Lisp's syntax is its greatest strength, and it's the simplest one available.
    - What single datatype? There are many datatypes in Lisp.
    - You can call C libraries from Lisp, which gives you access to system calls.
    - You use something like XEmacs to edit Lisp. There's no problem with parentheses.

    I didn't need a teacher to get it, but obviously you are one of the people that do (but not a faux Lisp teacher who doesn't really know it).
     

Share This Page