Saturday, 22 October 2011

Program on Selection Sort


#include<iostream>
#include<cstdlib>
using namespace std;
class sort
{
        int a[20];
        int n,t;
        public:
                void getdata();
                void selectionsort();
                void display();
};
void sort::getdata()
{
        cout<<"enter the number of elements in the array\n";
        cin>>n;
        cout<<"enter the elements\n";
        for(t=0;t<n;t++)
                cin>>a[t];
}
void sort::selectionsort()
{
        int small;
        for(int i=0;i<n-1;i++)
        {
                small=i;
                for(int j=i+1;j<n;j++)
                {
                        if(a[small]>a[j])
                        small=j;
                }
                int temp=a[i];
                a[i]=a[small];
                a[small]=temp;
        }
}
void sort::display()
{
        cout<<"the sorted list is\n";
        for(int i=0;i<n;i++)
        {
                cout<<a[i]<<"\t";
        }
}
int main()
{
        sort ob;
        int op;
        while(1)
        {
                cout<<"\nenter the option\n";
                cout<<"1.get data\n2.selection sort\n3.display\n4.exit\n";
                cin>>op;
                switch(op)
                {
                        case 1:
                                ob.getdata();
                                break;
                        case 2:
                                ob.selectionsort();
                                break;
                        case 3:
                                ob.display();
                                break;
                        case 4:
                                exit(1);
                }
        }
}



OUTPUT:-

enter the option
1.get data
2.selection sort
3.display
4.exit
1
enter the number of elements in the array
5
enter the elements
1
6
5
2
3

enter the option
1.get data
2.selection sort
3.display
4.exit
2

enter the option
1.get data
2.selection sort
3.display
4.exit
3
the sorted list is
1       2       3       5       6
enter the option
1.get data
2.selection sort
3.display
4.exit
4

Program on Bubble Sort


#include<iostream>
#include<cstdlib>
using namespace std;
class sort
{
        int a[20];
        int n,t;
        public:
                void getdata();
                void bubblesort();
                void display();
};
void sort::getdata()
{
        cout<<"enter the number of elements in the array\n";
        cin>>n;
        cout<<"enter the elements\n";
        for(t=0;t<n;t++)
                cin>>a[t];
}
void sort::bubblesort()
{
        for(int i=0;i<n-1;i++)
        {
                for(int j=0;j<n-1-i;j++)
                {
                        if(a[j]>a[j+1])
                        {
                                int temp=a[j];
                                a[j]=a[j+1];
                                a[j+1]=temp;
                        }
                }
        }
}
void sort::display()
{
        cout<<"the sorted list is\n";
        for(int i=0;i<n;i++)
        {
                cout<<a[i]<<"\t";
        }
}
int main()
{
        sort ob;
        int op;
        while(1)
        {
                cout<<"\nenter the option\n";
                cout<<"1.get data\n2.bubble sort\n3.display\n4.exit\n";
                cin>>op;
                switch(op)
                {
                        case 1:
                                ob.getdata();
                                break;
                        case 2:
                                ob.bubblesort();
                                break;
                        case 3:
                                ob.display();
                                break;
                        case 4:
                                exit(1);
                }
        }
}


OUTPUT:-


enter the option
1.get data
2.bubble sort
3.display
4.exit
1
enter the number of elements in the array
3
enter the elements
2
1
3

enter the option
1.get data
2.bubble sort
3.display
4.exit
2

enter the option
1.get data
2.bubble sort
3.display
4.exit
3
the sorted list is
1       2       3
enter the option
1.get data
2.bubble sort
3.display
4.exit
4

Wednesday, 19 October 2011

AMC Meeting Details



Lab Externals from 27-10-2011 to 2-11-2011
And Mid exams from 3-11-2011 to 5-11-2011.
Final exams from 14-11-2011 to 19-11-2011.

Prepare DS and BE subjects well.

HOD said That “at Present an average 14 members may fail in BE”, So be careful about BE

Prepare Well for Exams.
All the Best. 

Thursday, 13 October 2011

Program on insertion and deletion using pointers


#include<iostream>
using namespace std;
template<class T>
class linear_list
{
      T *p;
      int size;
      public:
             void set();
             T get();
             int getindex(T);
             void del(T);
             T findmax();
             T findmin();
             void empty();
             void display();
};
template<class T>
void linear_list<T>::set()
{
     cout<<"\nEnter size of array\n";
     cin>>size;
     p=new T[size];
     cout<<"\nEnter elements\n";
     for(int i=0; i<size; i++)
     cin>>*(p+i);
}
template<class T>
T linear_list<T>::get()
{
     if(size<1)
     {
               cout<<"\nList is empty";
               return -1;
     }
     else
     return *p;
}
template<class T>
int linear_list<T>::getindex(T ele)
{
     if(size<1)
     {
               cout<<"\nList is empty";
               return -1;
     }
     else
     {
         for(int i=0; i<size; i++)
         {
                 if(*(p+i)==ele)
                 return (i+1);
         }
     }
     return -1;
}
template<class T>
void linear_list<T>::del(T ele)
{
     int pos;
     pos=getindex(ele);
     for(int i=pos-1; i<size; i++)
     *(p+i)=*(p+i+1);
     size=size-1;
}
template<class T>
T linear_list<T>::findmax()
{
     int max=*p;
     for(int i=1; i<size; i++)
     {
             if(max<*(p+i))
             {
                            max=*(p+i);
             }
     }
     return max;
}
template<class T>
T linear_list<T>::findmin()
{
     int min=*p;
     for(int i=1; i<size; i++)
     {
             if(min>*(p+i))
             {
                            min=*(p+i);
             }
     }
     return min;
}
template<class T>
void linear_list<T>::empty()
{
     for(int i=0; i<size; i++)
     {
             *(p+i)=0;
     }
}
template<class T>
void linear_list<T>::display()
{
     cout<<"\nArray is\n";
     for(int i=0; i<size; i++)
     cout<<*(p+i)<<" ";
     cout<<"\n";
}
int main()
{
    int ele, pos, option, n=1;
    linear_list<int> ob;
    while(n==1)
    {
              cout<<"\nEnter option";
              cout<<"\n1 set element\n2 get element\n3 getindex of element\n4 delete an element \n5 find maximum element\n6 find minimum element\n7 empty the array\n0 exit program\n";
              cin>>option;
              switch(option)
              {
                            case 1:
                                 ob.set();
                                 ob.display();
                                 break;
                            case 2:
                                 ob.get();
                                 ob.display();
                                 break;
                            case 3:
                                 cout<<"\nEnter element to get index of\n";
                                 cin>>ele;
                                 pos=ob.getindex(ele);
                                 if(pos!=0)
                                 {
                                           cout<<"\nElement found at "<<pos;
                                 }
                                 else
                                 cout<<"\nElement not found";
                                 break;
                            case 4:
                                 cout<<"\nEnter element to be deleted";
                                 cin>>ele;
                                 ob.del(ele);
                                 ob.display();
                                 break;
                            case 5:
                                 cout<<"\nMaximum element is "<<ob.findmax()<<"\n";
                                 break;
                            case 6:
                                 cout<<"\nMinimum element is "<<ob.findmin()<<"\n";
                                 break;
                            case 7:
                                 ob.empty();
                                 ob.display();
                                 break;
                            case 0:
                                 n=0;
                                 break;
              }
    }
    system("pause");
}

Program on insertion and deletion using arrays



#include<iostream>
using namespace std;
template<class T>
class linear_list
{
      T list[20];
      int size;
      public:
             void set();
             T get();
             int getindex(T);
             void del(T);
             T findmax();
             T findmin();
             void empty();
             void display();
};
template<class T>
void linear_list<T>::set()
{
     cout<<"\nEnter size of array\n";
     cin>>size;
     cout<<"\nEnter elements\n";
     for(int i=0; i<size; i++)
     cin>>list[i];
}
template<class T>
T linear_list<T>::get()
{
     if(size<1)
     {
               cout<<"\nList is empty";
               return -1;
     }
     else
     return list[0];
}
template<class T>
int linear_list<T>::getindex(T ele)
{
     if(size<1)
     {
               cout<<"\nList is empty";
               return -1;
     }
     else
     {
         for(int i=0; i<size; i++)
         {
                 if(list[i]==ele)
                 return (i+1);
         }
     }
     return -1;
}
template<class T>
void linear_list<T>::del(T ele)
{
     int pos;
     pos=getindex(ele);
     for(int i=pos-1; i<size; i++)
     list[i]=list[i+1];
     size=size-1;
}
template<class T>
T linear_list<T>::findmax()
{
     int max=list[0];
     for(int i=1; i<size; i++)
     {
             if(max<list[i])
             {
                            max=list[i];
             }
     }
     return max;
}
template<class T>
T linear_list<T>::findmin()
{
     int min=list[0];
     for(int i=1; i<size; i++)
     {
             if(min>list[i])
             {
                            min=list[i];
             }
     }
     return min;
}
template<class T>
void linear_list<T>::empty()
{
     for(int i=0; i<size; i++)
     {
             list[i]=0;
     }
}
template<class T>
void linear_list<T>::display()
{
     cout<<"\nArray is\n";
     for(int i=0; i<size; i++)
     cout<<list[i]<<" ";
     cout<<"\n";
}
int main()
{
    int ele, pos, option, n=1;
    linear_list<int> ob;
    while(n==1)
    {
              cout<<"\nEnter option";
              cout<<"\n1 set element\n2 get element\n3 getindex of element\n4 delete an element \n5 find maximum element\n6 find minimum element\n7 empty the array\n0 exit program\n";
              cin>>option;
              switch(option)
              {
                            case 1:
                                 ob.set();
                                 ob.display();
                                 break;
                            case 2:
                                 ob.get();
                                 ob.display();
                                 break;
                            case 3:
                                 cout<<"\nEnter element to get index of\n";
                                 cin>>ele;
                                 pos=ob.getindex(ele);
                                 if(pos!=0)
                                 {
                                           cout<<"\nElement found at "<<pos;
                                 }
                                 else
                                 cout<<"\nElement not found";
                                 break;
                            case 4:
                                 cout<<"\nEnter element to be deleted";
                                 cin>>ele;
                                 ob.del(ele);
                                 ob.display();
                                 break;
                            case 5:
                                 cout<<"\nMaximum element is "<<ob.findmax()<<"\n";
                                 break;
                            case 6:
                                 cout<<"\nMinimum element is "<<ob.findmin()<<"\n";
                                 break;
                            case 7:
                                 ob.empty();
                                 ob.display();
                                 break;
                            case 0:
                                 n=0;
                                 break;
              }
    }
    system("pause");
}

Basic Electronics Record Experiments List


  1. P-N Junction Diode Characteristics
  2. Zener Diode Characteristics
  3. Half Wave Rectifier
  4. Full Wave Rectifier
  5. Transistor CE Characteristics
  6. Transistor CE Amplifier
  7. Current Series Feedback Amplifier
  8. RC Phase Shift Oscillator
  9. FET Characteristics

Basic Electronics Assignment


















These are few questions of our assignment. I'll upload remaining later.