If the idea is to have the ONE function arrange your array's contents in descending order and return the highest, then your changes are very simple.
Change your array function from a void to an int so that it returns an int value. At the end of the function once youve arranged the contents in descending order, the first element of the array is the largest (I'm guessing thats what you mean by maximum). Just return this element and you're set. From your main function you just capture this return value in an int variable and output that variable.
(**Note** - I havent gone through your sorting logic so as long as that is correct, this should work.)
Quote:
|
Originally Posted by toezaurus81
/*Define a class intList contains one private attribute:
an array of integers of size 10. Provide member functions to accept
and display the elements of array. Provide one member function that
arranges the array elements in descending order and returns the maximum
of the array elements.
Write a driver program to test the above intList class.*/
#include<iostream.h>
class intList
{
private:
int data[10];
int pass, i, temp;
public:
void accept()
{
cout<<"Input integer number for array";
cout<<"\n******************************"<<endl;
for(i=0;i<10;i++)
{
cout<<"Enter value for array["<<i<<"]: ";
cin>>data[i];
}
}
void display()
{
for(i=0;i<10;i++)
{
cout<<"Value for array["<<i<<"]: "<<data[i]<<endl;
}
}
void arrange()
{ int Max=10;
for(pass=1;pass<=Max-1;pass++)
for(i=0;i<Max-pass;i++)
{
if(data[i]<data[i+1]){
temp=data[i];
data[i]=data[i+1];
data[i+1]=temp;
}
}
}
};
void main(){
intList list;
list.accept();
cout<<"\nThe values stored in the arrays";
cout<<"\n*******************************"<<endl;
list.display();
list.arrange();
cout<<"\nThe values stored in the arrays after sort in decending";
cout<<"\n*******************************"<<endl;
list.display();
//cout<<"The maxinum of the arrays elements: "<<max;
}
|