HI, I have a prog. assignment, I did most of it, but I couldn't write some functions properly, so try 2 help.?
these are the functions I wrote b4.
#include "Array.h"
#include <iostream>
using namespace std;
Array::Array() //constructor to set size=6
{
size=6;
}
void Array::read() // read array elements
{
cout<<"Enter "<<size<<" Array Elements:\n";
for (int i=0; i<size; i++)
cin>>A[i];
}
void Array::display() // display array elements
{
for (int i=0; i<size; i++)
cout<<A[i]<<"\t";
cout<<endl;
}
int Array::max () //find array maximum
{
int max = A[0];
for (int i=1; i<size; i++)
if (A[i]>max)
max=A[i];
return max;
}
int Array::min () //find array minimum
{
int min = A[0];
for (int i=1; i<size; i++)
if (A[i]<min)
min=A[i];
return min;
}
bool Array::search (int key) //search array for specific key
{
for (int i=0; i<size; i++)
if (A[i]==key)
return true;
return false;
}
void Array::reverse () //reverse array elements
{
int mid=size/2;
int temp;
for (int i=0; i<mid; i++){
temp=A[i];
A[i]=A[size-1-i];
A[size-1-i]=temp;
}
}
void Array::sort () //sort array elements with ascending order
{
int temp;
for (int i=size-1; i>0; i--)
for (int j=0; j<i; j++)
if (A[j]>A[j+1]){
temp=A[j];
A[j]=A[j+1];
A[j+1]=temp;
}
}
I need to add these functions also (I tried but there were many errors :S )
void replace (int x, int y): a function that is used to replace an existing array value x with another value y.
int count (int ele): a function that is used to count the number of times the value ele appears in the array.
void split (): a function that is used to split the array into two equal halves and store them in two different arrays.
THANKS