View Single Post
  #1 (permalink)  
Old February 2nd, 2009, 05:08 AM
code_lover code_lover is offline
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 46
Thanks: 2
Thanked 1 Time in 1 Post
Default How to reverse an array here?

#include <iostream.h>
const int MAX = 5;
class array
{
private:
int arr[MAX];
public:
void populate();
void reverse();
void display();
};

void array::populate()
{
int n;
for (short i=0;i<=MAX;i++)
{
cout<<"\nEnter number:";
cin>>n;
arr[i]=n;
}
}

void array::reverse()
{
for (short i = 0;i<=MAX;i++)
{
arr[i] = arr[(MAX + 1)- i];

}

//arr[0]=arr[6];
//arr[1]=arr[5];
//arr[2]=arr[4];
//arr[3]=arr[3];
//arr[4]=arr[2];
//arr[5]=arr[1];
//arr[6]=arr[0];
}

void array::display()
{
for (short i = 0;i<=MAX;i++)
cout<<arr[i]<<endl;
}

main()
{
array a;

a.populate();
a.display();

a.reverse();
a.display();

system("pause");
}
__________________
MAXOOD!

Life is an endless journey towards perfection
Reply With Quote