Mange errors
1>c:\documents and settings\makhdoom\my documents\visual studio 2005\projects\dynarray\dynarray\dynarray.h(61) : error C2061: syntax error : identifier 'ostream'1>c:\documents and settings\makhdoom\my documents\visual studio 2005\projects\dynarray\dynarray\dynarray.h(61) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\makhdoom\my documents\visual studio 2005\projects\dynarray\dynarray\dynarray.h(61) : error C2805: binary 'operator <<' has too few parameters
1>c:\documents and settings\makhdoom\my documents\visual studio 2005\projects\dynarray\dynarray\main.cpp(14) : error C2065: 'cout' : undeclared identifier
1>c:\documents and settings\makhdoom\my documents\visual studio 2005\projects\dynarray\dynarray\main.cpp(14) : error C2065: 'endl' : undeclared identifier
1>Generating Code...
____________________________________________________________
#include "iostream"
typedef double itemType; // need for another type, change it here
class dynarray
{
/*
* Outout a representation of this array to an output stream 'str'. Say,
*
* dynarray var1;
* ............
* Do somthing with var1.
* ............
* cout << var1 ---> This function will be called now.
* 'cout' will be 'str'.
* 'var1' will be 'rhs'.
* ............
*
* 'str' => The output stream.
* 'rhs' => The array to the right side of '<<' operator.
*
* Returns: The output stream after appending the representation of this array.
* Throws: None.
*/
friend ostream& operator<<( ostream &str, const dynarray &rhs );
public:
/*
* Create an arrays of this class.
*
* 's' => Initial size of the array. Default size is 0.
* 'inc' => Initial increment of the array. Default increment is 5.
*
* Returns: Nothing.
* Throws:
* INVALID_SIZE if 's' is negative.
* INVALID_INCREMENT if 'inc' is negative.
* OUT_OF_MEMORY if memory is not available.
*/
dynarray( int s = 0, int inc = 5 );
/*
* Create an object of this class. The information (size, capacity, data etc)
* will be copied from 'rhs' to 'this'.
*
* 'rhs' => An object of 'dynarray'.
*
* Returns: Nothing.
* Throws:
* OUT_OF_MEMORY if memory is not available.
*/
dynarray( const dynarray &rhs );
/*
* Destroy the object. The memory of the array will be freed.
*
* Returns: Nothing.
* Throws: None.
*/
~dynarray();
/*
* The item 'item' will be stored after the last element of this array.
* If no space is available, then the capacity will be increased at the value of 'inc'.
* For this, necessary spaces will be allocated.
*
* 'item' => The item to insert.
*
* Returns: Nothing.
* Throws:
* OUT_OF_MEMORY if memory is not available.
*/
void push_back( itemType item );
/*
* The item 'item' will be stored at the position 'pos'. All the elements from 'pos'
* to the last will be shifted to the right by 1 step. For this, necessary spaces
* will be allocated. If 'pos' equals to 'num', then 'item' will be placed at the last.
*
* 'item' => The item to insert.
* 'pos' => The position where to insert. It must be in the range [0, num].
*
* Returns: Nothing.
* Throws:
* INVALID_POSITION if 'pos' is not in the range [0, num].
* OUT_OF_MEMORY if memory is not available.
*/
void insert( itemType item, int pos );
/*
* Remove the last element of the array from it. Also returns this element.
* After removing the element, if the extra space (capacity - size) in the array
* is more than 2 * increment, then 'inc' amount of space will be truncated.
* For example, say, size = 20, capacity = 20, inc = 5.
* Now if we call 'pop_back()' 10 times, then size = 10, capacity = 20, inc = 5.
* Next call to this function will truncate the array. Spaces will be freed.
* Then the situation will be, size = 9, capacity = 15, inc = 5. The other 5 spaces
* are freed.
*
* Returns: The item which will be removed (popped).
* Throws:
* POP_NOT_POSSIBLE if no data exists in the array.
*/
itemType pop_back( );
/*
* The element at the position 'pos' will be removed from the array. All the elements
* from 'pos + 1' to the last will be shifted to the left by 1 step. After removing the
* element, if the extra space (capacity - size) in the array is more than 2 * increment,
* then 'inc' amount of space will be truncated. This case is similar to 'pop_back()'.
*
* 'pos' => The position of the deleting item. It must be in the range [0, num).
*
* Returns: The item which will be erased.
* Throws:
* INVALID_POSITION if 'pos' is not in the range [0, num).
*/
itemType erase( int pos );
/*
* Free all the spaces of the array. After calling this function, the situation will be
* size = 0, capacity = 0. 'inc' will be retained.
*
* Returns: Nothing.
* Throws: None.
*/
void clear( );
/*
* Return the size of the array.
*
* Returns: The size of the array.
* Throws: None.
*/
int size( ) const;
/*
* Check whether the array is empty or not.
*
* Returns: true if there is no data in the array (i.e., if size = 0).
* false otherwise.
*
* Throws: None.
*/
bool empty( ) const;
/*
* The element at the position 'pos' will be returned.
*
* 'pos' => The position of the requesting item. It must be in the range [0, num).
*
* Returns: The item which is at 'pos'.
* Throws:
* INVALID_POSITION if 'pos' is not in the range [0, num).
*/
itemType &at( int pos ) const;
//////////////////////////////////////////////////////////////////////
// overloaded operators
/*
* Copy the array 'rhs' to 'this'. Say,
* dynarray var1;
* ............
* Do somthing with var1.
* ............
* dynarray var2;
* var2 = var1. -----> This function will be called now.
* 'var2' will be 'this'.
* ............
*
* 'rhs' => The right side object which will be copied to 'this'.
*
* Returns: Constant reference to this array.
* Throws:
* OUT_OF_MEMORY if memory is not available.
*/
const dynarray &operator=( const dynarray & rhs);
/*
* Return the item at the position 'pos'. Say,
* dynarray var1;
* ............
* Do somthing with var1.
* ............
* itemType a = var1[3] ---> This function will be called now.
* 'var1' will be 'this'.
* 'pos' will be 3.
* ............
*
* 'pos' => The position of the requested item.
*
* Returns: The reference to the item at position 'pos'.
* Throws:
* INVALID_POSITION if 'pos' is not in the range [0, num).
*/
itemType & operator[]( int pos ); // non const variant
/*
* Same as above 'operator[]'. But this time, constant reference to the item
* will be returned.
*
* 'pos' => The position of the requested item.
*
* Returns: Constant reference to the item at position 'pos'.
* Throws:
* INVALID_POSITION if 'pos' is not in the range [0, num).
*/
const itemType & operator[]( int pos ) const; // const variant
/*
* Build a new array by concatenating the elements of 'this' and 'rhs'. If 'this'
* has the elements { 10, 12, 13 } and 'rhs' has the elements { 23, 1, 20 }, then
* the new array will have { 10, 12, 13, 23, 1, 20 }. Say,
*
* dynarray var1;
* ............
* Do somthing with var1.
* ............
* dynarray var2;
* ............
* Do somthing with var2.
* ............
* dynarray newVar = var1 + var2 ---> This function will be called now.
* 'var1' will be 'this'.
* 'var2' will be 'rhs'.
* ............
*
* 'rhs' => The object to the right side of '+' operator.
*
* Returns: New array after concatenating 'this' and 'rhs'.
* Throws:
* OUT_OF_MEMORY if memory is not available.
*/
dynarray operator+( const dynarray &rhs );
/*
* Change 'this' to a new array by concatenating the elements of 'this' and 'rhs'.
* If 'this' has the elements { 10, 12, 13 } and 'rhs' has the elements { 23, 1, 20 },
* then 'this' will be now { 10, 12, 13, 23, 1, 20 }. Say,
*
* dynarray var1;
* ............
* Do somthing with var1.
* ............
* dynarray var2;
* ............
* Do somthing with var2.
* ............
* var1 += var2 ---> This function will be called now.
* 'var1' will be 'this'.
* 'var2' will be 'rhs'.
* ............
*
* 'rhs' => The object to the right side of '+=' operator.
*
* Returns: Reference to this array after being concatenated by 'rhs'.
* Throws:
* OUT_OF_MEMORY if memory is not available.
*/
dynarray &operator+=( const dynarray &rhs );
/*
* Check 'this' to 'rhs' for equality. Say,
*
* dynarray var1;
* ............
* Do somthing with var1.
* ............
* dynarray var2;
* ............
* Do somthing with var2.
* ............
* if (var1 == var2) ---> This function will be called now.
* 'var1' will be 'this'.
* 'var2' will be 'rhs'.
* ............
*
* 'rhs' => The array to the right side of '==' operator.
*
* Returns: True if 'this' and 'rhs' are euqal. false otherwise.
* Throws: None.
*/
bool operator==( const dynarray &rhs );
/*
* Check 'this' to 'rhs' for inequality. Say,
*
* dynarray var1;
* ............
* Do somthing with var1.
* ............
* dynarray var2;
* ............
* Do somthing with var2.
* ............
* if (var1 != var2) ---> This function will be called now.
* 'var1' will be 'this'.
* 'var2' will be 'rhs'.
* ............
*
* 'rhs' => The array to the right side of '!=' operator.
*
* Returns: True if 'this' and 'rhs' are ineuqal. false otherwise.
* Throws: None.
*/
bool operator!=( const dynarray &rhs );
//////////////////////////////////////////////////////////////////////////////
// optional functions
/*
* Returns the last element in the array.
*
* Returns: Last element in the array.
* Throws:
* BACK_NOT_POSSIBLE if there is no data in the array.
*/
itemType &back( ); // optional
/*
* Returns the 1st element in the array.
*
* Returns: 1st element in the array.
* Throws:
* FRONT_NOT_POSSIBLE if there is no data in the array.
*/
itemType &front( ); // optional
/*
* Returns the capacity of the array.
*
* Returns: Capacity of the array.
* Throws: None
*/
int capacity( ) const; // optional
/*
* Check whether 'item' exists in the array or not.
*
* 'item' => The item whose existence is being traced.
*
* Returns: true if 'item' exists in the array. false otherwise.
* Throws: None
*/
int contains( const itemType &item); // optional
/*
* Resize the array. This may increase or decrease the array. If the size is
* increased, then extra space will be filled with 'fill'. If the size is
* decreased, then space will be truncated. This time data may be lost.
*
* 'newSize' => The new size of the array.
* 'fill' => The data with which extra space will be filled.
*
* Returns: Nothing.
* Throws:
* OUT_OF_MEMORY if memory is not available.
*/
void resize( int newSize, itemType fill = NULL ); // optional
/*
* Check 'this' to 'rhs'. Say,
*
* dynarray var1;
* ............
* Do somthing with var1.
* ............
* dynarray var2;
* ............
* Do somthing with var2.
* ............
* if (var1 < var2) ---> This function will be called now.
* 'var1' will be 'this'.
* 'var2' will be 'rhs'.
* ............
*
* 'rhs' => The object to the right side of '<' operator.
*
* Returns: True if 'this' is less than 'rhs'. false otherwise.
* Throws: None.
*/
bool operator< ( const dynarray &rhs ); // optional
/*
* Check 'this' to 'rhs'. Say,
*
* dynarray var1;
* ............
* Do somthing with var1.
* ............
* dynarray var2;
* ............
* Do somthing with var2.
* ............
* if (var1 <= var2) ---> This function will be called now.
* 'var1' will be 'this'.
* 'var2' will be 'rhs'.
* ............
*
* 'rhs' => The object to the right side of '<=' operator.
*
* Returns: True if 'this' is less than or equal to 'rhs'. false otherwise.
* Throws: None.
*/
bool operator<=( const dynarray &rhs ); // optional
/*
* Check 'this' to 'rhs'. Say,
*
* dynarray var1;
* ............
* Do somthing with var1.
* ............
* dynarray var2;
* ............
* Do somthing with var2.
* ............
* if (var1 > var2) ---> This function will be called now.
* 'var1' will be 'this'.
* 'var2' will be 'rhs'.
* ............
*
* 'rhs' => The object to the right side of '>' operator.
*
* Returns: True if 'this' is greater than 'rhs'. false otherwise.
* Throws: None.
*/
bool operator> ( const dynarray &rhs ); // optional
/*
* Check 'this' to 'rhs'. Say,
*
* dynarray var1;
* ............
* Do somthing with var1.
* ............
* dynarray var2;
* ............
* Do somthing with var2.
* ............
* if (var1 >= var2) ---> This function will be called now.
* 'var1' will be 'this'.
* 'var2' will be 'rhs'.
* ............
*
* 'rhs' => The object to the right side of '>=' operator.
*
* Returns: True if 'this' is greater than or equal to 'rhs'. false otherwise.
* Throws: None.
*/
bool operator>=( const dynarray &rhs ); // optional
private:
//////////////////////////////////////////////////////////////////////////
// private functions
/*
* Copy the array 'rhs' to 'this'.
*
* 'rhs' => The array which will copied to 'this'.
*
* Returns: Nothing.
* Throws:
* OUT_OF_MEMORY if memory is not available.
*/
void copy_from( const dynarray &rhs );
/*
* Allocate 'n' amount of spaces.
*
* 'n' => The number of space which will be allocated.
*
* Returns: The pointer to the allocated array of 'n' items.
* Throws:
* OUT_OF_MEMORY if memory is not available.
*/
itemType* try_allocate_space( int n );
/*
* Free all the allocated spaces for this array.
*
* Returns: Nothing.
* Throws: None.
*/
void try_deallocate_space();
//Data Members.
itemType *ptr; // pointer to the first element of the array
int cap; // capacity of the array
int num; // size of the array
int inc; //When an array is exhausted, 'inc' amount of space will be allocated.
};