Ok so I am currently stuck on what I should do next in a program I am working on. These are my instructions:
Design, implement, and test a class for storing integer arrays "safely". The array should be able to hold any number of integers up to 100.
In the class header file "SafeArray.h" students must define the class and specify the constructor/destructor functions, the public methods and private variables. In the class implementation file "SafeArray.cpp" students must implement the following operations:
constructor - to initialize the object.
copy constructor - to copy an object.
destructor - to delete the object.
set - allow the user to set a value of the array at a particular location.
get - allow the user to get a value of the array at a particular location.
print - print out the array.
add - add the elements of one array to another.
subtract - subtract the elements of one array from another.
The output of my program is suppose to look like this:
Set q1: 2, 3, 4
Print q1: 2, 3, 4
Set q2: 1, 4, -2
Print q2: 1, 4, -2
Add q2 to q1
Print q1: 3, 7, 2
Get q1 at 1: 7
If I could get some help on this I would greatly appreciate it. Here is the code I have so far.
#ifndef SAFEARRAY_H
#define SAFEARRAY_H
class Safe
{
private:
// Declare variables to store A, B and C
int A[100];
int size;
public:
// Declare Default Constructor
Safe();
// Copy Constructor:
Safe(Safe & orig);
// Declare Print Function
void print();
// Add and Subtract:
void add ( Safe & one );
void subtract(Safe & one) ;
// Declare Setter
int set( int value, int pos)
{
if (pos < 0 || pos >= size)
{
//error, out of range access
}
else A[pos] = value;
}
};
#endif /* SAFEARRAY_H */