|
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:
Now consult your compiler's literature about what
to click to compile your program. The shortcut key is
traditionally 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.
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 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.
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.
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.
|