Delete Operation in C++ using class:: By A.P... " it is used to remove to a data items In the given collection of data items. " #include "iostream.h" #include"conio.h" Class ap { int arr[100]; public : void get_data(); void del_data(); }; void ap::get_data() { int size, i; ...
Insertion Operation Using Class::
#include"iostream.h"
#include"conio.h"
Class ap
{
int arr[100],size;
public:
void get_data();
void insert_data();
void show ();
void show ();
};
void ap::get_data()
{
cout <<"enter size";
cin>>size;
for( int i=0; i <size; i++)
{
cin>>arr [i];
}
}
void ap::insert_data()
{
int pos,num;
cout<<endl<<"enter any no.:";
cin>>num;
cout<<endl <<"enter position"
cin>>pos;
for (i=size; i>pos; i--)
{
arr [i]=arr [i-1];
}
arr [pos]=num;
size++;
}
void ap::show()
{
cout <<endl <<"array element after insertion of new element ":
for ( int i=0; i <size; i++)
{
cout <<arr [i]<<" ";
}
}
void main()
{
clrscr ();
ap.obj;
obj.get_data ();
obj.insert_data ();
obj.show();
getch ();
}
Output. ::
enter no. 3
enter array 2
4
6
enter position 2
enter any no. 5
elament after insertion of new element 2546
cin>>size;
for( int i=0; i <size; i++)
{
cin>>arr [i];
}
}
void ap::insert_data()
{
int pos,num;
cout<<endl<<"enter any no.:";
cin>>num;
cout<<endl <<"enter position"
cin>>pos;
for (i=size; i>pos; i--)
{
arr [i]=arr [i-1];
}
arr [pos]=num;
size++;
}
void ap::show()
{
cout <<endl <<"array element after insertion of new element ":
for ( int i=0; i <size; i++)
{
cout <<arr [i]<<" ";
}
}
void main()
{
clrscr ();
ap.obj;
obj.get_data ();
obj.insert_data ();
obj.show();
getch ();
}
Output. ::
enter no. 3
enter array 2
4
6
enter position 2
enter any no. 5
elament after insertion of new element 2546
Comments
Post a Comment