C++ Programming
What is C++ programming?
C++ is a programming language which consists of a vocabulary of commands that humans can understand and that can be converted into machine language fairly easily and a language structure that allows humans to combine these C++ commands into a program that actually does something. This programming language is widely used to program small robot and other minor machines with remote controls. For example, the 2014 Aerial Assist is being programmed using the C++ language.
What is a program?
A C++ program is a text file which contains a sequence of C++ commands put together according to the laws of C++ grammar. This text file is known as the source file. The point of programming is to write a sequence of C++ commands that can be converted into a machine language program that does whatever it is that you want done.
This is an example of a C++ program which adds two numbers and then averages them. The user must put in the two numbers (any) and then run the program to average the given numbers.
This is an example of a C++ program which adds two numbers and then averages them. The user must put in the two numbers (any) and then run the program to average the given numbers.
Structure of a C++ program
The program above is a very simple program which delivers a message. Lets discuss how the program is made and what each line means from top to bottom (1-7) :
Line 1: (//) are comments by the programmer and have no effect on the behavior of the program. Programmers use them to include short explanations on what the program is about. In this case, it is a brief introductory description of the program.
Line 2: #include <iostream>Lines beginning with a hash sign (#) are directives read and interpreted by what is known as the preprocessor. They are special lines interpreted before the compilation of the program itself begins.
Line 3: A blank line. Blank lines have no effect on a program. They are used to make the program look neater and preventing it from looking messy.
Line 4: int main ()This line initiates the declaration of a function. Essentially, a function is a group of code statements which are given a name: in this case, this gives the name "main" to the group of code statements that follow.
Lines 5 and 7: { and }The open brace ({) at line 5 indicates the beginning of main's function definition, and the closing brace (}) at line 7, indicates its end. Everything between these braces is the function's body that defines what happens when main is called. All functions use braces to indicate the beginning and end of their definitions.
Line 6: std::cout << "Hello World!";This line is a C++ statement.
Line 1: (//) are comments by the programmer and have no effect on the behavior of the program. Programmers use them to include short explanations on what the program is about. In this case, it is a brief introductory description of the program.
Line 2: #include <iostream>Lines beginning with a hash sign (#) are directives read and interpreted by what is known as the preprocessor. They are special lines interpreted before the compilation of the program itself begins.
Line 3: A blank line. Blank lines have no effect on a program. They are used to make the program look neater and preventing it from looking messy.
Line 4: int main ()This line initiates the declaration of a function. Essentially, a function is a group of code statements which are given a name: in this case, this gives the name "main" to the group of code statements that follow.
Lines 5 and 7: { and }The open brace ({) at line 5 indicates the beginning of main's function definition, and the closing brace (}) at line 7, indicates its end. Everything between these braces is the function's body that defines what happens when main is called. All functions use braces to indicate the beginning and end of their definitions.
Line 6: std::cout << "Hello World!";This line is a C++ statement.