Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mox123

macrumors 6502
Original poster
Jul 18, 2007
259
1
Chicago
so i am going through a crash course on C++. i currently have the base model penyrn MBP. once i have C++ codes written on a text file, what should i do next to run the program?

1. any step-by-step instruction on how i can go from lines of C++ codes to compiling it to running it?

2. what would be some of the best ways to master C++ programming in a very quick time? i. e. get a reasonable score on brainbench exams

for background info, i have a PhD already in a hardcore theoretical science, and i have some experience with using the terminal and reading fortran codes

Thanks a million in advance for any suggestions!
 

toddburch

macrumors 6502a
Dec 4, 2006
748
0
Katy, Texas
I would suggest you install Xcode. It came on the CD's with your MBP, or you can download it from Apple Web Site.

Once you install Xcode, create a File -> New Project and select one of the styles of C++ project.

Todd
 

mox123

macrumors 6502
Original poster
Jul 18, 2007
259
1
Chicago
I would suggest you install Xcode. It came on the CD's with your MBP, or you can download it from Apple Web Site.

Once you install Xcode, create a File -> New Project and select one of the styles of C++ project.

Todd

oh kewl...is that X11 inside the utilities folder?
 

mox123

macrumors 6502
Original poster
Jul 18, 2007
259
1
Chicago
Well X11 is located in the Utilities folder yes, but I'm not sure what specific relevance it has to this question? Are you looking at developing an X11 app?

oh oops...so Xcode and X11 are different programs then for writing codes?
 

Sander

macrumors 6502a
Apr 24, 2008
521
67
so i am going through a crash course on C++. i currently have the base model penyrn MBP. once i have C++ codes written on a text file, what should i do next to run the program?

1. any step-by-step instruction on how i can go from lines of C++ codes to compiling it to running it?

2. what would be some of the best ways to master C++ programming in a very quick time? i. e. get a reasonable score on brainbench exams

for background info, i have a PhD already in a hardcore theoretical science, and i have some experience with using the terminal and reading fortran codes

Thanks a million in advance for any suggestions!

Since you say you have experience with using the terminal, I'd say you don't need to get into Xcode yet.

Compile your new C++ program like so:

g++ -o myprogram myprogram.cpp

you can then run it by typing

./myprogram

to the same prompt.

Xcode is a so-called "Integrated Development Environment" (like Visual Studio on Windows, or Eclipse). What's nice about IDE's:

- they help you manage multi-file projects easily
- they help you locate syntax errors in your code quickly
- they often have a nice integrated help/documentation system.

The first benefit is not really relevant for the vast majority of "newbe" programs (most of which are typed in a single file anyway).
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
What Sander wrote above is the right way to start out, in my opinion. I doubt seriously that any exam you are studying for is going to cater to any particular IDE, so using a command line compiler is the way to go.

I haven't taken any brainbench exams (and shudder to think of what kinds of questions might appear on this sort of test, anyway), so you're going to have to be a bit more specific on what you hope to learn for us to be able to give you pointers on what to focus on.

If the test is on using the STL effectively, that is far different than if it's just testing your ability to write standard C++ code, perhaps define a few objects, find errors in examples, etc.

-Lee
 

mox123

macrumors 6502
Original poster
Jul 18, 2007
259
1
Chicago
I would suggest you install Xcode. It came on the CD's with your MBP, or you can download it from Apple Web Site.

Once you install Xcode, create a File -> New Project and select one of the styles of C++ project.

Todd

oh kewl....so what's the difference between Carbon C++ applications and Carbon C++ standard applications? what is carbon? i know apple uses it
 

mox123

macrumors 6502
Original poster
Jul 18, 2007
259
1
Chicago
Since you say you have experience with using the terminal, I'd say you don't need to get into Xcode yet.

Compile your new C++ program like so:

g++ -o myprogram myprogram.cpp

you can then run it by typing

./myprogram

to the same prompt.

Xcode is a so-called "Integrated Development Environment" (like Visual Studio on Windows, or Eclipse). What's nice about IDE's:

- they help you manage multi-file projects easily
- they help you locate syntax errors in your code quickly
- they often have a nice integrated help/documentation system.

The first benefit is not really relevant for the vast majority of "newbe" programs (most of which are typed in a single file anyway).

oh kewl...this is exactly what i needed to find out! sometimes i see people doing these sort of things in cheap linux boxes....so i want to be able to do this on my own mac as well as in linux/unix boxes at work as well!
 

mox123

macrumors 6502
Original poster
Jul 18, 2007
259
1
Chicago
What Sander wrote above is the right way to start out, in my opinion. I doubt seriously that any exam you are studying for is going to cater to any particular IDE, so using a command line compiler is the way to go.

I haven't taken any brainbench exams (and shudder to think of what kinds of questions might appear on this sort of test, anyway), so you're going to have to be a bit more specific on what you hope to learn for us to be able to give you pointers on what to focus on.

If the test is on using the STL effectively, that is far different than if it's just testing your ability to write standard C++ code, perhaps define a few objects, find errors in examples, etc.

-Lee

hmm what is STL? basically i need to be proficient in writing C++ codes for quantitative modeling....instead of using proprietory softwares like Mathematica i suppose...since not everyone would have that

I guess in general i find out that most people don't have macs nor what i thought would be standard softwares (like mathematica)...so somehow i need to do more work and learn how to do the same things without using proprietary softwares and convenient hardwares like a mac :(
 

Cromulent

macrumors 604
Oct 2, 2006
6,812
1,100
The Land of Hope and Glory
oh kewl....so what's the difference between Carbon C++ applications and Carbon C++ standard applications? what is carbon? i know apple uses it

Carbon is an API that allows you to make native Mac OS X applications. I would forget about it for the time being and just stick to doing command line programs until you are comfortable with C/C++.
 

mox123

macrumors 6502
Original poster
Jul 18, 2007
259
1
Chicago
Carbon is an API that allows you to make native Mac OS X applications. I would forget about it for the time being and just stick to doing command line programs until you are comfortable with C/C++.

hmm...probably a very stupid question...what is API?

so if i use xcode for rudimentary C++ codes, what kind of new project should i choose to begin with?
 

Cromulent

macrumors 604
Oct 2, 2006
6,812
1,100
The Land of Hope and Glory
hmm...probably a very stupid question...what is API?

Application Programming Interface. It supplies a group of functions which allow you to interact with either other programs, libraries or the OS.

so if i use xcode for rudimentary C++ codes, what kind of new project should i choose to begin with?

C++ Tool in the Command Line Utility section of the new project window.
 

yeroen

macrumors 6502a
Mar 8, 2007
944
2
Cambridge, MA
hmm...probably a very stupid question...what is API?

so if i use xcode for rudimentary C++ codes, what kind of new project should i choose to begin with?

API == "Application Programming Interface". Essentially an API is a set of functions, datatypes, and/or classes that are bundled into a shared library (or the OS, or another application) for you to make use of. For more info, consult wikipedia.

At this point, learning Xcode or any other IDE would just be a massive distraction. Learn how to edit, compile, and build by hand first, things that the IDE will hide from you but that you will need to know nonetheless, then graduate to the complexity of the IDE as the complexity of your projects warrants.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
hmm what is STL? basically i need to be proficient in writing C++ codes for quantitative modeling....instead of using proprietory softwares like Mathematica i suppose...since not everyone would have that

I guess in general i find out that most people don't have macs nor what i thought would be standard softwares (like mathematica)...so somehow i need to do more work and learn how to do the same things without using proprietary softwares and convenient hardwares like a mac :(

STL is the Standard Template Library. I only brought it up because it is a pretty common tool for C++ and thought it might be covered on the tests you mentioned. If you are just starting out you should learn to work without it, anyway.

I don't know anything about quantitative modeling but a very brief overview I just read makes me think that you just need to be able to program mathematical relationships, forumlae, etc. C++ is certainly able to handle this, and I think starting out you should just learn how to do input and output with std::cin and std::cout. For cout you should look into setting precision, etc. since it sounds like you will be dealing with a fair amount of floating-point math.

Once you've gotten that far you can start looking into the mathematical functions provided by including the header file math.h. If there are more advanced mathematical operations you need to perform than those provided you can start looking into building these. Other may have already programmed these operations and made them available online, but it may be better for you to write them yourself to get familiar with how they are programmed.

-Lee
 

Sander

macrumors 6502a
Apr 24, 2008
521
67
oh kewl...this is exactly what i needed to find out! sometimes i see people doing these sort of things in cheap linux boxes....so i want to be able to do this on my own mac as well as in linux/unix boxes at work as well!

Ahem to "cheap linux boxes". I bought my wife a Mac Mini a few years ago, and when I found out about the Terminal and did a listing of /bin, I rember thinking "Wow, this is almost like a real computer!".

We have two Macs now, and I'm getting a MacBook Pro soon.

Also, I don't mean to sound condescending, but it looks like you still have a lot to learn. I would really focus on the programming language first. A lot of people get put off while programming because they have set their aims a bit too high, and assume they can produce cool stuff in a week or so. I had to have a long sobering chat with one of my friends who thought he'd "start with a simple game" - I assumed he meant tic-tac-toe, but he was thinking more in the lines of Doom ("Really simple, not with fancy multi-player stuff or anything").

If your aim is to get a good brainbench score so as to get yourself invited for job interviews, be careful. I've interviewed lots of people, and "artificially inflated scores" are always popped with one or two smart questions.

I think learning to program C++ is like learning to play the violin. Expect to be horrible at it for a few years, and expect to throw away the first few projects you attempt.

Also, are you sure you want to start with C++, and not, say, C? If you already know FORTRAN, you should be able to pick up C relatively easily, because it doesn't introduce any new programming paradigms (generic programming, object orientation) like C++ does.

Then, once you reach the point that you're thinking "I wish I could organize my code in such a way that related data and functions were grouped together so I can more easily exchange parts of my software, or put in different algorithms without having to change my code in dozens of places", then you read up on object orientation and reach enlightenment.

If it weren't blatant self-advertizing, I would suggest clicking on the link in my signature. You are the exact audience for my book.
 

mox123

macrumors 6502
Original poster
Jul 18, 2007
259
1
Chicago
Ahem to "cheap linux boxes". I bought my wife a Mac Mini a few years ago, and when I found out about the Terminal and did a listing of /bin, I rember thinking "Wow, this is almost like a real computer!".

We have two Macs now, and I'm getting a MacBook Pro soon.

Also, I don't mean to sound condescending, but it looks like you still have a lot to learn. I would really focus on the programming language first. A lot of people get put off while programming because they have set their aims a bit too high, and assume they can produce cool stuff in a week or so. I had to have a long sobering chat with one of my friends who thought he'd "start with a simple game" - I assumed he meant tic-tac-toe, but he was thinking more in the lines of Doom ("Really simple, not with fancy multi-player stuff or anything").

If your aim is to get a good brainbench score so as to get yourself invited for job interviews, be careful. I've interviewed lots of people, and "artificially inflated scores" are always popped with one or two smart questions.

I think learning to program C++ is like learning to play the violin. Expect to be horrible at it for a few years, and expect to throw away the first few projects you attempt.

Also, are you sure you want to start with C++, and not, say, C? If you already know FORTRAN, you should be able to pick up C relatively easily, because it doesn't introduce any new programming paradigms (generic programming, object orientation) like C++ does.

Then, once you reach the point that you're thinking "I wish I could organize my code in such a way that related data and functions were grouped together so I can more easily exchange parts of my software, or put in different algorithms without having to change my code in dozens of places", then you read up on object orientation and reach enlightenment.

If it weren't blatant self-advertizing, I would suggest clicking on the link in my signature. You are the exact audience for my book.


Actually i should have said inexpensive....all i meant was that I have been used to all the good stuff, both hardware and software, where in reality i have to work with people who haven't had access to them....so now i sorta have to get back to basics and be well-versed in all these other stuff too!!

What do you mean by "I've interviewed lots of people, and "artificially inflated scores" are always popped with one or two smart questions"? What kind of questions would you ask?

THe kind of work I have in mind actually requires someone to have a lot of math and physics background, which i do....so I have been told that I already have the hard part down....now i just need to pick up on the skills on running these problems that I can set up using C++ and such. I have read up on C++ and principles behind object-oriented programming....frankly i find the latter to be much more intuitive than the procedural kind.....theory aside (which i'm always better at...the more abstract things get, the better i am at them), i guess i am trying to get my hands wet in actually writing and compiling some actual codes...

At this point, my biggest concern is actually being able to know all the syntax of C++ off the top of my head, which presumably someone who has actual programming experience would be able to do

would you know if brainbench asks big-picture questions on object-oriented principles behind C++, or on the actual nitty-grindy syntax stuff? at this point, i'm much more concerned about the latter....
 

mox123

macrumors 6502
Original poster
Jul 18, 2007
259
1
Chicago
oops...i hit the wrong button...

so to sum up, i guess i'm not really trying to be a hardcore programmer....i need to learn C++ so i can use it as a means to some bigger end of solving certain problems that i can't do with just pencil or paper (or when not allowed to use mathematica and such!)
 

Cromulent

macrumors 604
Oct 2, 2006
6,812
1,100
The Land of Hope and Glory
so to sum up, i guess i'm not really trying to be a hardcore programmer....i need to learn C++ so i can use it as a means to some bigger end of solving certain problems that i can't do with just pencil or paper (or when not allowed to use mathematica and such!)

I think that is what every programmer does :). I doubt you will find a programmer who writes code for the hell of it.
 

yeroen

macrumors 6502a
Mar 8, 2007
944
2
Cambridge, MA
It sounds as if you got a quant-job at an investment bank or hedge fund where the habit is to retread Ph.D's in math/physics as quantitative developers.

You should just pick up a copy of 'Numerical Recipes in C++', and learn what you need to know of C++ from that.

I will say this speaking from experience, for numerics, Fotran is better, if less fashionable these days.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
It sounds as if you got a quant-job at an investment bank or hedge fund where the habit is to retread Ph.D's in math/physics as quantitative developers.

You should just pick up a copy of 'Numerical Recipes in C++', and learn what you need to know of C++ from that.

I will say this speaking from experience, for numerics, Fotran is better, if less fashionable these days.

Modern Fortran is very capable, even for OOP. Modules, generics, array-slicing goodness, pointers, rich allocation primitives (is this thing allocated? how big is it? is it big enough to hold this? no, let's reallocate then). It's not how the thread started, but it is quite good for math and scientific applications. The only issue might be third party library integration, but it has strong enough interoperability with C that I think that can be mitigated.
 

Sander

macrumors 6502a
Apr 24, 2008
521
67
so to sum up, i guess i'm not really trying to be a hardcore programmer....i need to learn C++ so i can use it as a means to some bigger end of solving certain problems that i can't do with just pencil or paper (or when not allowed to use mathematica and such!)

Okay. I think I got misled by your brainbench comment earlier. I've never taken a brainbench test myself, but new applicants in our company usually do one as a "pre-screening". I thought this was the main use for it, so when you asked how to quickly increase your brainbench scores, I assumed that was so you could interview for a C++ position.

I usually only glance at these scores. If someone is sent to me because he's a "C++ expert", I have other ways of finding out.

One of my favorite questions is to ask which C++ book is currently on their bedside table, and paying attention to their response. Or ask them which book they would recommend.

I'm actually not particularly interested if someone really is a C++ expert. In fact, I'd rather they aren't afraid of admitting they aren't. I interviewed a guy who couldn't quite tell me what template metaprogramming was, but insisted that it was useless anyway so it wasn't something he'd ever needed to learn.

There are a lot of C programmers out there who think they became C++ programmers after renaming their code with a .cpp extension.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.