I am getting this compile error when I run the below program:
Error : illegal struct/union/enum/class definition
bubbleSort.cpp line 15 double[] a;
Error : declaration syntax error
bubbleSort.cpp line 17 };
Error : undefined identifier 'a'
bubbleSort.cpp line 21 a = new double[max];
Error : undefined identifier 'a'
bubbleSort.cpp line 27 a[nElems] = value;
Error : undefined identifier 'a'
bubbleSort.cpp line 35 cout << a[j]+ " ";
Error : undefined identifier 'a'
bubbleSort.cpp line 44 if(a[in]>a[in+1])
Error : undefined identifier 'a'
bubbleSort.cpp line 50 double temp = a[one];
Error : undefined identifier 'a'
bubbleSort.cpp line 51 a[one] = a[two];
Error : undefined identifier 'a'
bubbleSort.cpp line 52 a[two] = temp;
Error : function call 'ArrayBub()' does not match
'ArrayBub::ArrayBub(int)'
'ArrayBub::ArrayBub(const ArrayBub &)'
bubbleSort.cpp line 58 ArrayBub arr;
Error : illegal operand
bubbleSort.cpp line 59 arr = new ArrayBub(maxSize);
Error : illegal operand
bubbleSort.cpp line 75 cout<< arr.display();
Error : illegal operand
bubbleSort.cpp line 79 cout << arr.display();
Your insights are appreciated, thanks
#include <iostream.h>
class ArrayBub
{
public:
ArrayBub(int);
void insert(double);
void display();
void bubbleSort();
void swap(int, int);
private:
double[] a;
int nElems;
};
ArrayBub::ArrayBub(int max)
{
a = new double[max];
nElems = 0;
}
void ArrayBub::insert(double value)
{
a[nElems] = value;
nElems++;
}
void ArrayBub::display()
{
for(int j=0; j<nElems; j++)
{
cout << a[j]+ " ";
}
}
void ArrayBub::bubbleSort()
{
int out, in;
for (out=nElems-1; out>1; out--)
for(in=0; in<out; in++)
if(a[in]>a[in+1])
swap(in, in+1);
}
void ArrayBub::swap(int one, int two)
{
double temp = a[one];
a[one] = a[two];
a[two] = temp;
}
int main()
{
int maxSize = 100;
ArrayBub arr;
arr = new ArrayBub(maxSize);
arr.insert(2213);
arr.insert(33);
arr.insert(2);
arr.insert(58);
arr.insert(987);
arr.insert(11);
arr.insert(47);
arr.insert(7);
arr.insert(223);
arr.insert(26);
arr.insert(58);
arr.insert(7);
cout<< arr.display();
arr.bubbleSort();
cout << arr.display();
return 0;
}



LinkBack URL
About LinkBacks




