Logo 
Search:

C++ Programming Articles

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

Program to perform array operations like append, insert, delete, edit, display and search and element

Posted By: Maria Silva     Category: C++ Programming     Views: 29540

Program to perform array operations like append, insert, delete, edit, display and search and element.

Code for Program to perform array operations like append, insert, delete, edit, display and search and element in C++ Programming

#include<iostream.h>
#include<stdio.h>
#include<conio.h>

main()
{
    int array[15];
    int no_el;
    clrscr();
    cout<<"Enter the no of element :";
    cin>>no_el;
    for(int i=0;i<no_el;i++)
    {
        cout<<"Enter the element : ";
        cin>>array[i];
    }
    while(1)
    {
        clrscr();
        cout<<endl<<"1. Append";
        cout<<endl<<"2. Insert";
        cout<<endl<<"3. delete by value";
        cout<<endl<<"4. edit";
        cout<<endl<<"5. display";
        cout<<endl<<"6. search";
        cout<<endl<<"7. exit";
        cout<<endl<<"Enter your choice : ";
        int choice;
        cin>>choice;
        switch(choice)
        {
            case 1:
                cout<<"Enter the new element : ";
                int new_el;
                cin>>new_el;
                array[no_el]=new_el;
                no_el++;
            break;
            case 2:
                cout<<"Enter the position at which you want to insert : ";
                int pos;
                cin>>pos;
                cout<<"Enter the new element : ";
                cin>>new_el;
                pos--;
                for(i=no_el-1;i>=pos;i--)
                    array[i+1]=array[i];
                array[pos]=new_el;
                no_el++;
            break;
            case 3:
                cout<<"Enter the value to be search : ";
                int key;
                cin>>key;
                for(pos=0;pos<no_el;pos++)
                {
                    if(array[pos]==key)
                        break;
                }
                if(pos==no_el)
                {
                    cout<<"Search key not found";
                    break;
                }
                for(i=pos;i<no_el;i++)
                    array[i]=array[i+1];
                no_el--;
            break;
            case 4:
                cout<<"Enter the position to be edit : ";
                cin>>pos;
                cout<<"Enter the new value for old position : ";
                cin>>array[pos-1];
            break;
            case 5:
                cout<<endl;
                for(i=0;i<no_el;i++)
                    cout<<endl<<"The element is : "<<array[i];
            break;
            case 6:
                cout<<"Enter the value to be search : ";
                cin>>key;
                for(pos=0;pos<no_el;pos++)
                {
                    if(array[pos]==key)
                        break;
                }
                if(pos==no_el)
                {
                    cout<<"Search key not found";
                    break;
                }
                cout<<"Search key found at : "<<pos+1;
            break;
            case 7:
                return(0);
            break;
        }
        getch();
    }
}
  
Share: 



Maria Silva
Maria Silva author of Program to perform array operations like append, insert, delete, edit, display and search and element is from Salvador, Brazil.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

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

 
Barish Barla from United States Comment on: Feb 01
Great for reference,thanks.

Ali Khurram from Pakistan Comment on: Jul 07
give me output of this programme immedieatly plzzzzzzzzzzzzz
bgQlo

Billy Joel Mercado from Philippines Comment on: Jun 30
Thanks for this.. This was a big help for me.. For my reference

View All Comments