Sunday, October 30, 2016

Simple Program Book Entry Using structure Variable in C++ Programming

Example Program

#include<iostream.h>
#include<stdio.h>

struct books
{
    char name[20],author[20];
}a[50];
int main()
{
    
    int i,n;
    cout<<"No Of Books[less than 50]:";
    cin>>n;
cout<<"Enter the book details\n";
cout<<"----------------------\n";
    
    for(i=0;i<n;i++)
    {
 cout<<"Details of Book No "<<i+1<<"\n";
 cout<<"Book Name :";
 cin>>a[i].name;
 cout<<"Book Author :";
 cin>>a[i].author;
 cout<<"----------------------\n";
    }
    cout<<"================================================\n";
    cout<<" S.No\t| Book Name\t|author\n";
    cout<<"=====================================================";
    for(i=0;i<n;i++)
    {
 cout<<"\n  "<<i+1<<"\t|"<<a[i].name<<"\t| "<<a[i].author;
    }
    cout<<"\n=================================================";
    
    return 0;
}



Sample Output

No Of Books[less than 50]:2
Enter the book details
----------------------
Details of Book No 1
Book Name :Programming
Book Author :Dromy
Details of Book No 2
Book Name :C
Book Author :Byron
=======================================================
 S.No | Book Name |author
=======================================================
  1 |Programming | Dromy
  2 |C | Byron
=======================================================

Simple Program for Static Data and Member Function Using C++ Programming

 To count the object value using the storage keyword static.

ALGORITHM: 

STEP 1:  Start the program.

STEP 2:  Declare the class name as Stat with data member s and member functions.
STEP 3:  The constructor Stat() which is used to increment the value of count as 1 to to assign the variable code.
STEP 4:  The function showcode() to display the code value.
STEP 5:  The function showcount() to display the count value.

STEP 6:   Stop the program.



PROGRAM: by abglobe.blogspot.com

#include<iostream.h>
#include<conio.h>
class stat
{
    int code;
    static int count;
   public:
    stat()
    {
      code=++count;
    }
    void showcode()
    {
      cout<<"\n\tObject number is :"<<code;
    }
    static void showcount()
    {
              cout<<"\n\tCount Objects :"<<count;
    }
};

int stat::count;
void main()
{
   clrscr();

   stat obj1,obj2;
   obj1.showcount();

   obj1.showcode();

   obj2.showcount();

   obj2.showcode();

   getch();
}

Output: 

Count Objects: 2

Object Number is: 1
Count Objects: 2
Object Number is: 2

thanks for watching!!!!!!

any problem please comment @

Simple Program for Friend Function Using C++ Programming

To find the mean value of a given number using friend function.

ALGORITHM:

STEP 1:  Start the program.
STEP 2:  Declare the class name as Base with data members and member functions.
STEP 3:  The function get() is used to read the 2 inputs from the user.
STEP 4:  Declare the friend function mean(base ob) inside the class.
STEP 5:  Outside the class to define the friend function and do the following.
STEP 6:  Return the mean value (ob.val1+ob.val2)/2 as a float.
STEP 7:  Stop the program.



#include<iostream.h>

#include<conio.h>

class  base

{
    int val1,val2;

   public:

    void get()
    {
       cout<<"Enter two values:";

       cin>>val1>>val2;
    }
    friend float mean(base ob);
};

float mean(base ob)
{
   return float(ob.val1+ob.val2)/2;
}

void main()

{
    clrscr();

    base obj;

    obj.get();

    cout<<"\n Mean value is : "<<mean(obj);

    getch();
}      


Output:

Enter two values: 10, 20
Mean Value is: 15

thanks for watching!!!!!!

any problem please comment @

    

Simple Program for Binary Operator Overloading Using C++ Programming

To write a program to add two complex numbers using binary operator overloading.

ALGORITHM:

Step 1: Start the program.

Step 2: Declare the class.
Step 3: Declare the variables and its member function.
Step 4: Using the function getvalue() to get the two numbers.
Step 5: Define the function operator +() to add two complex numbers.
Step 6: Define the function operator –()to subtract two complex numbers.
Step 7: Define the display function.
Step 8: Declare the class objects obj1,obj2 and result.
Step 9: Call the function getvalue using obj1 and obj2
Step 10: Calculate the value for the object result by calling the function operator + and     operator -.
Step 11: Call the display function using obj1 and obj2 and result.
Step 12: Return the values.
Step 13: Stop the program.

PROGRAM:

#include<iostream.h>
#include<conio.h>
class complex
 {
    int a,b;

     public:

      void getvalue()
        {

          cout<<"Enter the value of Complex Numbers a,b:";

          cin>>a>>b;

        }

          complex operator+(complex ob)

           {

              complex t;

              t.a=a+ob.a;

              t.b=b+ob.b;

              return(t);
            }

              complex operator-(complex ob)

              {

                 complex t;

                 t.a=a-ob.a;

                 t.b=b-ob.b;

                 return(t);
              }

                void display()

              {

                            cout<<a<<"+"<<b<<"i"<<"\n";

              }
 };

    void main()

     {

       clrscr();

       complex obj1,obj2,result,result1;
       obj1.getvalue();

       obj2.getvalue();
       result = obj1+obj2;

       result1=obj1-obj2;
       cout<<"Input Values:\n";

       obj1.display();

       obj2.display();
  
       cout<<"Result:";

       result.display();

       result1.display();
  
       getch();
     }

Output:


Enter the value of Complex Numbers a, b
4                  5

Enter the value of Complex Numbers a, b
2                  2

Input Values
4 + 5i
2 + 2i

Result
6 +   7i
2 +   3i

thanks for watching!!!!!!

any problem please comment @

CONSTRUCTORS AND TYPES


C++ Provides a special member function called constructor that enables an object to initialize itself when it is created.This is know as automatic initialization of objects.

it special function because its name is same as the class name.The constructor is invoked whenever an object of its associated class is created.
A Constructor is declared and defined as follows :


                                                      class student
                                                       {
                                                       private:
                                                                   int roll no;
                                                                   int marks;
                                                       public:
                                                                    student( )             // default constructor defined
                                                                     {
                                                                             roll no=0;
                                                                             marks=0;
                                                                      }
                                                        };
                                                         void main( )
                                                          {
                                                                 student s;                  // object s created
                                                           }
                                                   

                         in this example, the declaration
                                                                             
                                                                               student s;
 not only created the object s of type student but also initialize its data members roll no,marks to zero.

characteristics of a constructor


* A constructor name must be the same as that of its class name.
* it is declared with no return type(not even void)
* it is declared in public section of the class.
* it can have default arguments.
* it can not refer to its own address.
* it may not be static.
* it may not be virtual.
* it can not be inherited.


types of constructors

there are three types of constructors 


1. default constructors

2. parameterized constructors

3. copy constructors

1.  Default Constructor:-  Default Constructor is also called as Empty Constructor which has no arguments and It  is Automatically called when we creates the object of class  but Remember name of Constructor is same as name of class and Constructor never declared with the help of Return Type. Means we cant Declare a Constructor with the help of void Return Type. , if we never Pass or Declare any Arguments then this called as the Copy Constructor.

/*  Example Program For Simple Example Program Of default Constructor In C++

 #include <iostream.h>
 #include<conio.h>
       class Defal
           {
            public:

            int x;    // Variable Declaration

            int y;

            Defal(){x=y=0;}    //default constructor
                           
          };

          int main()
           {
           Defal A;

            cout << "Default constructs x,y value::"<<

            A.x <<" , "<< A.y << "\n";

            return 0;
         }

2.  Parameterized Constructor :- This is Another type  Constructor which has some Arguments and same name as class name but it uses some Arguments So For this We have to create object of Class by passing some Arguments at the time of creating object with the name of class. When we pass some Arguments to the Constructor then this will automatically pass the Arguments to the Constructor and the values will retrieve by the Respective Data Members of the Class.

/*  Example Program For Simple Example Program Of Parameterized Constructor In C++   

    Coded By:abglobe.blogspot.com             */

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

using namespace std;

class Example        {
   
int a,b;  // Variable Declaration
    public:

    
    Example(int x,int y)  //Constructor           
    {
    
    a=x;       // Assign Values In Constructor

    b=y;

    cout<<"Im Constructor\n";
    }

    void Display()
    {

    cout<<"Values :"<<a<<"\t"<<b;
    
    }

  };

       int main()        
        {

           Example Object(10,20);
        
           Object.Display();   // Constructor invoked

           getch();  // Wait For Output Screen
           
           return 0;
         
         }


3.  Copy Constructor:- This is also Another type of Constructor. In this Constructor we pass the object of class into the Another Object of Same Class. As name Suggests you Copy, means Copy the values of one Object into the another Object of Class .This is used for Copying the values of class object into an another object of class So we call them as Copy Constructor and For Copying the values We have to pass the name of object whose values we wants to Copying and When we are using or passing an Object to a Constructor then we must have to use the & Ampersand or Address Operator.

/*  Example Program For Simple Example Program Of Copy Constructor Overloading In C++

    Coded By:abglobe.blogspot.com             */

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

using namespace std;

class Example        
{
    
    int a,b;  // Variable Declaration
    public:

    Example(int x,int y)   //Constructor with Argument
     {
    
    a=x;     // Assign Values In Constructor

    b=y;

    cout<<"\nIm Constructor";

    }

    void Display() 
    {

    cout<<"\nValues :"<<a<<"\t"<<b;

    }
 };

int main() 
               {
    Example Object(10,20);

       
        Example Object2=Object;   //Copy Constructor

        

        Object.Display();     // Constructor invoked.

        Object2.Display();

        getch();   // Wait For Output Screen

        return 0;
}

thanks for watching!!!!!!

any problem please comment @

Monday, April 4, 2016

CYCLOTRON WORKING PRINCIPLE

Cyclotron Working Principle

It is a device developed by Lawrence and Livingstone and is used to accelerate charged particles like protons and deuterons. This results in the production of high energy beam which is then used for artificial disintegration, etc.
It consists of two D shaped metal boxes (about 21″ in diameter) with their straight sides facing each other. There is a very small gap between these Dee’s faces across which a high potential difference (of order of 105 volts) is applied by a high frequency (10-15 mega cycles per second) oscillator. Thus an alternating electric field is established between Dee’s  during one half cycle, one dee is positive and the other is negative while during the next half cycle, the other is positive and one is negative. A source of particle (heavy hydrogen for producing deutrons) is placed between the faces. The whole apparatus is placed between the pole pieces NS of a very strong magnet.

Suppose a deuteron is at the centre of the gap and D1 is at negative potential compared to D2 then deuterons will be accelerated by the electric field between the dees towards D1. Since magnetic field B is perpendicular to the direction of motion of deuteron, a force will act on the particle given by
F = qv x B (where v and B are vectors) = qvB
Consequently, particle moves along a circular path whose radius is given by
So time period and frequency is independent of speed of charge and radius of circular path. If this frequency is equal to the frequency of the oscillator then by the time particle complete half revolution the polarity of the field will change. Deuteron will again be accelerated across the gap, its velocity will increase so that now it will move in a circular path of greater radius but its frequency will not be affected and the process of acceleration continues.
The particle is thus accelerated to gain high velocity. Its kinetic energy increases and when radius of the path reaches upto the value of the radius of the dee (R), beam is deflected by a negatively charged plate. Therefore with r=R, its maximum kinetic energy will be
So the necessary condition for accelerating the deuterons is
f=fo

where f0 is oscillator frequency. This is called resonance condition.

As velocity attained is high, we choose heavier particles e.g., protons, deuterons for acceleration in cyclotron. The reason is that at such high velocities, mass varies with velocity and f will then depend on velocity, upsetting the resonance condition. This variation in mass is more marked in the case of lighter particles. So cyclotron is suitable only for accelerating heavy particle like protons, deuterons a – particles etc.
Electrons can not be accelerated by cyclotrons because the mass of electron is very small and a small increase in energy of electron makes the electrons move with very high speed. As a result of it the electron go quickly out of step with oscillating electric field, it is for these reasons that other accelerating machines such as synchrotron, betatron (for accelerating electrons) have been developed. Cyclotron can not be used for accelerating uncharged particle like neutrons.

Theory and Working

The charged particle (say a positively charged proton) is released near mid point of the face of one of the Dees. Being in the electric field from one Dee to another, it is accelerated by the electric force in the direction of electric field. As the particle enters the adjoining Dee, the magnetic force, being perpendicular to it, renders the charged particle to move along a semicircular path within the Dee. By the time, it emerges again in the narrow gap separating the two Dees, the electrical polarity of Dees changes so that the particle is again accelerated again with an increase in speed.





But as the speed of the particle has increased, the radius of curvature of the semicircular path increases in accordance with the formula :



r = mv/Bq ( where B is magnetic field , m is mass , v is velocity , q is charge )


For given charge, mass and magnetic field, the radius is proportional to the speed. Clearly, the charged particle begins to move in a larger semicircular path after every passage through the gap. By the time particle reaches the gap successively, electric polarity of Dees keeps changing ensuring that the charged particle is accelerated with an increase in speed. This process continues till the charged particle reaches the periphery and exits through the guide with high energy and bombards a given target being investigated. The description of different segments of the path of accelerated particle is given here :


1: Path is a straight line. Particle is accelerated due to electric force. Speed and kinetic energy of the particle increase.


2: Path is a semicircular curve. Particle is accelerated due to magnetic force. This acceleration is centripetal acceleration without any change in speed and kinetic energy of the particle.


3: Path is a straight line. Particle is accelerated due to electric force in the direction opposite to the direction as in case 1. Speed and kinetic energy of the particle increase by same amount as in the case 1.


4: Path is a semicircular curve of greater radius of curvature due to increased speed. Particle is accelerated due to magnetic force. This acceleration is centripetal acceleration without any change in speed and kinetic energy of the particle.


5: Path is a straight line. Particle is accelerated due to electric force in the direction opposite to the direction as in case 1. Speed and kinetic energy of the particle increase by same amount as in the case 1 or 3.



We see that the particle follows consecutive larger semicircular path due to increase in the speed at the end of semicircular journey. The resulting path of charged particle, therefore, is a spiral path – not circular.



Cyclotron in India


Variable Energy Cyclotron Centre (VECC) is located in Calcutta, India.The Centre building itself houses a 224 cm cyclotron, was the first of its kind in India, having been operational since 1977-06-16. It provides proton, deuteron, alpha particle and heavy ion beams of various energies to other institutions..

Limitations of Cyclotron


Only when the speed of the circulating ion is less than 'c' the speed of light, we find the frequency of revolution to be independent of its speed.
At higher speeds, the mass of the ion will increase and this changes the time period of the ion revolution. This results in the ion lagging behind the electric field and it eventually loses by collisions against the walls of the dees.
*The cyclotron is suitable for accelerating heavy charged particles but not electrons.
*Cyclotrons cannot accelerate in charged particles.
*It is not suited for very high kinetic energy.


thanks for watching!!!!!!

any problem please comment @