Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Data File StructureRSS Feeds

Program to show an example of Hashing using Mid-Square Method.

Posted By: Easy Tutor     Category: C++ Programming     Views: 6757

Write a program to show an example of Hashing using Mid-Square Method.

Code for Program to show an example of Hashing using Mid-Square Method. in C++ Programming

 # include <iostream.h>
 # include <string.h>
 # include <stdlib.h>
 # include <conio.h>
 # include <math.h>


 int main( )
 {
    clrscr( );

    cout << endl << "Mid-Square Hashing Method" << endl;
    cout << "*************************" << endl << endl;

    unsigned int iNumber = 0;
    unsigned int iLimit = 0;

    cout << "Enter the Number = N = ";
    cin >> iNumber;

    cout << endl << "Enter the Limit = K = ";
    cin >> iLimit;

    unsigned long lNumber = powl(iNumber, 2);

    char sNumber[50] = {NULL};

    ultoa(lNumber, sNumber, 10);

    int iCount = (strlen(sNumber) - iLimit);
    int iLength = 0;

    char sTemp[30] = {NULL};

    cout << endl << "K * K = "<< lNumber << endl;

    for (int i = 0; i < iCount; i ++)
    {
       iLength = (strlen(sNumber) - 1);

       if ( (i % 2) == 0)
       {
      strset(sTemp, NULL);
      strncpy(sTemp, sNumber, iLength);

      strset(sNumber, NULL);
      strcpy(sNumber, sTemp);
       }

       else
       {
      strrev(sNumber);
      strset(sTemp, NULL);
      strncpy(sTemp, sNumber, iLength);
      strrev(sTemp);

      strset(sNumber, NULL);
      strcpy(sNumber, sTemp);
       }
    }

    int iHashKey = atoi(sNumber);

    cout << endl << "Hashing Key = " << iHashKey;

    getch( );
    return 0;
 }




 /**************************************************************************  *************************************************************************  A C++ Program to show an example of Hashing using Mid-Square Method.  **************************************************************************  **************************************************************************/
 
 # include <iostream.h>
 # include <string.h>
 # include <stdlib.h>
 # include <conio.h>
 # include <math.h>


 int main( )
 {
    clrscr( );

    cout << endl << "Mid-Square Hashing Method" << endl;
    cout << "*************************" << endl << endl;

    unsigned int iNumber = 0;
    unsigned int iLimit = 0;

    cout << "Enter the Number = N = ";
    cin >> iNumber;

    cout << endl << "Enter the Limit = K = ";
    cin >> iLimit;

    unsigned long lNumber = powl(iNumber, 2);

    char sNumber[50] = {NULL};

    ultoa(lNumber, sNumber, 10);

    int iCount = (strlen(sNumber) - iLimit);
    int iLength = 0;

    char sTemp[30] = {NULL};

    cout << endl << "K * K = "<< lNumber << endl;

    for (int i = 0; i < iCount; i ++)
    {
       iLength = (strlen(sNumber) - 1);

       if ( (i % 2) == 0)
       {
      strset(sTemp, NULL);
      strncpy(sTemp, sNumber, iLength);

      strset(sNumber, NULL);
      strcpy(sNumber, sTemp);
       }

       else
       {
      strrev(sNumber);
      strset(sTemp, NULL);
      strncpy(sTemp, sNumber, iLength);
      strrev(sTemp);

      strset(sNumber, NULL);
      strcpy(sNumber, sTemp);
       }
    }

    int iHashKey = atoi(sNumber);

    cout << endl << "Hashing Key = " << iHashKey;

    getch( );
    return 0;
 }




 /**************************************************************************  *************************************************************************  A C++ Program to show an example of Hashing using Mid-Square Method.  **************************************************************************  **************************************************************************/
 
 # include <iostream.h>
 # include <string.h>
 # include <stdlib.h>
 # include <conio.h>
 # include <math.h>


 int main( )
 {
    clrscr( );

    cout << endl << "Mid-Square Hashing Method" << endl;
    cout << "*************************" << endl << endl;

    unsigned int iNumber = 0;
    unsigned int iLimit = 0;

    cout << "Enter the Number = N = ";
    cin >> iNumber;

    cout << endl << "Enter the Limit = K = ";
    cin >> iLimit;

    unsigned long lNumber = powl(iNumber, 2);

    char sNumber[50] = {NULL};

    ultoa(lNumber, sNumber, 10);

    int iCount = (strlen(sNumber) - iLimit);
    int iLength = 0;

    char sTemp[30] = {NULL};

    cout << endl << "K * K = "<< lNumber << endl;

    for (int i = 0; i < iCount; i ++)
    {
       iLength = (strlen(sNumber) - 1);

       if ( (i % 2) == 0)
       {
      strset(sTemp, NULL);
      strncpy(sTemp, sNumber, iLength);

      strset(sNumber, NULL);
      strcpy(sNumber, sTemp);
       }

       else
       {
      strrev(sNumber);
      strset(sTemp, NULL);
      strncpy(sTemp, sNumber, iLength);
      strrev(sTemp);

      strset(sNumber, NULL);
      strcpy(sNumber, sTemp);
       }
    }

    int iHashKey = atoi(sNumber);

    cout << endl << "Hashing Key = " << iHashKey;

    getch( );
    return 0;
 }




 /**************************************************************************  *************************************************************************  A C++ Program to show an example of Hashing using Mid-Square Method.  **************************************************************************  **************************************************************************/
 
 # include <iostream.h>
 # include <string.h>
 # include <stdlib.h>
 # include <conio.h>
 # include <math.h>


 int main( )
 {
    clrscr( );

    cout << endl << "Mid-Square Hashing Method" << endl;
    cout << "*************************" << endl << endl;

    unsigned int iNumber = 0;
    unsigned int iLimit = 0;

    cout << "Enter the Number = N = ";
    cin >> iNumber;

    cout << endl << "Enter the Limit = K = ";
    cin >> iLimit;

    unsigned long lNumber = powl(iNumber, 2);

    char sNumber[50] = {NULL};

    ultoa(lNumber, sNumber, 10);

    int iCount = (strlen(sNumber) - iLimit);
    int iLength = 0;

    char sTemp[30] = {NULL};

    cout << endl << "K * K = "<< lNumber << endl;

    for (int i = 0; i < iCount; i ++)
    {
       iLength = (strlen(sNumber) - 1);

       if ( (i % 2) == 0)
       {
      strset(sTemp, NULL);
      strncpy(sTemp, sNumber, iLength);

      strset(sNumber, NULL);
      strcpy(sNumber, sTemp);
       }

       else
       {
      strrev(sNumber);
      strset(sTemp, NULL);
      strncpy(sTemp, sNumber, iLength);
      strrev(sTemp);

      strset(sNumber, NULL);
      strcpy(sNumber, sTemp);
       }
    }

    int iHashKey = atoi(sNumber);

    cout << endl << "Hashing Key = " << iHashKey;

    getch( );
    return 0;
 }




 /**************************************************************************  *************************************************************************  A C++ Program to show an example of Hashing using Mid-Square Method.  **************************************************************************  **************************************************************************/
 
 # include <iostream.h>
 # include <string.h>
 # include <stdlib.h>
 # include <conio.h>
 # include <math.h>


 int main( )
 {
    clrscr( );

    cout << endl << "Mid-Square Hashing Method" << endl;
    cout << "*************************" << endl << endl;

    unsigned int iNumber = 0;
    unsigned int iLimit = 0;

    cout << "Enter the Number = N = ";
    cin >> iNumber;

    cout << endl << "Enter the Limit = K = ";
    cin >> iLimit;

    unsigned long lNumber = powl(iNumber, 2);

    char sNumber[50] = {NULL};

    ultoa(lNumber, sNumber, 10);

    int iCount = (strlen(sNumber) - iLimit);
    int iLength = 0;

    char sTemp[30] = {NULL};

    cout << endl << "K * K = "<< lNumber << endl;

    for (int i = 0; i < iCount; i ++)
    {
       iLength = (strlen(sNumber) - 1);

       if ( (i % 2) == 0)
       {
      strset(sTemp, NULL);
      strncpy(sTemp, sNumber, iLength);

      strset(sNumber, NULL);
      strcpy(sNumber, sTemp);
       }

       else
       {
      strrev(sNumber);
      strset(sTemp, NULL);
      strncpy(sTemp, sNumber, iLength);
      strrev(sTemp);

      strset(sNumber, NULL);
      strcpy(sNumber, sTemp);
       }
    }

    int iHashKey = atoi(sNumber);

    cout << endl << "Hashing Key = " << iHashKey;

    getch( );
    return 0;
 }




 /**************************************************************************  *************************************************************************  A C++ Program to show an example of Hashing using Mid-Square Method.  **************************************************************************  **************************************************************************/
 
 # include <iostream.h>
 # include <string.h>
 # include <stdlib.h>
 # include <conio.h>
 # include <math.h>


 int main( )
 {
    clrscr( );

    cout << endl << "Mid-Square Hashing Method" << endl;
    cout << "*************************" << endl << endl;

    unsigned int iNumber = 0;
    unsigned int iLimit = 0;

    cout << "Enter the Number = N = ";
    cin >> iNumber;

    cout << endl << "Enter the Limit = K = ";
    cin >> iLimit;

    unsigned long lNumber = powl(iNumber, 2);

    char sNumber[50] = {NULL};

    ultoa(lNumber, sNumber, 10);

    int iCount = (strlen(sNumber) - iLimit);
    int iLength = 0;

    char sTemp[30] = {NULL};

    cout << endl << "K * K = "<< lNumber << endl;

    for (int i = 0; i < iCount; i ++)
    {
       iLength = (strlen(sNumber) - 1);

       if ( (i % 2) == 0)
       {
      strset(sTemp, NULL);
      strncpy(sTemp, sNumber, iLength);

      strset(sNumber, NULL);
      strcpy(sNumber, sTemp);
       }

       else
       {
      strrev(sNumber);
      strset(sTemp, NULL);
      strncpy(sTemp, sNumber, iLength);
      strrev(sTemp);

      strset(sNumber, NULL);
      strcpy(sNumber, sTemp);
       }
    }

    int iHashKey = atoi(sNumber);

    cout << endl << "Hashing Key = " << iHashKey;

    getch( );
    return 0;
 }


  
Share: 



Easy Tutor
Easy Tutor author of Program to show an example of Hashing using Mid-Square Method. is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!