Professional Documents
Culture Documents
1.1 Data Structures
1.1 Data Structures
1.1 Data Structures
Code:
#include<iostream>
using namespace
std;
int a[10];
int n, i, j, val, pos;
void create();
void display();
void insert();
void del();
void search();
int main()
{
int
choice;
do{
cout<<"***************MENU OF THE
PROGRAM******************"<<endl; cout<<"1.Create an array"<<endl;
cout<<"2.Display the array"<<endl;
cout<<"3.Insert an element"<<endl;
cout<<"4.Delete an
element"<<endl;
cout<<"5.Search an
element"<<endl;
cout<<"6.Exit"<<endl;
switch(choice)
{ case 1:
create();
cout<<endl;break
; case 2: display();
cout<<endl;break
; case 3: insert();
cout<<endl;break
; case 4: del();
cout<<endl;
break; case 5: search();
cout<<endl;break
; case 6: exit(0);
default: cout<<"Invalid
choice:"; break;
}while(choice!
=6); return 0;
}
void create(){
cout<<"Enter the no. of elements in the array:
"; cin>>n;
cout<<"Enter the elements of array: "<<endl;
for(i=0;i<n;i++){
cin>>a[i];
}
cout<<endl;
}
void display(){
cout<<"The array is following:"<<endl;
for(i=0;i<n;i++)
{ cout<<a[i]<<"
";
}
cout<<endl;
}
void insert(){
cout<<"Enter the position of new element: ";
cin>>pos;
cout<<"Enter the value of new element:
"; cin>>val;
for(i=n-1;i>=pos;i--)
{ a[i+1]=a[i];
}
a[pos]=val;
n=n+1;
cout<<"Updated Array:
"; for(i=0;i<n;i++){
cout<<a[i]<<" ";
}
cout<<endl;
}
void del(){
cout<<"Enter the position of element to delete:";
cin>>pos;
val=a[pos];
for(i=pos;i<n-1;i++)
{
a[i]=a[i+1];
}
n=n-1;
cout<<"The deleted element is =
"<<val<<endl; cout<<"Updated Array: ";
for(i=0;i<n;i++)
{ cout<<a[i]<<"
";
}
cout<<endl
;
cout<<endl
;
}
void search(){
int elem;
cout <<"Enter the
element :"; cin >> elem;
] Run >
*** **
X
X
} File Edit Selection View Go Run Terminal HeI|s #include<iostream > • Untitled-4 - Visual Studio Code ”””*”””**””**””MENU OF
THE PROGRAM”” * *”” ** ”””
"ROBLEMS 3 OU+"U+ TERMINAL DEBUG CONSOLE * ””” * ””
1.
C
Updated Array: 11 22 66 33 44 55
r
eate an array
2.Display the — EI X
array 3.Insert an
Code + X
element 4.Delete
an element
5.Search an
element
6. Exit
Choose a option (1—6)
***************MENU OF THE
PROGRAM****************** 1.Create an array
2.Display the
array 3.Insert an
element 4.Delete
an element
5.Search an
element 6.Exit
Choose a option (1-
6) 5
Enter the element :66
Element found at
position: 2
Python 3.9.6 64-bit @ 3 0
1.
2.
3.
4.
5.
Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):