I am looking for some help on some various errors and problems. This is my header file in which I am getting various errors in my for loops saying expected primary expression before } token.

#include <iostream>
using namespace std;

template <class T>                                
class basicArray
{
      public:                                                                           
              basicArray();
              basicArray(int arraySize);                            
              T getSize();
              T initArray();
              T printArray();
              T sortArray();
      private:
              T *data;
              int size;  
};      

//instantiate data as a 16 element array
template <class T>
basicArray<T>::basicArray()
{
              T data[16];
}

/*confused if this is right. one argument constructor with parameter that gives the size of the array and stores the value in size. instantiate data as an array of type with size number ofelements. */
template <class T>
basicArray<T>::basicArray(int arraySize )
{
              arraySize = size;   
              data = new T[size];
}
//getsize method return the size of the array
template <class T>
T basicArray<T>::getSize()
{
              return size;
}     
//initialize the array with random values         
template <class T>           
T basicArray<T>::initArray()                        
{                                                      
       int i;
             
       srand(0);                                          
       for(i=0, i<size, i++)                              
       {                                
                a[i] = rand() %100;
       }
}
//print method for the array
template <class T>
T basicArray<T>::printArray()                                       
{                                                           
       int i;
             
       for(i=0, i<size, i++)
       {                                                    
             cout << "Array["<<i<<"]= " << a[i] << endl;
       }      
}
//sort method for the array
template <class T>
T basicArray<T>::sortArray()                            
{                                                           
       int i, j;
       int indexMin;
       int valueMin;
             
       for(i=0, i<size, i++)                                
       {
       indexMin = i;
       valueMin = a[i];
                   
             for(j=i+1, j<arraySize,j++)
             {
                      if(a[j] < valueMin)
                      {
                              indexMin = j;
                              valueMin = A[j];
                      }
             }
       a[indexMin] = A[i];
       a[i] = valueMin;
       }
}

In my main function I need to call initArray, then printArray, then sortArray, and printArray to have an output looking like Array[0] = 53. A little confused with this.

for ( /* ... */ [B];[/B] /* ... */ [B];[/B] /* ... */ )

not

for ( /* ... */ [B],[/B] /* ... */ [B],[/B] /* ... */ )

you need to separate the parts of a for loop with semicolons, not commas.

also line 30 should be size = arraysize not the other way around.

Great, got that working. For my main function would it be something like this if I want to call each of these functions.

int main()
{
    basicArray<int> dataArray;
    
    dataArray.initArray();
    dataArray.printArray();
    dataArray.sortArray();
    dataArray.printArray();
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

i would avoid using system("pause") in your programs. if you search this site you will find some nice examples why not to.

A suggestion would be to add another member function like

template <class T>
T basicArray<T>::method()
{
    initArray();
    printArray();
    sortArray();
    printArray();
}

So then your main function would be

int main()
{
    basicArray<int> dataArray;
    dataArray.method();
    std::cin.get();
}

This is useful, only if you are thinking of performing the same operations. But practically might be un-necessary.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.