0% found this document useful (0 votes)
178 views

Code For Program To Perform Array Operations Like Append, Insert, Delete, Edit, Display and Search and Element in C++ Programming

This C++ program allows the user to perform various operations on an array, including appending, inserting, deleting, editing, displaying, and searching elements. The user is prompted to enter the number of elements, which are input and stored in an integer array. A menu is then displayed listing the array operation choices. Based on the user's selection, the appropriate array manipulation function is performed, such as appending a new element, inserting at a specified position, deleting a value, editing a position, displaying all elements, or searching for a value.

Uploaded by

Chiradip Basu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
178 views

Code For Program To Perform Array Operations Like Append, Insert, Delete, Edit, Display and Search and Element in C++ Programming

This C++ program allows the user to perform various operations on an array, including appending, inserting, deleting, editing, displaying, and searching elements. The user is prompted to enter the number of elements, which are input and stored in an integer array. A menu is then displayed listing the array operation choices. Based on the user's selection, the appropriate array manipulation function is performed, such as appending a new element, inserting at a specified position, deleting a value, editing a position, displaying all elements, or searching for a value.

Uploaded by

Chiradip Basu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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
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
int key;

: ";

which you want to insert : ";


: ";

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;
}
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();
}

You might also like