Monday, May 24, 2010

C++ array programming. Please help and/or assist!?

I'm currently trying to develop an array class that addresses some of the shortcomings of the standard C++ array implementation.





The file has functions for an array. I'm having trouble coding correct functions. Please help





public Array(int); //Constructor that uses the passed integer to set the size of the array.





public Array(int, double); //constructor that uses the passed integer to set the size of the array and initializes all elements to the passed double value





public SetData(int, double); //sets the int-th element to the value of the passed double.





I'm currently working on this, but these are giving me the most problems. Any advice or help is GREATLY appreciated. Any snippets of codes or comment lines are greatly appreciated as well.

C++ array programming. Please help and/or assist!?
okay, I won't give you an array, but think on this:





file TestClass.h





class test


{


public:


test(); //default constructor


test(int i); constructor that takes an integer


};





file test.cpp





#include %26lt;iostream%26gt;


#include %26lt;test.h%26gt;





test::test()


{


std::cout %26lt;%26lt; "default constructor" %26lt;%26lt; std::endl;


} //implementation of default constructor


test::test(int i)


{


std::cout %26lt;%26lt;"constructor with int" %26lt;%26lt; std::endl;


std::cout %26lt;%26lt; i %26lt;%26lt; std::endl;


}





file main.cpp





#include %26lt;iostream%26gt;


#include %26lt;test.h%26gt;





int main(int argc, char* argv[])


{


test t;


test t2( 3);





test *pt = new test(3);


test *pt1 = new test();





delete pt;


delete *pt1;


}


No comments:

Post a Comment