Emmma W.

asked • 07/06/21

Slove the problem in c++.slove task01.So that i can copy & paste

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 <iostream>

#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 1: In the driver file (main.cpp), perform the following sub-tasks:


1. Create two objects of this class, one with no constructor argument and one with the argument 5.


2. Take five input values from the user and store them in the array inside the second object using the set method.


3. For the second object, print all the values you just stored. Note that, you cannot assign anything in the first object since the array inside it has size 0. Neither can you change the size of this array to some other size.





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.