Sunday 2 August 2015

Nested if Structure :


if statement within an if statement is called nested if statement. In nested structure, control enters into the inner if only when the outer condition is true. Only one block is executed and the remaining blocks is skipped automatically.

Syntax

The syntax of nested if is as follows :

           if (condition)
            
                   if (condition){
                       statement(s);
                                          }
                   else {
                       statement(s);
                          }

           else {
               statement(s);
                   }       

Red text is Inner if and black text is Outer if .  

Working : 

In nested if statement, the condition of outer if is checked. If it is true, the control enters in the inner if block. The inner if is working according to simple if statement. If the outer if condition is false, the inner if is skipped and control directly moves to the else part of outer if.    

Nested if Flowchart :


                lets analyze about syntax and flowchart nested if else syntax


Example :


#include <iostream>
using namespace std;
 
int main ()
{
   int marks = 55;
   if( marks >= 80) {
      cout << "U are 1st class !!";
   } 
   else {
      if( marks >= 60) {
          cout << "U are 2nd class !!";
      }  
      else {
 if( marks >= 40) {
     cout << "U are 3rd class !!";
 }
 else {  
   cout << "U are fail !!";
        }    
      }
   }
   return 0;
}

Output :


U are 3rd class !!

Saturday 1 August 2015

Multiple if-else-if Statments :


if else if statement can be used to choose one block of statements from many blocks statements. It is used when there are many options but only one block can be executed on the basis of a condition. 

Syntax 


The syntax is as follows :

                if (condition)
                      block 1;
               else
               if (condition)
                     block 2;
               else 
               if (condition)
                     block 3;
                .
                .
                .
               else
                    block n;

Working :


When the first condition becomes true then first block gets executed.

When first condition becomes false then second block is checked against the condition. If second condition becomes true then second block gets executed.

if else if Flowchat :

Else if ladder

Example :

#include <iostream>
using namespace std;
 
int main ()
{
   // declare local variable
   int marks = 55;
 
   // check the condition
   if( marks >= 80 )
   {
       // if 1st condition is true
       cout << "U are 1st class !!" << endl;
   }
   else if( marks >= 60)
   {
       // if 2nd condition is false
       cout << "U are 2nd class !!" << endl;
   }
   else if( marks >= 40)
   {
       // if 3rd condition is false
       cout << "U are 3rd class !!" << endl;
   }
   else 
   {
       // none of condition is true
       cout << "U are fail !!" << endl;
   }
 
   return 0;
}

Output :

U are 3rd class !!

if-else Statements :


if else statement is another type of if statement. It executes one block of statements when the condition is true and the other when it is false. When the if condition becomes false then else block gets executed.

Conditions :


  • Both blocks can never be executed.
  • Both blocks can never be skipped.


Syntax 


if-else syntax is as follows :

             if (condition)
                 statement;
             else
                 statement;

Two or more statements are written in curly braces { }. The syntax is as follows :

             if (condition) {
                statements 1;
                statements 2;
                .
                .
               statements n;
                                    }
            else {
               statement 1;
               statement 2;
               .
               .
               statement n;
                    }

if else Flowchart :



if else in cpp


Example :

#include <iostream>
using namespace std;
 
int main ()
{
   // declare local variable
   int marks = 30;
 
   // check the condition
   if( marks > 40 )
   {
       // if condition is true
       cout << "You are pass !!" << endl;
   }
   else
   {
       // if condition is false
       cout << "You are fail !!" << endl;
   }
 
   return 0;
}

Output :

You are fail !!

Sunday 19 July 2015

if Statement :


In C++ if statement is used to check the truthness of the expression. Condition written inside If statement consists of a boolean expression. If the condition written inside if is true then if block gets executed.

Syntax

The syntax of if statement is as follows :

             if (condition){
                  statement;
                                   }

The above syntax is used for single statement. A set of statements can also be made conditional. In this case, these statements are written in curly brackets {  } . The set of statements is also called compound statements.

                The syntax for compound statements in if statement is as follows :

            if (condition){
                statement 1;
                statement 2;
                .
                .
                statement n;
                                 }

Example :  

void main(){
int marks;
cout<<"Enter Marks : ";
cin>>marks;
if (marks>40)                        //////////////////////////Condition/////////////
cout<<"Congratulations.....You Have Passed.";               ////////////////Statement////////////
getch();
}

If user enter more than 40 marks then statement is excuted otherwise display will be empty.
Firstly check if condition, condition is fulfil then enter into a body otherwise program will be terminated.

Output :

Enter Marks : 80
Congratulations.....You Have Passed.

Again Run the program,

Enter Marks : 30
///program will be terminated and display screen will be empty.

Friday 17 July 2015

ASCII Characters :

How to convert ASCII character set to their respective integers representation in C++ programming ?



#include <iostream>
using namespace std;

int main(void)
{
cout<<"For integer number from 32 till 127\n";
cout<<"their representation for\n";
cout<<"characters is shown below.\n";
cout<<"integer      character";
cout<<"-------         ---------\n";

for (int i = 32; i<128; i++)
{
cout<<i<<"\t\t"<<(char) i<<"\n";
 }
return 0;
}


Output example :

For integer number from 32 till
their representation for
characters is shown below

integer    character
-------       ---------

32                            >>     means space      
33                !
34                "
35                #
36                $
37                %
38                &
39                '
40                (
41                )
42                *
43                +
44                ,
45                -
46                .
47                /
48                0
49                1
50                2
51                3
52                4
53                5
54                6
55                7
56                8
57                9
58                :
59                ;
60                <
61                =
62                >
63                ?
64                @
65                A
66                B
67                C
68                D
69                E
70                F
71                G
72                H
73                I
74                J
75                K
76                L
77                M
78                N
79                O
80                P
81                Q
82                R
83                S
84                T
85                U
86                V
87                W
88                X
89                Y
90                Z
91                [
92                \
93                ]
94                ^
95                _
96                `
97                a
98                b
99                c
100              d
101              e
102              f
103              g
104                h
105                i
106                j
107                k
108                l
109                m
110                n
111                o
112                p
113                q
114                r
115                s
116                t
117                u
118                v
119                w
120                x
121                y
122                z
123                {
124                |
125                }
126                ~
127                ⌂
Press any key to continue . . .

setprecision Manipulator :


The 'setprecision' manipulator is used to set the number of digits to be displayed after decimal point. It is applied to all subsequent floating point numbers written to that output stream. The value is rounded with the use of this manipulator.

Syntax :


The syntax of 'setprecision' manipulator is as follows :

      setprecision (n)

The n indicates the number of digits displayed after the decimal point. It can be an unsigned positive integer constant, variable and expression.

Example : 

                       #include <iostream.h>
                    #include <conio.h>
                    #include <iomanip.h>
void main(){

                   double r, n1 = 132.364, n2 = 26.91;
                r = n1 / n2;

     cout<<r<<endl;
     cout<<setprecision(5)<<r<<endl;
     cout<<setprecision(4)<<r<<endl;
     cout<<setprecision(3)<<r<<endl;
     cout<<setprecision(2)<<r<<endl;
     cout<<setprecision(1)<<r<<endl;

getch();
}

Output :

                      4.918766
                      4.91877
                      4.9188
                      4.919
                      4.92
                      4.9

Thursday 16 July 2015

setw() Manipulators :


The word 'setw' stands for set width. The setw manipulator is used to display the value of an expression in specified columns. The value of expression can be string or number. If the value of expression is less than specified columns, the additional columns are left blank from left side. If output is larger than the specified columns. The use of setw has no effect on the output in this case.
  1. setw() is library function in C++.
  2. setw() is declared inside #include<iomanip>.
  3. setw() will set field width.
  4. setw() sets the number of characters to be used as the field width for the next insertion operation.

Syntax :


The syntax of 'setw' manipulator is as follows :
  
     setw(n)

The n indicates the number of columns in which the value is to be displayed.

Example 1 :

                 #include<iostream.h>
                 #include<conio.h>
                 #include<iomanip.h>          

void main(){
                
              cout<< setw (10);
              cout<< "Hello" <<endl;
getch();
}
  • Now Length of String Hello is 5.
  • We have set field width 10 so it will utilizes 5 fields.
  • Remaining 5 fields are kept blank.
  • Default Justification : Left.

Example 2 :


          #include <iostream>
          #include <iomanip>

using namespace std;

   int main(){
  
              int width = 6;
              int row;
              int column;

    for(row=1;row<=10;row++){
        for(column = 1; column <= 4; column++){
     
              cout << setw(width) << row * column;
                                              }
     cout << endl;
                            }

 return 0;
            }

Output :


 1     2     3     4
 2     4     6     8
 3     6     9    12
 4     8    12    16
 5    10    15    20
 6    12    18    24
 7    14    21    28
 8    16    24    32
 9    18    27    36
10    20    30    40

Advantages Of Object Oriented Programming :


Advantages Of Object Oriented Programming

Advantages Of Object Oriented 
           Programming



  • OOP provides a clear modular structure for programs.
  • It is good for defining abstract data types.
  • Implementation details are hidden from other modules and other modules has a clearly defined interface.
  • It is easy to maintain and modify existing code as new objects can be created with small differences to existing ones.
  • Objects, methods, instance, message passing, inheritance are some important properties provided by these particular languages.
  • Encapsulation, polymorphism, abstraction are also counts in these fundamentals of programming language.
  • It implements real life scenario.
  • In OOP, programmer not only defines data types but also deals with operations applied for data structures.

  • Features of Object Oriented Programming :

    • More reliable software development is possible.
    • Enhanced form of c programming language.
    • The most important Feature is that it’s procedural and object oriented nature.
    • Much suitable for large projects.
    • Fairly efficient languages.
    • It has the feature of memory management.

    Wednesday 15 July 2015

    Sizes of Different Data Types :


    How to Find Sizes of Data Types.
                                                   
                                                Then watch video and follow me :


                  

    Tuesday 14 July 2015

    Operator Precedence :


    The order of precedence in C++ language is as follows :

    • Any expression given in parentheses is evaluated first.
    • Then multiplication *  and division / operators are evaluated.
    • Then plus +  and minus - operators are evaluated.
    • In case of parentheses within parentheses, the expression of the inner parentheses will be evaluated first.


    Example :

                The expression 5 * (4 / (5 - 1 ) ) + 3 is evaluated in the following order :
    1. First of all, the expression 5 - 1 will be evaluated. It gives a value 4.
    2. Secondly, 4 will be divided by the result of last line i.e. 4 / 4 giving value 1.
    3. Thirdly, will be multiplied by i.e. giving a result 5.
    4. Finally, 5 will be added in 3 and the last result will be 8.

    Difference b/w Prefix and Postfix Increment :


    When increment operator is used independently, prefix and postfix form work similarly. For example, the result of A++ and ++A is same.

     But when increment operator is used in a larger expression with other operators, prefix and postfix forms work differently. For example, the results of two statements A = ++B and A = B++ are different.


    In prefix form, The statement A = ++B contains two operators ++ and =. It works in following order:

    1. It increments the value of B by 1.
    2. It assigns the value of B to A.

    In postfix form, the statement A = B++ works in the following order :

    1. It assigns the value of B to A.
    2. It increments the value of B by 1.



    Monday 13 July 2015

    Kickstarter Backer & Contributor Version pdf :


                                              C++,khgamujtaba,programming book,C++ How to program

    Kickstarter Backer & Contributor Version pdf Download


    Perform All Mathematical Operations :



                 

    Arithmetic Operators :


    Arithmetic operator is a symbol that performs mathematical operation on data. C++ provides many arithmetic operators. Following is a list of all arithmetic operators in C++.


    OperationSymbolDescription
    Addition+Adds two values
    Subtraction-Subtracts one value from another value
    Multiplication*Multiplies two values
    Division/Divide one value by another value
    Modulus%Gives the remainder of division of two integers


    All arithmetic operators work with numeric values. Suppose we have two variables A and B where A = 10 and B = 5. Arithmetic operators can be used on A and B as follows :


    OperationResult
    A + B15
    A - B5
    A * B50
    A / B2
    A % B0


    Some important points about modulus operator are as follows :

    • Modulus operator is also called remainder operator.
    • The modulus operator works only with integer values.
    • In expression like 3 % 5, 3 is not divisible by 5. Its result is 3.

    Sunday 12 July 2015

    Circumference of Circle :


    The Formula use in 2*3.14*radius ( r ) .

    User enter radius and display circumference of cicle.


            

    Saturday 11 July 2015

    Calculate Area of Circle :


    Formula of area of circle = 3.14*r*r

    User enter radius ( r ) and then the formula calculates area of circle. 


                    

    Keywords :


    Keyword is a word in C++ language that has a predefined meaning and purpose. Keywords are also known as reserved words. There are different types of keywords in C++ language. The total number of keywords is 63.


    List of Keywords :



    Identifier :


    The Identifiers are the names used to represent variable, constants, types, functions and labels in the program. Identifier is an important feature of all computer languages. A good identifier name should be descriptive but short.  


    An Identifier in C++ may consist of 31 characters. If the name of an identifier is longer than 31 characters, the first character will be used. The remaining characters will be ignored by C++ compiler.


     Some important rules for identifier name are as follows :
    • The first character must be an alphabetic or underscore ( _ ).
    • The identifier name must consist of only alphabetic characters, digits or underscores.
    • The reserved word cannot be used as identifier name.




    Types of Identifier :


    C++ provides the following types of identifiers :

    1. Standard Identifier :
                                           A type of identifier that has special meaning in C++ is known as standard identifier. 


    Example :

                cout and cin examples of standard identifiers.

        2.   User-defined Identifiers :


                                                             The type of identifier that is defined by the programmer
     to access memory location is known as user-defined identifiers.

    Example :

                   Some examples of user-defined identifiers are a, marks and age etc.

    Friday 10 July 2015

    White Spaces :

                             The white spaces are used in programs to increase readability. Different types of white spaces include space, tab and carriage return etc. C++ compiler ignores the white spaces. All statements of a program can be written on one line but it will be difficult to read. The white spaces makes the source program more readable. A single statement can be written on two or more lines or order to increase readability but it will remain same for the compiler. 




    Stephen Randy Davis pdf :


    C++,khgamujtaba,programming book,C++ How to program

    Stephen Randy Davis pdf Downlaod


    Token :

                 A token is a language element that is used to form a statement.C++ statement may consist of different tokens.Different types of tokens are as follows :

    • Keywords: Keywords is a word in C language that has predefined meaning and purpose.

    Example:   For               Double             if                 const


    • Identifiers: Identifiers is the name of a variable or function etc.It is also called user-defined word.

    Example:   Student_age           counter             good20                


    • Constants: Constant is a quantity that cannot be changed during execution of a program.

    Example:   113           420               800.4             -300.5      'e'         '%'





    • String literals: A collection of characters written in double quotations is called string or string literal. 

    Example:  "This is a string constant"              "300"             "99-Mall Road."


    • Operators: Operator is a symbol that performs some operation.It acts on different operands.

    Example:     +               -                    *               /             %


    • Special Symbol: Special symbol is a symbol that is used to separate two tokens.It is also called punctuators.

    Example:        [ ]             ( )            { }           ,            ;            .               :   



    Thursday 9 July 2015

    Microsoft Visual Studio :

    Introduction

    Microsoft Visual Studio is an integrated development environment (IDE) from Microsoft. It is used to develop computer programs for Microsoft Windows, as well as web sites, web applications and web services.




    Microsoft Visual Studio includes a code editor Visual Studio supports different programming languages and allows the code editor and debugger to support (to varying degrees) nearly any programming language, provided a language-specific service exists. Built-in languages include C, C++and C++/CLI (via Visual C++), VB.NET (via Visual Basic .NET), C# (via Visual C#), and F# (as of Visual Studio 2010). Support for other languages such as M, Python, and Ruby among others is available via language services installed separately. It also supports XML/XSLT, HTML/XHTML, JavaScript and CSS. Java (and J#) were supported in the past. (the code completion component) as well as code refactoring. The integrated debugger works both as a source-level debugger and a machine-level debugger. Other built-in tools include a forms designer for building GUI applications, web designer, class designer, and database schema designer.