Wednesday, September 22, 2010

Part 1 of Assignment due for Tuesday, Sept 28

Part II of this assignment will be given in class on Thursday, Sept 23.


Write a program called VarVec
.h file
_______________________________________
class VarVec
{
private:
     int size;
     double *pD; // * indicates a pointer to a double


public:
    VarVec(int sz = 5); // default size is 5 for this assignment, most commonly used size is 10

void putValue(int index, double d)
void print( ) // walks down each element of the array and displays

~VarVec ( ); //dstrcr

void resize (int ns);// change the size of the pD array, if smaller than original, just don't copy the end elements or you could just update the size, if larger than original, copy all elements from old array to new array, update pointer, change size variable and destruct the old array.
___________________________________________

.cpp file
______________________________________________________
VarVec::VarVec(int s)
:size(s), pD(new double[s]) {

size = s;
pD = new double[s];

double VarVec::getValue(int index){
   if(index<0 || index > size -1)
      cout<< "some error message";
      exit(); // to cancel the program
return *(pD + index);
_______________________________________________________

No comments:

Post a Comment