Chapter1 Getting Started
Modern C++ can be thought of as comprising there parts:
The low-level language,largely inherited from C
More advanced language features that allow us to define our own data types and to organize large-scale programs and systems
The standard library,which uses these advanced features to provide a set of useful data structures and algorithms
Most of the basic elements of C++:built-in,library,and class types;variables;expressions;statements;and functions.
A bookstore keeps a file of transactions,each of which records the sale of a given book.Each transaction contains an ISBN,the number of copies sold,and the price at which each copy was sold.Each transaction looks like 0-201-70353-X 4 24.99
We know that the program must :
1.Define variables
2.Do input and output
3.Define a data structure to hold the data we`re managing
4.Test whether two records have the same ISBN
5.Write a loop that will process every record in the transaction file
1.1 Writing a Simple C++ Program
Every C++ program contains one or more functions,one of which must be named main.A function consists of a sequence of statements that perform the work of the function.The operating system executes a program by calling the function named main.That function executes its constituent statements and returns a value to the operating systems.
Here is a simple version of *main*does nothing but return a value:
int main()
{
return 0;
}
The operating system uses the value return by main to determine whether the program succeeded or failed.A return value of 0 indicates success.
The main function is special in various ways,the most important of which are that the function must exist in every C++ program and it is the (only) function that the operating system explicitly calls.
We define main the same way we define other functions.A function definition specifies four elements:the return type,the function name,a(possibly empty) parameter enclosed in parentheses,and the function body.The main function may have only a restricted set of parameters.As defined here,the parameter list is empty.
The main function is required to have a return type of int ,which is the type that represents integers. The int type is a built-in type,which means that the type is defined by the language.
When the return includes a value such as 0,that value is the return value of the function. The value returned must have the same type as the return type of the function or be a type that can be converted to that type.In the case of main the return type must be int ,and the value 0 is an int.
On most systems,the return value from main is a status indicator.A return value of 0 indicated by the operating system.Usually a nonzero return indicates that an error occurred.Each operating system has its own way of telling the user what main returned.
1.1.1 Compiling and Executing Our Program
Program Source File Naming Convention
The suffix for C++ program files depends on which compiler you`re running.Other conventions include.