Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have to create a function called append, it will be passed a value, and the value will be added to the end of the array if theres room. if added the function returns true. if not it returns false. how can i do this. below is the current header of the class. what would the prototype look like. thanks for any help.
#include <iostream>
using namespace std;#ifndef INTEGERLIST_H
#define INTEGERLIST_Hclass integerList
{
public:
integerList(); //Default constructor, 0 size array
integerList(int sz); //Constructor create array and initialize values to 0
~integerList(); //Destructorvoid create(int sz); //Allocates the array and initializes value to 0
void clear(); //Removes the array space
int getSize() const; //Returns the numElements
bool setElement(int loc, int value); //If loc valid, assigns value at index loc and
//Returns true, otherwise return false
bool getElement(int loc, int &value) const; //If loc valid, assign value from there and
//return true, otherwise return false
private:
int *list; //Pointer to array
int numElements; //Number of elementsbool isValid(int loc) const; //Private function used to make sure the loc is in range
};ostream &operator<<(ostream &stream, const integerList &list);
#endif

I have to create a function called append,
append();it will be passed a value,
append(int value);the function returns true . . . false.
bool append(int value);

Also,
#include <iostream>
can be replaced with
#include <iosfwd>
for better efficiency.
And
using namespace std;
is a bad idea in a header file.

Thanks guys, but I don't understand the actual code in the
fuction that will add elements to my dynamic array.the given prototype is
integerList::appendElements(integerList &array)
thanks.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |