Lecutre_1
.pdfWeek 1
Algorithmization and
Programming Languages
Jumagaliyev Assylbek
asylbek.jumagaliyev@gmail.com
Introduction
About C++
Facilitates a disciplined approach to program design
C++ programs consist of pieces called classes and functions
Provides C++ Standard Library
First Program in C++: Printing a
Line of Text
Comments
-document program
-improve program readability
-ignored by compiler
-single-line comment starts with // (it terminates at the end of the current line)
-multiple-line comments starts with /* and ends with */
Preprocessor directive
-begins with a hash sign (#)
-processed before the program is compiled
-includes in the program the contents of the input/output stream header file
<iostream>
-preprocessor directives (like #include) do not end with a semicolon
int main ()
-a part of every C++ program
-is a program building block called a function
-exactly one function in every program must be main
-C++ programs begin executing at function main, independently of its location within the source code
-the keyword* int that main "returns" an integer
*A keyword is a word in code that is reserved by C++ for a specific use
BODY
-the left brace, {, must begin the body of every function
-the right brace, }, must end each function's body
-the entire line is called a statement
-instructs the computer to perform an action
-C++ statement must end with a semicolon(;)
-output and input are accomplished with streams of characters.
INPUT/OUTPUT
cin
-Standard input stream
-Normally keyboard
cout
-Standard output stream
-Normally computer screen
cerr
-Standard error stream
-Display error messages
Standard output stream object
std::cout
-“Connected” to screen
-Stream insertion operator (<<)
-Value to right (right operand) inserted into output stream
Namespace
std:: specifies using name that belongs to “namespace” std
std:: removed through use of using statements
Escape characters (\)
- Indicates “special” character output
return 0;
The return statement causes the main function to finish. return may be followed by a return code (in our example is followed by the return code with a value of zero). A return code of 0 for the main function is generally interpreted as the program worked as expected without any errors during its execution. This is the most usual way to end a C++ console program.