Emmma W.

asked • 07/06/21

Please slove it in C++.Task 02.

dynarr.h

#ifndef DYNARR_H_INCLUDED

#define DYNARR_H_INCLUDED

class dynArr { private: int *data;

int size;

public:

dynArr();

dynArr(int);

~dynArr();

void setValue(int, int);

int getValue(int); };

#endif // DYNARR_H_INCLUDED

dynarr.cpp

#include "dynarr.h"

#include

#include using namespace std;

dynArr::dynArr() {

data = NULL;

size = 0; }

dynArr::dynArr(int s)

{ data = new int[s];

size = s; }

dynArr::~dynArr()

{ delete [] data;

}

int dynArr::getValue(int index)

{ return data[index];

}

void dynArr::setValue(int index, int value)

{

data[index] = value;

} ;

Tasks:

Task 2: Modify the header and the source files. Add a member function void allocate(int s) which allows you to change the size of the array. Make sure that memory is not leaked.

1 Expert Answer

By:

Patrick B. answered • 07/07/21

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.