Best Industrial Training in C,C++,PHP,Dot Net,Java in Jalandhar

Saturday, 27 July 2013

Working of Monitor

The cathode ray tube (CRT) is a vacuum tube containing one or more electron guns (a source of electrons or electron emitter) and a fluorescent screen used to view images.[1] It has a means to accelerate and deflect the electron beam(s) onto the screen to create the images. The images may represent electrical waveforms (oscilloscope), pictures (television, computer monitor), radar targets or others.


A CRT works by sweeping an electron beam of varying intensity across a phosphor-coated screen.  The basic components of the CRT are described below:
 
Electron Gun -- The electron gun, which consists of the cathode, choke, accelerator, and lensing region, is the device which generates and focuses the electron beam used to project an image on the phosphor screen.

Cathode -- The cathode is a grounded metal plate that is super-heated so that electrons are literally jumping off the surface.

Accelerator Plate -- This metal ring is held at a large, positive voltage and is used to "grab" loose electrons from the cathode and hurl them forwards into the lensing chamber (towards the right in the diagram).

Choke -- This metal ring is located between the cathode and accelerator plate and held at a slightly negative charge.  The electric fields from the choke help columnate the electrons; they also can be used to quickly modulate the number of electrons in the beam and, thus, the brightness or intensity of the picture.

Lensing Region -- The lensing region consists of two adjacent metal tubes that are located just after the accelerator. The two tubes are held at different potentials, causing an electrostatic lens to form at their junction.  The electrons that have jumped off the cathode begin to focus.  Ideally, the focal point will occur at the point when the beam strikes the display, thereby providing pinpoint resolution on the screen.  The last metal tube of the lensing chamber is held at the highest potential of all the electron gun components so that exiting electrons have a very high forward velocity.

Steering Magnets -- These two sets of electromagnets are fed the retrace signals that synchronize the drawing of the picture on the screen.  The flux between each pair of magnets will bend the electron beam, one in the horizontal direction and the other in the vertical direction.

Phosphor Screen -- If all works well, a pinpoint electron beam strikes the screen with the appropriate intensity and causes the phosphor to fluoresce.  The intensity modulation is synchronized with the horizontal and vertical retraces so that one frame of video is displayed.  The process repeats itself rapidly (24 frames/second for analog television) so that the moving scene appears seamless.


Please check below link for further refrence:
1.
http://www.youtube.com/watch?v=Gnl1vuwjHto

2.
http://www.youtube.com/watch?v=dlT-seESkj0

Monday, 22 July 2013

Manipulator Functions in C++

Manipulator Functions
Manipulator functions are special stream functions that change certain characteristics of the input and output. They change the format flags and values for a stream. The main advantage of using manipulator functions is that they facilitate that formatting of input and output streams.
     The following are the list of standard manipulator used in a C++ program. To carry out the operations of these manipulator functions in a user program, the header file input and output manipulator <iomanip.h> must be included.
 Predefined manipulators
Following are the standard manipulators normally used in the stream classes:
endl
hex, dec, oct
setbase
setw
setfill
setprecision
ends
ws
flush
setiosflags
resetiosflags
(a) Endl   the endl is an output manipulator to generate a carriage return or line feed character. Theendl may be used several times in a C++ statement.
     For example,
     (1)
          cout << “ a “ << endl << “b” << endl;
     (2)
          cout << “ a = “ << a << endl;
          cout << “ b = “ << b << endl;
  A program to display a message on two lines using the endl manipulator and the corresponding output is given below.
      / / using endl manipulator
      #include <iostream.h>
      Void main (void)
      {
           cout << “ My name is Komputer “;
           cout << endl;
           cout << “ many greetings to you “;
      }
Output of the above program
    My name is Komputer
    Many greetings to you
    The endl is the same as the non-graphic character to generate line feed (\n).
    A program to illustrate the usage of line feed character and the endl manipulator and the corresponding output are given below.
     #include <iostream.h>
     void main ( )
     {
         int a;
         a = 20;
        cout << “ a = “<< a << endl;
        cout << “ a = “<< a <<   “\n”;
        cout << “ a = “<< a <<    ‘\n’;
    }
Output of the above program
    a = 20
    a = 20
    a = 20
(b) Setbase()  The setbase() manipulator is used to convert the base of one numeric value into another base. Following are the common base converters in C++.

dec   - decimal base (base = 10)
hex   - hexadecimal base (base = 16)
oct   - octal base (base = 8)
  In addition to the base conversion facilities such as to bases dec, hex and oct, the setbase()manipulator is also used to define the base of the numeral value of a variable. The prototype ofsetbase() manipulator is defined in the iomanip.h header file and it should be include in user program. The hex,    dec,    oct manipulators change the base of inserted or extracted integral values. The original default for stream input and output is dec.

PROGRAM 
A program to show the base of a numeric value of a variable using hex,  oct and dec manipulator functions.
     / / using dec, hex, oct manipulator
     #include <iostream.h>
     Void main (void)
{
       int   value;
       cout  << “ Enter number’ << endl;
       cin >> value;
       cout << “ Decimal base = “ << dec << value << endl;
       cout << “ Hexadecimal base = “ << hex << value << endl;
       cout << “ Octal base = “ << oct << value << endl;
    }
Output of the above program
    Enter number
    10
    Decimal base = 10
    Hexadecimal base = a
    Octal base = 12

PROGRAM
A program to show the base of a numeric value of a variable using setbase manipulator function.
    / /using setbase manipulator
    #include <iostream.h>
    #include <iomanip.h>
    void main (void)
    {
         int    value
         cout << “ Enter number” << endl;
         cin >> value;
         cout << “ decimal base = “ << setbase (10)
         cout << value << endl;
         cout << “ hexadecimal base = “ << setbase (16);
         cout << value << endl;
         cout << “ Octal base = “ << setbase (8) << value << endl;
    }
The output of this program is the same as the output of program 2.2
(c)   Setw ()  The setw ( ) stands for the set width. The setw ( ) manipulator is used to specify the minimum number of character positions on the output field a variable will consume.
     The general format of the setw manipulator function is
                       setw( int w )
Which changes the field width to w, but only for the next insertion. The default field width is 0.
    For example,
           cout << setw (1) << a << endl;
           cout << setw (10) << a << endl;
   Between the data variables in C++ space will not be inserted automatically by the compiler. It is upto a programmer to introduce proper spaces among data while displaying onto the screen.

 PROGRAM 
A program to display the content of a variable without inserting any space.
    #include <iostream.h>
    void main (void)
    {
        int   a,b;
        a = 200;
        b = 300;
        cout << a << b << endl;
    }
Output of the above program
200300

PROGRAM 
A program to insert a tab character between two variables while displaying the content onto the screen.
        / /using setw manipulator
        #include <iostream.h>
        #include <iomanip.h>
        void main (void)
        {
            int  a,b;
            a = 200;
            b = 300;
            cout << a << ‘\t’ << b << endl;
        }
Output of the above program
200     300

PROGRAM 
A program to display the data variables using setw manipulator functions.
       / /using setw manipulator
       #include <iostream.h>
       #include <iomanip.h>
       void main (void)
       {  
           int  a,b;
           a = 200;
           b = 300;
          cout << setw (5) << a << setw (5) << b << endl;
          cout << setw (6) << a << setw (6) << b << endl;
          cout << setw (7) << a << setw (7) << b << endl;
          cout << setw (8) << a << setw (8) << b << endl;
       }
Output of the above program
    200         300
      200         300
        200         300
          200         300
(d)  Setfill() The setfill ( ) manipulator function is used to specify a different character to fill the unused field width of the value.
    The general syntax of the setfill ( ) manipulator is
                     setfill( char f)
which changes the fill character to f. The default fill character is a space.
For example,
       setfill ( ‘ . ’ ) ; / / fill a dot ( . ) character
       setfill ( ‘ * ’ ) / / fill a asterisk (*) character
PROGRAM 
A program to illustrate how a character is filled in filled in the unused field width of the value of the data variable.
      / /using setfill manipulator
      #include <iostream.h>
      #include <iomanip.h>
      void main ( void)
      {
          int   a,b;
          a = 200;
          b = 300;
          cout << setfill ( ‘ * ’ );
          cout << setw (5) << a << setw (5) << b << endl;
          cout << setw (6) << a << setw (6) << b << endl;
          cout << setw (7) << a << setw (7) << b << endl;
          cout << setw (8) << a << setw (8) << b << endl;
     }
Output of the above program
    **200**300
    ***200***300
    ****200****300
    *****200*****300
(e) Setprecision()  The setprecision ( ) is used to control the number of digits of an output stream display of a floating point value. The setprecision ( ) manipulator prototype is defined in the header file <iomanip.h>.
      The general syntax of the setprecision manipulator is
                       Setprecision (int p)
      Which sets the precision for floating point insertions to p. The default precision is 6       

PROGRAM 
A program to use the setprecision manipulator function while displaying a floating point value onto the screen.
     / /using setprecision manipulator
     #include <iostream.h>
     #include <iomanip.h>
     void main (void)
     {
        float  a,b,c;
        a = 5;
        b = 3;
        c = a/b;
        cout << setprecision (1) << c << endl;
        cout << setprecision (2) << c << endl;
        cout << setprecision (3) << c << endl;
        cout << setprecision (4) << c << endl;
        cout << setprecision (5) << c << endl;
        cout << setprecision (6) << c << endl;
    }
Output of the program
    1.7
    1.67
    1.667
    1.6667
    1.66667
    1.666667

(f)  Ends  The ends is a manipulator used to attach a null terminating character (‘\0’) at the end of a string. The ends manipulator takes no argument whenever it is invoked. This causes a null character to the output.
  
PROGRAM 
A program to show how a null character is inserted using ends manipulator while displaying a string onto the screen.
      / /using ends manipulator
      #include <iostream.h>
      #include <iomanip.h>
      Void main ( )
   
  {
      int number = 231;
      cout << ‘ \ ” ’ << “ number = “ << number << ends;
      cout << ‘ \ “ ‘ << endl;
  }
Output of the above program
      “ number = 123 “
(g) Ws  The manipulator function ws stands for white space. It is used to ignore the leading white space that precedes the first field.
        / /using ws manipulator
        #include <iostream.h>
        #include <iomanip.h>
        Void main ( )
        {
            char name [100]
            cout << “ enter a line of text \n”;
            cin >> ws;
            cin >> name;
            cout  << “ typed text is = “ << name << endl;
       }
 Output of the program
        enter a line of text
        this is a text
        typed text is = this
(b)  Flush   The flush member function is used to cause the stream associated with the output to be completed emptied. This argument function takes no input prameters whenever it is invoked. For input on the screen, this is not necessary as all output is flushed automatically. However, in the case of a disk file begin copied to another, it has to flush the output buffer prior to rewinding the output file for continued use. The function flush ( ) does not have anything to do with flushing the input buffer.
        / /using flush member function
        #include <iostream.h>
        #include <iomanip.h>
        void main ( )
        {
             cout << “ My name is Komputer \n”;
             cout << “ many greetings to you \n”;
             cout . flush ( ) ;
        }
The hex, dec, oct, ws, endl, ends and flush manipulators are defined in stream.h. The other manipulators are defined in iomanip.h which must be included in any program that employs them.

(i)  Setiosflags and Resetiosflags  The setiosflags manipulator function is used to control different input and output settings. The I/O stream maintains a collection of flag bits.
       The setiosflags manipulator performs the same function as the setf function.
The flags represented by the set bits in f are set.
        The general syntax of the setiosflags is,
              setiosflags ( long h)
    The restiosflags manipulator performs the same function as that of the resetf function. The flags represented by the set bits in f are reset.
    The general syntax of the resetiosflags is a follows,
            Resetiosflags (long f) 
  
PROGRAM 

A program to demonstrate how setiosflags is set while displaying the base of a numeral.
    / /using setiosflags of basefield
    #include <iostream.h>
    #include <iomanip.h>
    void main (void)
     {
          int  value;
          cout << “ enter a number \n”;
          cin  >>  value;
          cout << setiosflags (ios : : showbase) ;
          cout << setiosflags (ios : : dec) ;
          cout << “ decimal = “ << value << endl;
          cout << setiosflags (ios : : hex) ;
          cout << hexadecimal = “ << value << endl ;
          cout << setiosflags (ios : : oct) ;
          cout << “ octal = “ << value << endl ;
      }
Output of the above program
     enter a number
     10
     decimal = 10  
     hexadecimal = 0xa
     octal = 012

Program in C++ to find addition of time in hours and mintues

#include<iostream>
using namespace std;
class Time
{
private:
int h,m;
public:
void get(int x,int y)
{
h=x;
m=y;
}
void disp()
{
cout<<h<<":"<<m<<"\n";
}
void add(Time t1,Time t2)
{
m=t1.m+t2.m;
h=m/60;

m=m%60;
h=h+t1.h+t2.h;
}
};
int main()
{
Time t1;
t1.get(3,45);
Time t2;
t2.get(2,30);
Time t3;

t3.add(t1,t2);
t1.disp();
t2.disp();
t3.disp();
return 0;

}


Output:
Executing the program....

3:45
2:30
6:15

Thursday, 18 July 2013

Standard Output (cout) and Input(cin)

In C++, I/O is performed by using streams. A stream is a “stream of data” in which character sequences are “flow into” or “flow out off.” A stream is an object with properties that are defined by a class. Global objects are predefined for the standard I/O channels.
The header file iostream must be included to make use of the input/output (cin/cout) operators.

Standard Output (cout)

By default, the standard output of a program points at the screen. So with the cout operator and the “insertion” operator (<<) you can print a message onto the screen. Let’s take a look at an example:

	#include<iostream>
	using namespace std;

	int main()
	{
		cout << "Hello World!";
		return 0;
	}

Note:the double quotes around Hello World (because it is a constant string of characters.)
To print the content of a variable the double quotes are not used. Take a look at an example:

	#include<iostream>
	using namespace std;

	int main()
	{
		char Yes = ‘y';
		cout << Yes;
		return 0;
	}

Note: If you don’t want to use the namespace std, you could write std::cout << Yes
The << operator can be used multiple times in a single statement. Take a look at an example:

	#include<iostream>
	using namespace std;

	int main()
	{
		cout << "Hello, " << "this is a test " << "string.";
		return 0;
	}

Note: the use of the white spaces. (Otherwise the sentence: “Hello, this is a test string.” will be printed like this “Hello,this is a test string.”.)
It is possible to combine variables and text:

	#include<iostream>
	using namespace std;

	int main()
	{
		char Yes = ‘y';
		cout << "Print the character " << Yes;
		return 0;
	}

The cout operator does not put a line break at the end of the output. So if you want to print two sentences you will have to use the new-line character ( \n ).
For example:
	
        cout << "This is one sentence.\n";
	cout << "This is another.\n";

It is possible to use the endl manipulator instead of the new-line character.
For example:
	
        cout << "This is one sentence." << endl;
	cout << "This is another." << endl;

The endl manipulator will place a new-line character, so the result is the same. The difference is that the endl manipulator will also flush the buffer when you are in buffered mode. (In most cases the cout will be an unbuffered stream, so you could use the \n or endl, without any difference in behavior.)

Standard input (cin)

In most cases the standard input device is the keyboard. With the cin and >> operators it is possible to read input from the keyboard.
Take a look at an example:

	#include<iostream>
	using namespace std;

	int main()
	{
		char MY_CHAR;
		cout << "Press a character and press return: ";
		cin >> MY_CHAR;
		cout << MY_CHAR;
		return 0;
	}

Note: The input is processed by cin after the return key is pressed.
The cin operator will always return the variable type that you use with cin. So if you request an integer you will get an integer and so on. This can cause an error when the user of the program does not return the type that you are expecting. (Example: you ask for an integer and you get a string of characters.) Later on we will offer a solution to this problem.
The cin operator is also chainable. For example:
	
       cin >> XX >> YY;

In this case the user must give two input values, that are separated by any valid blank separator (tab, space or new-line).

Differences between 'break' and 'continue' statements

1. break is a keyword used to terminate the loop or exit from the block.The control jumps to next statement after the loop or block. 
1. continue is a keyword used for skipping the current iteration and go to next iteration of the loop.

 2.Syntax: { Statement 1; Statement 2; Statement n; break; }
 2.Syntax: { Statement 1; continue; Statement 2; }

 3. break can be used with for, while, do- while, and switch statements. When break is used in nested loops          i.e. within the inner most loop then only the innermost loop is terminated.
 3. This statement when occurs in a loop does not terminate it but skips the statements after this continue          statement. The control goes to the next iteration. continue can be used with for, while and do-while.

 4. Example: i = 1, j = 0; while(i<=5) { i=i+1; if(i== 2)break; j=j+1; }
 4. Example: i = 1, j = 0; while(i<=5) { i=i+1; if(i== 2)  continue; j=j+1; }

Monday, 15 July 2013

Static Function in C++

We can define class members static using static keyword. When we declare a member of a class as static it means no matter how many objects of the class are created, there is only one copy of the static member.
A static member is shared by all objects of the class. All static data is initialized to zero when the first object is created, if no other initialization is present. We can't put it in the class definition but it can be initialized outside the class as done in the following example by redeclaring the static variable, using the scope resolution operator :: to identify which class it belongs to.
Let us try the following example to understand the concept of static data members:
#include <iostream>
 
using namespace std;

class Box
{
   public:
      static int objectCount;
      // Constructor definition
      Box(double l=2.0, double b=2.0, double h=2.0)
      {
         cout <<"Constructor called." << endl;
         length = l;
         breadth = b;
         height = h;
         // Increase every time object is created
         objectCount++;
      }
      double Volume()
      {
         return length * breadth * height;
      }
   private:
      double length;     // Length of a box
      double breadth;    // Breadth of a box
      double height;     // Height of a box
};

// Initialize static member of class Box
int Box::objectCount = 0;

int main(void)
{
   Box Box1(3.3, 1.2, 1.5);    // Declare box1
   Box Box2(8.5, 6.0, 2.0);    // Declare box2

   // Print total number of objects.
   cout << "Total objects: " << Box::objectCount << endl;

   return 0;
}
When the above code is compiled and executed, it produces following result:
Constructor called.
Constructor called.
Total objects: 2

Static Function Members:

By declaring a function member as static, you make it independent of any particular object of the class. A static member function can be called even if no objects of the class exist and the static functions are accessed using only the class name and the scope resolution operator ::.
A static member function can only access static data member, other static member functions and any other functions from outside the class.
Static member functions have a class scope and they do not have access to the this pointer of the class. You could use a static member function to determine whether some objects of the class have been created or not.
Let us try the following example to understand the concept of static function members:
#include <iostream>
 
using namespace std;

class Box
{
   public:
      static int objectCount;
      // Constructor definition
      Box(double l=2.0, double b=2.0, double h=2.0)
      {
         cout <<"Constructor called." << endl;
         length = l;
         breadth = b;
         height = h;
         // Increase every time object is created
         objectCount++;
      }
      double Volume()
      {
         return length * breadth * height;
      }
      static int getCount()
      {
         return objectCount;
      }
   private:
      double length;     // Length of a box
      double breadth;    // Breadth of a box
      double height;     // Height of a box
};

// Initialize static member of class Box
int Box::objectCount = 0;

int main(void)
{
  
   // Print total number of objects before creating object.
   cout << "Inital Stage Count: " << Box::getCount() << endl;

   Box Box1(3.3, 1.2, 1.5);    // Declare box1
   Box Box2(8.5, 6.0, 2.0);    // Declare box2

   // Print total number of objects after creating object.
   cout << "Final Stage Count: " << Box::getCount() << endl;

   return 0;
}
When the above code is compiled and executed, it produces following result:
Inital Stage Count: 0
Constructor called.
Constructor called.
Final Stage Count: 2