Thursday, July 9, 2009

C++ array function programming. PLEASE HELP!!!?

How would you implement the following two functions?





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





double GetData(int); //Returns value of the int-th element. If passt the array boundaries, then return the first or last element.





Please help and explain.

C++ array function programming. PLEASE HELP!!!?
May be you can post your requirements at http://homework.gionram.com/


and let many programmers bid for your project.


You can hire whoever you like.





Do not pay any money afront however.
Reply:Are we talking just an independent function or a class member function? I can only assume you mean a class member function since you did not include the array itself in the parameters.





class MyArray


{


private:


m_Array[ARRAY_INDICES]





public:


const int ARRAY_INDICES=10;





void SetData(int n, double val)


{


if ( n %26lt; 0 || n %26gt;= ARRAY_INDICES )


{


// maybe throw an exeption


return;


}


m_Array[n] = val;


}





double GetData(int n)


{


if ( n %26lt; 0 || n %26gt;= ARRAY_INDICES )


{


// maybe throw an exeption


return;


}


return m_Array[n];


}





};

carnation

No comments:

Post a Comment