#include<iostream>
using namespace std;
class CppArray
{
private:
int a[10],i,j,n,b[10],temp;
public:
void get();
void print();
void sort();
void range();
void exchange();
int size();
};
void CppArray::get()
{
cout<<"\n Enter the limit of array ";
cin>>n;
cout<<"\n Enter the array elements ";
for(i=0;i<n;i++)
{
cout<<"\n a["<<i<<"]=";
cin>>a[i];
}
}
void CppArray::print()
{
cout<<"\n The entered array is ";
for(i=0;i<n;i++)
{
cout<<"\n a["<<i<<"]="<<a[i];
}
}
void CppArray::sort()
{
for(j=0;j<n;j++)
{
for(i=0;i<n-1;i++)
{
if(a[i]>a[i+1])
{
temp=a[i+1];
a[i+1]=a[i];
a[i]=temp;
}
}
}
cout<<"\n The sorted array is ";
for(i=0;i<n;i++)
{
cout<<"\n a["<<i<<"]="<<a[i];
}
}
void CppArray::range()
{
cout<<"\n The range of array is from "<<a[0]<<" to "<<a[n-1];
}
void CppArray::exchange()
{
for(i=0;i<n;i++)
{
b[i]=a[i];
}
cout<<"\n The exchanged array is ";
for(i=0;i<n;i++)
{
cout<<"\n b["<<i<<"]="<<b[i];
}
}
int CppArray::size()
{
return n;
}
int main()
{
int a;
CppArray obj;
obj.get();
obj.print();
obj.range();
obj.exchange();
obj.sort();
a=obj.size();
cout<<"\n The size of array is "<<a;
return 0;
}
************output*****************
PS F:\harshal\MCA\opps\assignment 3> cd "f:\harshal\MCA\opps\assignment 3\" ; if ($?) { g++ ass3.cpp -o ass3 } ; if ($?) { .\ass3 }
Enter the limit of array 4
Enter the array elements
a[0]=3
a[1]=2
a[2]=4
a[3]=5
The entered array is
a[0]=3
a[1]=2
a[2]=4
a[3]=5
The range of array is from 3 to 5
The exchanged array is
b[0]=3
b[1]=2
b[2]=4
b[3]=5
The sorted array is
a[0]=2
a[1]=3
a[2]=4
a[3]=5
The size of array is 4
**//