C++





Developed by Bjarne Stroustrup at Bell labs.
Strongly typed language.
Middle level language.

High level language:
Short code more concentration on logic.

Low level language:
More concentration on initialization and assigning.

Middle level language:
Combination of both high level language and low level language.

Strongly typed programming language:
If a variable is assigned it always behaves as certain type until it is re-assigned.

Downloading and installing code blocks:

Declaration of variable:
Informs the compiler the size to reserve in memory.
Syntax: Data-type variable;

Initialization of variable:
After declaring variable they are assigned a value for first time.
Syntax: Data-type var=value;
             Data-type var(value);
             Data-type var{value};
Example: int x=0;
                int x(0);
                int x{0};

Data types:
Used to say that the type of data it can hold.
Integer: Size is 4 bytes.
Boolean: Can store true or false.
Character: 1 byte of memory.
Float: 4 bytes of memory.
Double: 8 bytes of memory.
Void: Without any value.

Hello world program:


Loops in c++:
Block of code needs to be executed several times.

For loop:
Code needs to be executed for particular no of times.
Syntax: for(initialization; condition; increment/dec){
                 //statements;
             }
Example:

While loop:
Executes the statement as long as condition is true.
Syntax:
While(Condition){
//Statement;
}
Example:

Do-While loop:
It executes the statements even if the condition fails for first time.
Syntax:
do{
//Statements;
}while(condition);
Example:

Loop control statements:
Break:

Continue:

Conditional execution:
Checking the condition and printing statement.

If:
Condition is true it will print the statement.
Syntax: If(condition){
               //Statement;
             }
Example:

If-else:
If the condition is true it will print statement otherwise print else statement.
Syntax: if(Condition){
                       //Statement;
                    }
               else{
                         //Statement;
                      }
Example:

Switch:
Used to test for equality against the list of values.
Syntax:
Switch(Expression): {
Case constant-expression:  Statement;  break;
Default: Statement;
}

Functions and calling functions:
Group of statement that together perform a specific task.
Syntax: return-type function-name(parameters){
                         //Statements;
              }
For calling function we have to write function-name(parameters).

Mathematical functions:
Pow: Power of a no.
Abs: Returns the absolute value.
Floor: Returns the nearest value less than or equal to no.
Sqrt: Returns the sqrt of a no.

String manipulation:
Concatenation of string:

Partial string:

Starting index:

Count the no of occurrences of sub-string in string:


Taking user name and age:

File writing:

File reading:

Printing the second and fourth line in file:

Finding the first non repeated character in string:

Highest repeated character:

Digit identification of string:

Pyramid:

Permutation:

Graphics function:


Connecting to data base:




You Might Also Like