Xpode.com        Click here to Print this article.

C++ Array Program

#include <iostream>
#include <conio.h>
using namespace std;
class r {
private :
public :
int insert (int a[5], int d, int i)
{
int n=5;
for(int j=n-1;j>1; j--)
{
a[j+1]=a[j];
}
a[i]=d;
for(int k=0; k<=5; k++)
{
cout<<"\t"<<a[k];
}
}
};
int main ()
{
char choice;
do{
int a[5], d, i;
char choice1;
r a1;
cout<<"enter 5 numbers ";
for(int j=0;j<5;j++)
cin>>a[j];
cout<<"insert data into array at specific index "<<"\t"<<"i"<<"\n";
cout<<"Delete data from array from specific index "<<"\t"<<"d"<<"\n";
cin>>choice1;
if(choice1 == 'i' || choice1 == 'I')
{
cout<<"enter element of index ";
cin>>d;
cout<<"enter index";
cin>>i;
a1.insert(a, d, i);
}
else if (choice1 == 'd' || choice1 == 'D')
{
int index=0;
cout<<"enter index number to del its element ";
cin>>index;
int size=5;
cout<<i<<"\n";
cout<<a[i]<<"\n";
for(int k=i; k<size-1; k++)
{
a[k]=a[k+1];
}
for(int u=0; u<size-1; u++)
{
cout<<"\t"<<a[u];
}
}
else
{
cout<<"You entered wrong ";
}
cout<<"\n"<<"Try Again press y or n to exit";
cin>>choice;
}
while (choice == 'y' || choice == 'Y');
{
getch();
}
}



http://c++programs.com
http://c++ programs.com

Contributed by:
Suleman Younas
I'm a student of Bs hons

Resourse address on xpode.com
http://xpode.com/xpodehost/Print.aspx?Articleid=788

Click here to go on website