Saturday 24 September 2011

Single Linked List Program


#include<iostream>
using namespace std;
class structures
{
        struct std
        {
        int rno;
        char name[20];
        struct std*link;
        }*head;
        int size;
        public:
        void getdata();
        void display();
        void insertbegin();
        void insertmiddle();
        void insertend();
        void delbegin();
        void dellast();
        void delmiddle();
        void search();
        structures()
        {
        head=NULL;
        }
};
void structures::getdata()
{
        struct std*t;
   cout<<"enter size \n";
   cin>>size;
   for(int i=0;i<size;i++)
   {
        t=new std;
        cout<<"\nenter roll no ";
        cin>>t->rno;
        cout<<"\nName is ";
        cin>>t->name;
        if(head==NULL)
        {
                 t->link=NULL;
                 head=t;
        }
        else
        {
                 t->link=head;
                 head=t;
        }
    }
}
void structures::insertbegin()
{
 struct std*t;
 t=new std;
 cout<<"\n Enter rollno ";
 cin>>t->rno;
 cout<<"Name is ";
 cin>>t->name;
 if(head==NULL)
 {
  head=t;
 t->link=NULL;
 }
 else
 {
  t->link=head;
  head=t;
 }
}
void structures::insertmiddle()
{
        int no;
struct std*t;
t=new std;
cout<<"\n enter roll no";
cin>>t->rno;
cout<<"\nName ";
cin>>t->name;
cout<<"enter roll no after which the node to be inserted\n";
cin>>no;
std*p;
p=new std;
p=head;
while(p->rno!=no&p!=NULL)
p=p->link;
if(p!=NULL)
 {
 t->link=p->link;
 p->link=t;
 }
}
void structures::insertend()
{
 struct std*t;
 t=new std;
 cout<<"\n Enter Roll no ";
 cin>>t->rno;
 cout<<"\nName is ";
 cin>>t->name;
 if(head==NULL)
 {
  head=t;
  t->link=NULL;
 }
 else
 {
  std*p;
 p=new std;
 p=head;
 while(p->link!=NULL)
 p=p->link;
 p->link=t;
 t->link=NULL;
 }
}
void structures::delbegin()
{
 struct std*t;
 t=new std;
t=head;
head=head->link;
delete(t);
}
void structures::dellast()
{
 struct std*p,*t;
 p=new std;
 t=new std;
 p=head;
 while(p->link->link!=NULL)
 p=p->link;
 t=p->link;
 p->link=NULL;
 delete(t);
}
void structures::delmiddle()
{
 int no;
 cout<<"enter rno of node to be deleted";
 cin>>no;
 std*p,*t;
 p=head;
 while(p->link->link!=NULL&p->link->rno!=no)
 p=p->link;
 t=p->link;
 p->link=t->link;
 delete(t);
}
void structures::search()
{
 int r;
 std*p;
 p=new std;
 p=head;
 cout<<"enter rno of node to search ";
 cin>>r;
 while(p->rno!=r&p->link!=NULL)
 p=p->link;
if(p==NULL)
 {
 cout<<"\nElement not found \n";
 }
 else
 {
 cout<<"node is "<<p->name<<"\t"<<p->rno;
 }
}
void structures::display()
{
 std*p;
 p=new std;
 p=head;
 cout<<"\nStudent details are\n";
 while(p!=NULL)
 {
  cout<<"\nRoll No is "<<p->rno;
  cout<<"\n Name is "<<p->name;
  p=p->link;
 }
}
int main()
{
 structures ob;
 ob.getdata();
 int option,n=1;
while(n==1)
{
 cout<<"\n Enter option";

cout<<"\n1.insert begin\n2.insert middle\n3.insert end\n4.delete begin\n5.delete last\n6.delete  middle\n7.search\n8.display\n0.exit program\n";
cin>>option;
switch(option)
{
 case 1:
 ob.insertbegin();
 ob.display();
 break;
 case 2:
 ob.insertmiddle();
 ob.display();
 break;
 case 3:
 ob.insertend();
 ob.display();
 case 4:
 ob.delbegin();
 ob.display();
 case 5:
 ob.dellast();
 ob.display();
 case 6:
 ob.delmiddle();
 ob.display();
 case 7:
 ob.search();
 case 8:
 ob.display();
 case 0:
 n=0;
 break;
}
}
}

Friday 23 September 2011

BST Program


#include<iostream>
#include<cstdlib>
using namespace std;
struct node
{
        node* left;
        int val;
        node* right;
};
node* root=NULL;
class BST
{
        public:
        node* insert(node*,int);
        node* del(node*,int);
        bool search(node*,int);
        node* successor(node*);
        void preorder(node*);
        void postorder(node*);
        void inorder(node*);
};
node* BST::insert(node* t,int ele)
{
        node* p;
        p=new node;
        if(t==NULL)
        {
                p->val=ele;
                p->right=p->left=NULL;
                t=p;
        }
        else if(ele<t->val)
                t->left=insert(t->left,ele);
        else if(ele>t->val)
                t->right=insert(t->right,ele);
        return t;
}
node* BST::del(node* t,int ele)
{
        node* tmp;
        if(t==NULL)
        {
                cout<<"BST is empty.";
                return NULL;
        }
        else if(ele>t->val)
                t->right=del(t->right,ele);
        else if(ele<t->val)
                t->left=del(t->left,ele);
        else if(t->left!=NULL&&t->right!=NULL)
        {
                tmp=successor(t->left);
                t->val=tmp->val;
                t->left=del(t->left,t->val);
        }
        else
        {
                tmp=t;
                if(t->right==NULL)
                        t=t->left;
                else if(t->left==NULL)
                        t=t->right;
                free(tmp);
        }
        return t;
}
node* BST::successor(node* t)
{
        while(t->right!=NULL)
                t=t->right;
        return t;
}
bool BST::search(node* p,int ele)
{
        bool b;
        if(p==NULL)
                return false;
        else if(ele==p->val)
                return true;
        else if(ele>p->val)
                b=search(p->right,ele);
        else if(ele<p->val)
                b=search(p->left,ele);
        return b;
}
void BST::preorder(node* t)
{
        if(t!=NULL)
        {

                cout<<t->val<<"\t";
                if(t->left!=NULL)
                        preorder(t->left);
                if(t->right!=NULL)
                        preorder(t->right);

        }
}
void BST::postorder(node* t)
{
        if(t!=NULL)
        {
                if(t->left!=NULL)
                        postorder(t->left);
                if(t->right!=NULL)
                        postorder(t->right);
                cout<<t->val<<"\t";
        }
}
void BST::inorder(node* t)
{
        if(t!=NULL)
        {
                if(t->left!=NULL)
                        inorder(t->left);
                cout<<t->val<<"\t";
                if(t->right!=NULL)
                        inorder(t->right);
        }
}
int main()
{
        BST ob;
        int option,ele;
        bool b;
        while(1)
        {
                cout<<"\n1.Insert\n2.Delete\n3.Search\n4.Display in Pre Order\n5.Display in Post Order\n6.Display In Order\n7.Exit Program\n";
                cout<<"\nEnter your option:";
                cin>>option;
                switch(option)
                {
                        case 1:
                        {
                                cout<<"Enter the element to be inserted:";
                                cin>>ele;

                                root=ob.insert(root,ele);
                        }
                        break;
                        case 2:
                        {
                                cout<<"Enter the node to be deleted:";
                                cin>>ele;
                                root=ob.del(root,ele);
                        }
                        break;
                        case 3:
                        {
                                cout<<"Enter the element to be searched:";
                                cin>>ele;
                                b=ob.search(root,ele);
                                if(b==true)
                                        cout<<"Element found.";
                                else
                                        cout<<"Element not found.";
                        }
                        break;
                        case 4:ob.preorder(root);
                                break;
                        case 5:ob.postorder(root);
                                break;
                        case 6:ob.inorder(root);
                                break;
                        case 7:exit(1);
                }
        }
}

Queue Program using Linked List


#include<iostream>
#include<cstdlib>
using namespace std;
class queue
{
   public:
   struct node
     {
       int ele;
       struct node *link;
     };
   node *head;
   void insert(int);
   void del();
   queue()
     {
       head=NULL;
     }
   void display();
};
void queue::insert(int ele)
{
   node *t,*p;
   t=new node;
   t->ele=ele;
   t->link=NULL;
   p=new node;
   p=head;
   if(head==NULL)
       head=t;
   else
     {
        while(p->link!=NULL)
            p=p->link;
        p->link=t;
     }
}
void queue::del()
{
     node *p;
     if(head==NULL)
         cout<<"\nQueue is empty";
     else if(head->link==NULL)
       {
          delete head;
          head=NULL;
       }
     else
       {
          p=new node;
          p=head;
          head=p->link;
          delete p;
       }
}
void queue::display()
{
 node *p;
 p=new node;
 p=head;
 while(p!=NULL)
  {
     cout<<p->ele<<"\t";
     p=p->link;
 }
}
int main()
{
 queue ob;
 int ele,option;
 while(1)
   {
         cout<<"\n1.Insert\n2.Delete\n3.Display\n4.Exit program";
         cout<<"\nEnter your option: ";
         cin>>option;
         switch(option)
            {
                 case 1:
                   {
                       cout<<"\nEnter element to be inserted ";
                       cin>>ele;
                       ob.insert(ele);
                   }
                   break;
                 case 2:
                   ob.del();
                   break;
                 case 3:
                   ob.display();
                   break;
                 case 4:
                   exit(1);
           }
   }
}

Pstfix Evalution program


#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace std;
class posteval
{
  char postfix[30];
  int stack[30];
  int top;
  public:
  posteval()
    {
     top=-1;
    }
  void push(int);
  int pop();
  void eval();
};
void posteval::push(int ele)
{
  stack[++top]=ele;
}
int posteval::pop()
{
 return stack[top--];
}
void posteval::eval()
{
 int r,v1,v2;
 cout<<"Enter the postfix expression";
 cin>>postfix;
 for(int i=0;postfix[i]!='\0';i++)
  {
    int f=0;
    switch(postfix[i])
      {
        case '+':
          {
             v2=pop();
             v1=pop();
             r=v1+v2;
          }
          break;
        case '-':
          {
            v2=pop();
            v1=pop();
             r=v1-v2;
          }
          break;
        case '*':
          {
            v2=pop();
            v1=pop();
             r=v1*v2;
          }
          break;
        case '/':
          {
            v2=pop();
            v1=pop();
             r=v1/v2;
          }
         break;
        case '^':
          {
            v2=pop();
            v1=pop();
             r=pow(v1,v2);
          }
          break;
        default:
          {
             push(postfix[i]-48);
             f=1;
          }

     }
     if(f==0)
           push(r);
   }
   cout<<"\nResult of postfix evaluation is "<<stack[top]<<"\n";
}
int main()
{
  posteval ob;
  ob.eval();
}

Infix to Postfix Program


#include<iostream>
#include<cstdlib>
using namespace std;
class stackinpost
{
   char infix[30];
   char postfix[30];
   char stack[30];
   int top;
   public:
   stackinpost()
    {
      top=-1;
    }
   void push(char);
   char pop();
   int precedence(char);
   void intopost();
};
void stackinpost::push(char ele)
{
  stack[++top]=ele;
}
char stackinpost::pop()
{
   return stack[top--];
}
int stackinpost::precedence(char ele)
{
    switch(ele)
      {
        case '#':return -1;
        case '(':return 0;
        case '+':
        case '-':return 1;
        case '/':
        case '*':return 2;
        case '^':return 3;
      }
}
void stackinpost::intopost()
{
  char ch;
  stack[++top]='#';
  cout<<"\nEnter the infix expression";
  cin>>infix;
  int k=0;
  for(int i=0;infix[i]!='\0';i++)
    {
       switch(infix[i])
         {
          case '(':push(infix[i]);
          break;
          case ')':
            {
               ch=pop();
                 while(ch!='(')
                  {
                    postfix[k++]=ch;
                    ch=pop();
                  }
            }
         break;
         case '+':
         case '-':
         case '*':
         case '/':
         case '^':
           {
                int p;
                p=precedence(infix[i]);
                while(p<=precedence(stack[top]))
                     postfix[k++]=pop();
                push(infix[i]);
           }
         break;
         default:postfix[k++]=infix[i];
        }
    }
  while(stack[top]!='#')
        postfix[k++]=pop();
  postfix[k]='\0';
  cout<<"\nPostfix expression is \n";
  cout<<postfix;
}
int main()
{
  stackinpost ob;
  ob.intopost();
}

B5 Tour schedule


B5 Tour Details
On 17-09-2011 we book the tickets for touras per following details:-
TRAIN No
TRAIN NAME
FROM
TO
DISTANCE(KM)
DEPARTURE
ARRIVAL
08470
PURI GARIB RATH
VISAKHAPATNAM
PURI
468
20:40
05:50
12815
PURI NDLS EXPRESS
PURI
NIZAMUDDIN
1804
10:55
17:00
12816
PURI EXPRESS
NIZAMUDDIN
BBS
1732
06:30
10:30
18496
BBS RMM EXPRESS
BBS
VISAKHAPATNAM
443
12:00
19:10



On 20-09-2011 we discuss about tour planand travels with HOD it is as follows:-

TOUR PLANof B5 from 20-09-2011 to 2-09-2011



 

Tour Schedule:-
20-11-2011:-Visakhapatnamto Delhi journey
21-11-2011:-journey
22-11-2011:-Delhiarrival night halt
23-11-2011:-DelhiNight halt
24-11-2011:-Delhi-Agra-Delhinight halt
25-11-2011:-Hotelcheckout Night departure to Chandigarh
26-11-2011:-Chandigarh
27-11-2011:-ManaliNight halt
28-11-2011:-Rohtangpass Night departure for Shimla
29-11-2011:-Shimla
30-11-2011:-ShimlaNight departure for Delhi
01-12-2011:-Departurefrom Delhi journey to Visakhapatnam
02-11-2011:-arrivalat Visakhapatnam (19:10)

Thursday 22 September 2011



AIM: To calculate the frequency of the RC phase shift oscillator & to measure the phase angles at different RC sections.
  
                   1. Transistor BC107                        
                    2. Resistors:  10KΩ              -3Nos
                                           8KΩ or 10KΩ
                                           22KΩ                         
                                           1.2KΩ                        
                                           100KΩ                        
                  3. Capacitors:  0.001µf  – 3 Nos
1µf                    
                  4. Regulated power Supply  
                  5. CRO                                  


THEORY:
                 RC-Phase shift Oscillator has a CE amplifier followed by three sections of RC phase shift feed back Networks the out put of the last stage is return to the input of the amplifier. The values of R and C are chosen such that the phase shift of each RC section is 60º.Thus The RC ladder network produces a total phase shift of 180º between its input and output voltage for the given frequencies. Since CE Amplifier produces 180 º phases shift the total phase shift from the base of the transistor around the circuit and back to the base will be exactly 360º or 0º. This satisfies the Barkhausen condition for sustaining oscillations and total loop gain of this circuit is greater than or equal to 1, this condition used to generate the sinusoidal oscillations.
The frequency of oscillations of RC-Phase Shift Oscillator is,                                                               
                                                        
                                                                  1
                                                    f =     -----------
                                                             2pRC* √6

CIRCUIT DIAGRAM:

                                           

PROCEDURE:        
1.    Make the connection as per the circuit diagram as shown above.
2.    Observe the output signal and note down the output amplitude and time period (Td).
3.    Calculate the frequency of oscillations theoretically and verify it practically (f=1/Td).
4.     Calculate the phase shift at each RC section by measuring the time shifts (Tp) between the final waveform and the waveform at that section by using the below formula.     

OBSERVATIONS:

THEORITICAL CALCULATIONS:  R = 10K, C = 0.001 μf

                                               1                                     
                              f =     --------------     =     
                                          2pRC* √6       
PRACTICAL CALCULATIONS:          

                                      Td =

                                              1                                      
                                    f =     -----   
                                                Td                                   


                                               Tp1
                              (1). θ 1=  --------*360  =  
                                               Td                       

                                                 Tp2                         
                             (2).  θ 2 =  ------- * 3600  =    
                                                  Td                          

                                                 Tp3                              
                            (3). θ 3= ----------- *3600  =    
                                              T                   


MODEL WAVE FORMS:

OUT PUT WAVE FORM :




OUT PUT WAVE FORM : θ = 600


OUT PUT WAVE FORM : θ =  1200


OUT PUT WAVE FORM : θ =  180



RESULT:  The frequency of RC phase shift oscillator is calculated and the phase shift at different RC sections is noted.

VIVA QUESTIONS:

  1. What are the conditions of oscillations?
  2. Give the formula for frequency of oscillations?
  3. What is the total phase shift produce by the RC ladder network?
  4. Whether the oscillator is positive feedback or negative feedback?
  5. What are the types of oscillators?
  6.   What is the gain of RC phase shift oscillator?
  7.  What is the difference between damped oscillations undamped oscillations?
  8.  What are the applications of RC oscillations?
  9. How many resistors and capacitors are used in RC phase shift network
  10. How the Barkhausen criterion is satisfied in RC phase shift oscillator