Code:
#include <iostream.h>
class MyClass {
public:
int *array;
int *tmparray;
MyClass(int s) {
size = s;
array = new int[size];
}
~MyClass() {
delete [] array;
}
int get_length() {
return size;
}
void resize(int s) {
delete [] array;
size = s;
array = new int[size];
}
void clear_all() {
for (c = 0; c < size; ++c)
array[c] = NULL;
}
int get_average() {
for (c = 0; c < size; ++c)
average+=array[c];
if (size != 0)
return (average/size);
else
return (-1);
}
int find_low() {
lowspot = 0;
for (c = 0; c < size; ++c) {
if (array[c] < array[lowspot])
lowspot = c;
}
return (lowspot);
}
void output_all() {
for (c = 0; c < size; ++c)
cout << array[c] << endl;
}
void sel_sort() {
tmparray = new int [size];
tmpl = 0;
for (c = 0; c < size; ++c) {
tmpl = find_low();
tmparray[c] = array[c];
array[c] = 99999;
}
array = tmparray;
delete [] tmparray;
}
private:
int size;
int c;
int average;
int lowspot;
int tmpl;
};
int main()
{
int averg =0;
MyClass Array(3);
Array.array[1] = 6;
Array.array[2] = 3;
Array.array[3] = 9;
Array.output_all;
Array.sel_sort;
Array.output_all;
return(0);
}
I'm not very good at OOP yet, so I was wondering what I can do to this code to get rid of the error (probably from memory management) and to make the methods output_all and sel_sort work properly... =|
If anyone could help, I'd appreciate it