views:

41

answers:

1
class  array {

int * ptr ;
int length ;
void  realloc (int) ;

public :

// all public functions declarations

};

and the main( ) function :

int  main( )
{

const int dim = 5 ;
array a;
a.initialize(dim);
a.print();

for ( int I = 0; I < a.get_length() ; i++)
a.store(i , i);
a.print();

a.increment();
a.append(6);
a.print();

a.reverse();
a.print();

a.trunc();
a.print();} 
a.del();

return 0;
}

write the member function definitions for the class array

  • The private function realloc() gets heap space according to the value of its input argument. Of course, it must ensure that the existing heap space is copied into this new space, the old space is released, the length field is set accordingly. And iptr points to the new space.
  • The function initialize() stores the value of its input argument into length and allocates that many integers from the heap. It then sets each element to the value 0.
  • The accessor function get_lengt() returns the value of the length.
  • The function store() stores its second argument into the array position indicated by its first argument.
  • The function increment() adds 1 to each element in the array.
  • He function append() calls upon the function realloc() to increase the size of the array by 1. It then appends its input argument to the end of the array.
  • The function revers() reverses the order of elements in the array.
  • The function trunc() calls upon the function realloc() in order to truncate the last element in the array.
  • The function print() outputs each array element with its index position.
  • The function del() releases the heap space.
+1  A: 

You should understand that this is the place for knowledge and experience sharing. It's not for getting my works done without any effort from my side. And if you continue to copy other peoples' solution without trying the assignments, you are going to suffer in future.

taskinoor