Switch to full style
For C/C++ coders discussions and solutions
Post a reply

Array C++ Class

Mon May 04, 2009 12:20 am

i would like to know what is the output for this program.

Code:
#include <iostream>

using std::cout;
using std::endl;
using std::ios;
#include<new>

#include<iomanip>
//using std::fix;
using std::setprecision;

template typename T >
class Array{
public:
    Array(
int=5);
    ~Array() {
delete[] arrayPtr; }
    
T arrayRef(int)const;
    
int getsize() const;

private:
    
int size;
    
*arrayPtr;
};
templatetypename T>
Array< 
>::Array(int x)
{
    
size=x;
    
arrayPtr[i] = 1.0 i;
}
template<typename T>
Array< >::arrayRef(int num)const
{
    return 
arrayPtr[num];
}
templatetypename T >
int Array<T>::getSize() const
{
return 
getSize;
}
template <typename T >
void printArray(const Array<T> &a)
{
    for (
int i=0ia.getSize(); i++)
        
cout << a.arrayRef(i) << " ";
    
cout << endl << endl;
}
int main()

    
int fixed;
    Array< 
int intArray(4);
    Array< 
double doubleArray;

    
cout << setprecision(2);
    
printArrayintArray );
    
printArraydoubleArray);

    return 
0;




Post a reply
  Related Posts  to : Array C++ Class
 Define class helper class to check the method existance     -  
 java abstract class,concrete class and interface     -  
 relationship between the Canvas class and the Graphics class     -  
 Array difference for associate array     -  
 Define class inside another class C++     -  
 inner class that is a member of an outer class?     -  
 compare an array with another array?     -  
 load class to applet- load frame class to applet     -  
 Add elements to the end of an array     -  
 Get array chunk     -