Coders Packet

Contact Management in C++ using Structure

By Bharat Pandey

Hello coders, Today we are going to writing a source code for Storing contact_no and name in Contact_list using c++. In this source code, we are using a hash function, structure, etc.

In this program, we store contact name and contact_no in a structure then we used this program to add a contact, list all contacts, search contact through name, delete the contact. 

 Note: File Handling is not used in this source code so All added records are not saved in a file.

Let's start with understanding some Concepts we will use in this program. 

This program, using the structures for storing contact info. so let's understand the structure.

We know that structures are described in the C language. They provide a method for packing together data of different types.

struct contact_info
{
  string name; //store name
  long long contact_no; // store contact_no
  int flag;            //flag used for operation.
}contact[capacity];         // create contact_info in memory.Nex

Next, we used Hashing to add a contact in the contact array. 

int hashcontact(long long info, long long contact_no , int i=1)
{
  // Quadratic probing lies between the two in terms of cache performance and clustering.
  // we use Quadratic probing.
    if(contact[contact_no%capacity].contact_no == info && contact[contact_no%capacity].flag != -1)
    {
      return -1;
    }
    else
    {
      if(contact[contact_no%capacity].flag != 1)
      {
        return (contact_no%capacity);
      }
      else
      {
        hashcontact(info , ((contact_no%capacity)+i*i),i+=1 );
      }
      }
}

I don’t think there needs any explanation, how did I write the code. Let’s see the code.

Note: Note if you don't understand what is hashing and how to implement it. I will write a packet on this very soon.

 

Download Complete Code

Comments

No comments yet