As a sort of exercise for myself and hoping that this will help you learn, I've had a go at "fixing" your code, including a few comments regarding coding standards and the like.
However, I would stress that I would not expect to see code like this in any professional project, which I think at least one of my comments should make clear.
Regards,
Ian.
#include <iostream>
using namespace std;
class IntArray
{
public:
void SetData();
void GetData() const; void Search() const;
void Bubble();
IntArray
(
int size
)
{
this->size = size;
values = new int[size];
}
virtual ~IntArray()
{
delete [] values;
}
private:
IntArray
(
const IntArray& other
);
IntArray& operator=
(
const IntArray& other
);
IntArray();
private:
int size;
int* values; };
void IntArray::SetData()
{
cout << "==> Entering Data <==" << endl;
for (int i = 0; i < size; ++i)
{
cout << ">> Enter Element #" << i+1 << ": ";
cin >> values[i];
}
}
void IntArray::GetData() const
{
cout << "==> Printing Data <==" << endl;
for (int i = 0; i < size; ++i)
{
cout << values[i] << " ,";
}
cout << "\n";
}
void IntArray::Search() const
{
int key;
cout << "Please Enter A KEY To Find: ";
cin >> key;
int index = 0;
bool found = false;
for (int i = 0; i < size; ++i)
{
if ((!found) && (key == values[i]))
{
index = i;
found = true;
}
}
if (found)
{
cout << "KEY Found At The Index: " << index+1 << endl;
}
else
{
cout << "KEY is not present." << endl;
}
cout << '\n' << endl;
}
void IntArray::Bubble()
{
for (int i = 1; i < size; ++i)
{
for (int j = 0; j < size; ++j)
{
if (values[j] > values[i])
{
int temp = values[j];
values[j] = values[i];
values[i] = temp;
}
}
}
}
int main()
{
const int size = 5;
IntArray u(size);
u.SetData();
u.GetData();
u.Search();
u.Bubble();
u.GetData();
system("pause");
return 0;
}