Let's Begin!
Home Page Parent Page The first review

 

Let's Begin

 

Alright, let's begin the first lesson. First open up your C++ compiler. I suggest you either print this out or tile your windows by right-clicking on the taskbar and selecting tile windows horizontally or vertically. Now you can see them both at the same time.

Fire up that compiler (making sure that the computer is on first). Now open a new window. Pretty isn't it. We will follow the traditional rules of programming with a hello world program to teach the basics.

Type in the following:

#include <iostream.h>     // this tells the compiler to include a header file that contains  
      // information on how to send characters to the screen  
void main()     // this is the declaration of the main function  
         
{     // this tells the compiler that we are now going to start coding  
         
  cout<<"Hello World"<<endl; <<endl;   // this tells the compiler to print some words to screen  
         
}     // this tells the compiler that we are finished with coding the main function  

 

 

Now consult your compiler's literature about what to click to compile your program. The shortcut key is traditionally
ctrl + F9. It should compile with no trouble. For a short moment of time you should see a screen that says Hello World on a black field. Congratulations! You have made your first program. I know, I know, you want to see the output for more than a few seconds. That comes later.

Now let's rip that program apart. Here is that same program with the comment lines included. They are in RED with the rest of the program in BLUE. Comment lines are used to remind you what certain things do. They are very useful and very important if you want help from others when it comes to debugging programs. Dragon knows I have given help to a lot of people that didn't comment their code. Can you say," Oh the Humanity!!!"

To create a comment use the double slash "//" and start writing. There is another way to comment, but lets save it for a later time.

#include <iostream.h> // links the program with the library iostream.h

This statement tells the compiler to include a class which contains functions that we will use in this program. There are several different libraries besides iostream.h. To use their functions, use the command, #include <library name>, to include the library and you are ready to program.


void main() { //tells the compiler that this is the main
//section of the program

This tells the compiler that this is the main FUNCTION of the program. A function is a set of commands that tell the computer to do something. There can be many functions in a program We will talk more about functions later on.



cout <<"Hello World"<<endl; //prints "Hello World" to the screen

This is the only STATEMENT in the program. A statement is basically an expression with a semicolon at the end that gives a value to a variable which is on the left. An example of an expression is A + B. An example of a Statement is C = A;. Here we are using the KEYWORD cout. Cout is a command we use to print text to the user's monitor. The ' << ' is the extraction operator. It tells the computer that you want to perform a basic operation, in this case, printing "Hello World" to the screen. 'endl' tells the computer that you want the computer to drop down to the next line for printing.



}
//tells the compiler that this is the end of the main section

The brackets {} are used to form blocks or groups of commands that are usually related somehow. Using Brackets generally can make life easier if used properly. Don't start bracketing everything. Right now you are too inexperienced to use them correctly. Later on I will tell you some good places to use brackets.

Well, that's it for the first lesson. We have learned how to create a simple program that can print stuff onto the screen. The next lesson will be about cin and variables.

 

Tutorial2.html

 

 

 

 

1