Tuesday, December 9, 2014

Bitwise operator and Student mark list and perform radix sort in C++ Programming



Code for Program to show the use of Bitwise Operator Left Shift in C++ Programming

 # include 
 # include
 void binary_code(int);
 void main( )
    {
       clrscr( );
       textmode(bw80);
       int n;
       int bits;
       cout<<"\n Enter the value of n = ";
       cin>>n;
       cout<<"\n The Binary code of value of n = ";
       binary_code(n);
       cout<<"\n\n Enter the number of bits to shift left = ";
       cin>>bits;
       n=n<
       cout<<"\n The value of n after Left Shifting = "<
       cout<<"\n\n The Binary code of modified value of n = ";
       binary_code(n);
       getch( );
    }
/*************************************************************************///---------------------------  binary_code( )  ------------------------///*************************************************************************/
void binary_code(int number)
    {
       int remainder;
       int qutiont;
       int count=0;
       int x=(wherex( )+16);
       int y=wherey( );
       if(number>0)
      {
         while(number>0)
        {
           qutiont=number/2;
           remainder=number%2;
           number=qutiont;
           gotoxy((x-count),y);
           cout<
           count++;
        }
      }
       else
      {
         gotoxy((x-count),y);
         cout<<"0";
      }
    }

Code for Program that reads marks of a students and computes and displays grade in C++ Programming

#include
#include
int main()
    {
       clrscr();
       int marks;
       char grade;
       cout<<"\n Enter your Marks = ";
       cin>>marks;
       switch(marks/10)
      {
         case 10 :  grade='A';
            break;
         case 9 :  grade='A';
            break;
         case 8 :  grade='A';
            break;
         case 7 :  grade='B';
            break;
         case 6 :  grade='C';
            break;
         case 5 :  grade='D';
            break;
         default : grade='F';
      }
       cout<<"\n Your Grade is = "<
       getch();
       return 0;
    }

Program to perform radix sort in C++ Programming

#include 
#include 
#define max 10
class radixsort
{
    int arr[max],n;
    public:
    void getdata();
    void showdata();
    void sortLogic();
};
void radixsort :: getdata()
{
    cout<<"How many elements you require : ";
    cin>>n;
    for(int i=0;i
        cin>>arr[i];
}
void radixsort :: showdata()
{
    cout<<"\n--Display--\n";
    for(int i=0;i
        cout<"   ";
}
void radixsort :: sortLogic()
{
    for base 10int temp;
    int bucket[10][20], buck_count[10], b[10];
    int i,j,k,r,no_of_passes=0,divisor=1,largest,pass_no;
    largest=arr[0];
    for(i=1;i  
    {
        if(arr[i] > largest)
            largest=arr[i];
    }
    while(largest > 0)  
    {
        no_of_passes++;
        largest /= 10;
    }
    for(pass_no=0; pass_no < no_of_passes; pass_no++)
   {
 
        for(k=0; k<10 k="" span="">
            buck_count[k]=0; 
           {
            r=(arr[i]/divisor) % 10;
            bucket[r][buck_count[r]++]=arr[i];
        }
        i=0; 
        {
            for(j=0; j
                arr[i++] = bucket[k][j];
        }
        divisor *= 10;
    }
}
void main()
{
    clrscr();
    cout<<"\n*****Radix Sort*****\n";
    radixsort obj;
    obj.getdata();
    obj.sortLogic();
    obj.showdata();
    getch();
}

No comments:

Post a Comment