Source Code : Interfaces and control statement In C++

Interfaces:

  An interface describes the behavior or capabilities of a C++ class without committing to a particular implementation of that class.

The C++ interfaces are implemented using abstract classes and these abstract classes should not be confused with data abstraction which is a concept of keeping implementation details separate from associated data.

  A class is made abstract by declaring at least one of its functions as pure virtual function.

E.g:

class Box

{

public:

// pure virtaul function

virtual double getVolume() = 0;

private:

double length; // Length of a box

double breadth; // Breadth of a box

double height; // Height of a box

};

Operators

ØArithmetic (+,-,*,/,%)

ØRelational (<,>,<=,>=,==,!=)

ØLogical (&&,||,!)

ØBitwise (&,|)

ØAssignment (=)

ØCompound assignment(+=,*=,-=,/=,%=,&=,|=)

ØShift (right shift >>, left shift <<)

For loops

The syntax of for loop is

for(initialisation;conditionchecking;increment)

{  set of statements

}

E.g:  #include <iostream>

  using namespace std;

  int main ()

  {

  // for loop execution

  for( int a = 10; a < 20; a = a + 1 )

  {

  cout << "value of a: " << a << endl;

  }

  return 0;

  }

While Loop

The syntax for while loop

  while(condition)

  {

  statements;

  }

Eg:  int a = 10;

  // while loop execution

  while( a < 20 )

  {

  cout << "value of a: " << a << endl;

  a++;

  }

  return 0;

Do While Loop

The syntax of do while loop

do

{

  set of statements

}while(condn);

E.g:do

{

  cout << "value of a: " << a << endl;

  a = a + 1;

  if( a > 15)

  {

  break;

  }

  }while( a < 20 );

  return 0;

}

nested loops

A loop can be nested inside of another loop. C++ allows at least 256 levels of nesting.

Syntax:

The syntax for a nested for loop statement in C++ is as follows:

for ( init; condition; increment )

{

for ( init; condition; increment )

{

statement(s);

}

statement(s); // you can put more statetments.

}

The syntax for a nested while loop statement in C++ is as follows:

while(condition)

{

while(condition)

{

statement(s);

}

statement(s); // you can put more statetments.