1. Data variables and calculations
In this chapter, you will learn about the essentials of programming in C++. Here will study in details simple C++ programs and try to explain the basic C++ operations. This chapter will give you the knowledge which is important for creating the simple C++ programs of the traditional form: input – process – output. First of all you need to know some of the basic features of ISO/IEC C++ language features.
1.1. The structure of a C++ program
Programs that will run as console applications under Visual C++ 2010 are programs that read data from the command line and output the results to the command line. A program C++ consists of one or more functions. Every ISO/IEC standard programming language contains the function main( ), and all C++ programs of any size consist of several functions. Function main( ) represents the execution of the program start, plus a number of other functions. A function is simply a self – contained block of code with a unique name that you invoke for execution by using the name of a function.
A program in C++ programming language consists of one or more functions. Every ISO/IEC standard C++ program have to contain the function main ( ), and all C++ programs of any size consist of several functions. The main ( ) function where execution of the program starts, plus a number of other functions. A function is simply a self-contained bloc of code with unique name that you invoke for execution by using the name of the function. For example in Visual Basic when you start a new project the Basic will automatically open the Wizard tool. After you close this window you will see a function _tmain. This is a programming device to allow the name to be main or wmain, depending on whether or not the program is using Unicode characters. The names wmain and _tmain are Microsoft – specific. The name for the main function conforming to the ISO /IEC standard for C++ is main.
Figure 1.1 – Typical console program
The previous picture shows how a typical console program is structured. The execution of the program show starts at the beginning of the function main ( ). From main ( ), execution transfers to a function input_names ( ), which returns execution to the position immediately following the point where it was called in main ( ). The sort_names ( ) function is then called from main ( ), and, once control returns to main ( ), the final function output_names ( ) is called. Eventually, once output has been completed, execution returns once again to main ( ) and the program ends.
Of course different programs may have radically different function structures, but they all start execution at the beginning of main ( ) . If you structure your programs as a number of functions, you can write and test each functions separately. Segmenting your programs in this way gives you a further advantage in that functions you write to preform particular task can be re-used in other programs. The libraries that come with C++ programming language provide a lot of standard functions that you can use in your programs.