PDA

View Full Version : is there good c++ tutorial or ebook free???




xwk88
May 22, 2005, 10:52 AM
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.



cube
May 22, 2005, 11:11 AM
C++ is garbage. Learn Scheme.

GeeYouEye
May 22, 2005, 02:55 PM
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.

Grover
May 22, 2005, 03:24 PM
You can find a free C++ book (and similar books for some other languages) at:

http://mindview.net/Books/TICPP/ThinkingInCPP2e.html

mj_1903
May 22, 2005, 09:22 PM
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:

- (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];
}

kainjow
May 22, 2005, 10:13 PM
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:
How about this:
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: :)

jared_kipe
May 22, 2005, 10:37 PM
How about a good Objective-C for dummies then?

mj_1903
May 22, 2005, 10:43 PM
How about this:
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: :)

Basically what I ended up doing. :)

mj_1903
May 22, 2005, 10:45 PM
How about a good Objective-C for dummies then?

Try Aaron Hillegass' Cocoa Programming for Mac OS X (Second Edition) (http://www.amazon.com/exec/obidos/tg/detail/-/0321213149/qid=1116816311/sr=8-1/ref=pd_csp_1/104-2366880-4710319?v=glance&s=books&n=507846)

GeeYouEye
May 22, 2005, 11:15 PM
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.

rinseout
May 22, 2005, 11:35 PM
You can find a free C++ book (and similar books for some other languages) at:

http://mindview.net/Books/TICPP/ThinkingInCPP2e.html

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

Don't let people talk you out of C++. It's great.

Abstract
May 22, 2005, 11:42 PM
Learn C++ in 21 Days (http://www.geocities.com/vietz4info2/cpp.html)

Believe it or not, its decent. ;)

No wait, its decent if you don't know how to program, like me. :o

Mechcozmo
May 23, 2005, 12:39 AM
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.

superbovine
May 23, 2005, 12:45 AM
C++ is garbage. Learn Scheme.

nuk nuk nuk

cube
May 23, 2005, 10:06 AM
Scheme (and Lisp) are impossible.


It's only impossible for people who haven't bothered enough to get it.

xwk88
May 23, 2005, 01:42 PM
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.

therevolution
May 23, 2005, 01:52 PM
how do I compile a cpp file from terminalTo compile:

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

./a.out

csubear
May 23, 2005, 02:12 PM
C++ is garbage. Learn Scheme.

Ug... C++ is a very solid intro for obect oriented programing.

cube
May 23, 2005, 02:22 PM
Ug... C++ is a very solid intro for obect oriented programing.

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.

superbovine
May 24, 2005, 12:57 AM
To compile:

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

./a.out

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.

GeeYouEye
May 24, 2005, 02:12 AM
It's only impossible for people who haven't bothered enough to get it.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!

Davito
May 24, 2005, 03:26 AM
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 :)

cube
May 24, 2005, 04:03 AM
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!

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