Professional Documents
Culture Documents
II. Quick Facts Regrading C++ Object oriented programming with C++ - With its use in C+
C++ ranks 4th in popularity according to 2016 IEEE +, you are able to divide these complex problems into
spectrum Top Programming Language ranking. smaller sets by creating objects.
Learning C++ is a wise investment for all programmers. Power of standard library (Standard template library - STL)
- The power of C++ extends with the use of standard
“C++ is a statically-typed, free-form, (usually) compiled, libraries contained in it. These libraries contain efficient
multi-paradigm, intermediate- level general-purpose algorithms that you use extensively while coding. This
middle-level programming language.” saves ample amount of programming effort, which
otherwise would have been wasted reinventing the wheel.
In simple terms, C++ is a sophisticated, efficient and a
general-purpose programming language based on C. II. Anatomy of a C++ program
While Bjarne Stroustrup was working in AT&T Bell Labs in Your first C++ program
1979, he faced difficulties in analyzing UNIX kernel for 1. #include <iostream>
distributed systems. The current languages were either too 2. using namespace std;
slow or too low level. So, he set forward to create a new 3. int main()
language. His aim was to create a language with far higher 4. {
level of abstraction while retaining the efficiency of C. 5. cout << "Hello World";
This new programming language was named C with 6. return 0;
Classes, but was later renamed to C++ (++ refers to the 7. }
increment operator in C).
Code Discussion
III. Five Basic Concepts of C++ Line 1. #include <iostream>
1. C++ Variables - The backbone of any programming The standard I/O system is declared in the header file:-
language. A variable is merely a way to store some <iostream> iostream is a header file which provides us with
information for later use. input & output streams. Header files contained
predeclared function libraries, which can be used by users
2. C++ Control Structures - The code is read by the for their ease Line
compiler line by line (from top to bottom, and for the most
part left to right). This is known as "code flow." When the 2. using namespace std;
code is being read from top to bottom, it may encounter a Namespaces were introduced into C++ to resolve identifier
point where it needs to make a decision. Based on the name conflicts
decision, the program may jump to a different part of the Namespace collects identifiers used for class, object and
code. variables.
This ensured that two objects can have the same name and I. Decision Making in C++
yet be treated differently if they belonged to different Decision making statements in programming languages
namespaces. decides the direction of flow of program
execution. Decision making statements available in C or C+
Line 3. int main() + are [1].
-The actual program starts with the function named main().
-When your program starts, main() is called automatically. 1. if statement
main(), is the function which holds the executing part of 2. if..else statements
program its return type is int. 3. nested if statements
main() function is the body of your program. All processing 4. if-else-if ladder
should be done in this part. 5. switch statements
6. Jump Statements:
Line 4 and 7: { } a. break
The open brace ( { ) at line 4 indicates the beginning of b. continue
main's function definition, and the closing brace ( } ) at line c. goto
7, indicates its end. Everything between these braces is the d. return
function's body that defines what happens when main is
called. All functions use braces to indicate the beginning In C++, switch, case, break, and default are reserved words.
and end of their definitions. In a switch structure, first the expression is evaluated. The
When writing a function, or a class, or an if statement, or a value of the expression is then used to perform the actions
loop, C++ uses an opening curly brace to begin the body of specified in the statements that follow the reserved word
the function, class, if/else statement, or loop. case. Recall that in a syntax, shading indicates an optional
Then you put all the normal statements and close it all with part of the definition. Although it need not be, the
a matching closing curly brace. expression is usually an identifier. Whether it is an
identifier or an expression, the value can be only integral.
Line 5: cout << “Hello World”; The expression is sometimes called the selector. Its
cout is use to display something on the monitor. value determines which statement is selected for
<< output redirection operator. execution. A particular case value should appear only once.
Whatever follows the output redirection operator is One or more statements may follow a case label, so you do
written to the console. not need to use braces to turn multiple statements into a
if you want a string of characters written, be certain to single compound statement. The break statement may
enclose them in double quotes (") or may not appear after each statement.