Structure of a C++ Program

Before Starting: You should get a freely-distributed C++ compiler. An example of a freely-distributed C++ compiler would be Dev C++. You can get this compiler from the following link:

After Downloading: The main buttons that you will be using are File/New/Sourcefile and Execute/Compile & Run(F9) When you open up the new sourcefile, and type in the code, pressing compile and run, will take the sourcecode that you have written, and print it in a DOS-like application.

Basic Terminology:
string- a line of text printed across the screen
process- an action that the computer is taking

“Hello World!” Program:

1 //my first C++ program
2 #include<iostream>
3 using namespace std ;
4 main()
6 {
7 cout<<“Hello World!\n” ;
8 system(“pause”) ;
9 return 0;
10 }

Tearing apart the, “Hello World!” Program:

1 //my first C++ program * This is a comment. Comments do not appear on the program when it runs. As long as you have // in front of words, it is classified as a comment, and will turn blue.

2 #include<iostream> * This line of code is known as the, preprocessor. This line of code, tells the computer which other algorithm it should look from. In this example, the program, needs the assistants of the algorithm, iostream to run. Without this line of code, the program will not run.

3 using namespace std ; * This is what is known as a directive. The root of this term is direct. So, the application is directing the computer to do a process.

4 main() * main() is the center point of the application. The main part is telling the computer that this is the starting point of the application itself. The parenthesis are where the declared integers would go. Because there aren’t any in this application, only the main part is needed.

5 * This is just a blank line. The computer needs its space, so this is a line, where the computer can take a break when compiling.

6 { * This bracket is used to show where all the work is starting. In this case, the bracket is used for showing that the text is going to be printed.

7 cout<<“Hello World!\n” ; * This is a line of code, where all the work is being done. This line will print a string across the screen. The \n part tells the computer, that anything printed after this string, must go to the next line. You can go without having the \n in this line, but anything else, and the program will not compile.

8 system(“pause”) ; * If you are compiling and then trying to run a program in Windows, it won’t work. The moment you think it will work, it won’t. It will terminate itself. With this command in your application, it will stay open, so you can watch everything that is happening.

9 return 0; * You need the computer to know what to do, when all the processes are done. So, that’s where this line of code comes in. When all the processes and commands are finished running, this line of code tells the computer to terminate once a key is pressed. You need this line of code in your application.

10 } * You also need this last bracket. It closes off the application.

Ending Comments: Congratualtions! You have just written and compiled your own application. I had a great time writing this tutorial, and I intend on writing a follow-up on variables, arrays, and other features. If you have any comments, please feel free to make me aware of them.