Object

*An object is a collective group of data and functions, and object has it's own behavior properties as well.

Object Oriented Programming

*Combines data and functions in a single object, data can be accessed only through the object's code.

Characters Used in C++:

  1. Letters: A....Z,a....z

  2. Decimal Digits: 0-9

  3. Special Characters:   ! @ # $ % ^ & * ( ) _ \ + = { > < } [ ] ' . blank

Data Types.

Defines the type of data that you can store in a variable or a constant.

There are 2 types of data type.

  1. Basic Data types : are data types readily available in c++ following are the basic data types:

    1. Inter type (int) (sub types are short int, int and long int. (This data type can store integers without decimal points)

    2. Floating point (float) (Decimal form eg. 123.5667 and exponent form eg. 1234.23 e 06) (stores number with decimal points.)

    3. Character Type (char) (non numeric data type can hold single alphanumeric character)

    4. Void Type(void) (Represents absence of data)

  2. 2.Derived data types : are data types that are created by the user : eg. an array, a structure, a class etc.

 

C++ Tokens:

A group of characters that logically belong together. Four types of tokens are there in C++:

  1. Identifiers  : Symbolic names that can be used for various data items such as a variable or constant.

  2. Keywords : A reserved word in C++, cannot be used as an identifiers.

  3. Constants  : A number which cannot change its value during the course of the program. 

  4. Variables   : A location in the computer's memory that is given a symbolic name and can change it's value when required.

Structure of a C++ program :

# include<header file>

main()

{

......

.....

.....

}

 

Comments in a C++ program:

// for single line comment.

/* for starting a group of comments that will end with  */

 

Basic Input/Output in C++

cin statement is used to accept something from the user in a variable.

e.g. cin >> a;

cout statement is used to display something to the user screen.

e.g. cout << "This is a trial";

 

Output manipulators

setw() : is an operator that can be inserted directly into input output statements. e.g. the manipulator setw(n) can be inserted in the cout statment to set the minimum field width on columns or characters for a variable x as shown belos:

    cout << setw(10) << x;

the above statements means that the contents of x are to be displayed in the space of 10 characters and are to be right aligned within that space.

endl : can be inserted into the cout statement at a place where it is desired to take rest of the display on to the next line.

 

 

Backslash character constant(escape sequence)

There are some backslash characters that you can inset in your cout statements to manipulate the output. Following is the list of these backslash characters:

               /t is used to insert a tab in the display.

               /b is used to insert a backspace to in the display.

               /a is used for a bell(alert)

               /n is used to insert a line break.

 

Operators.

An operator is a symbol or letter used to indicate a specific operation on variables in a program. There are four basic type of operators:

  1. Arithmetic operators: + ,  - , % , / , *

  2. Unary arithmetic operators: -- , ++

  3. Relational and Logical operators:    > , < , >= , <= ,  = = , !=   (relational),  &&, || , ! (Logical)

  4. Conditional Operator: (? :) (We have not use this operator.)

Flow of Control.

There are different C++ statements that you use for controlling the flow of the program:

Conditional Execution statements:

IF Condition

    if (condition)

    {

    ........

    ........

    }

    else

    {

    .......

    .......

    }

 

    ifs can be also nested within one another like below:

   

    if (condition)

    {

    ........

    ........

        if(condition)

        {

        .......

        .....

        }

        else

        {

        ......

        .....

        }

    }

    else

    {

    .......

    .......

    }

 

Switch Statement

    switch(month)

    {

        case 1:

                  cout <<"it is january";

                    break;

        case 2:

                  cout <<"it is february";

                    break;

        case 3:

                  cout <<"it is march";

                    break;

        default:

                  cout <<"it is april";

    }               

 

 

Repetitive execution(Loops) : are used to repeat a set of statements to perform an operation more then once. Following are the loops that we have used :

The while loop : does not execute at all if the condition is not met.

e.g.

        while(flag !='n')

        {

        cout << "Please enter flag:";

        cin >> flag;

        }

 

The do-while loop: executes at least once before checking the condition:

e.g.

        int i=10,a;

       do

        {

        cout << "Please enter a number:";

        cint >> a;

        i++;

        }while(i<10)

even though the initialization value of i is 10 the loop will run once.

 

The for loop

It is a count controlled loop, the program knows in advance how many times the loop is to be executed.

e.g.

for(i=0;i<20;i++)

{

cout << "this is display no." << i;

}

 

 

1