
Emmma W.
asked 07/06/21Slove the task 03 in c++
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 3: Modify the header file and the source files again, so that it works for two dimensional array where all the rows are the same size. The user will specify the number of rows and columns as well as the content of the array, which you will take as input from user in the main function.
1 Expert Answer

Patrick B. answered 07/07/21
Math and computer tutor/teacher
using namespace std;
#include <iostream>
#ifndef _DYNAMIC_ARRAY
#include "DynamicArray.h"
#endif
Go()
{
DynamicArray dummy();
int n=5;
DynamicArray A(n);
int iNum;
for (int iLoop=0; iLoop<n; iLoop++)
{
cout << " Please input integer #" << (iLoop+1) << " of " << n << ":>";
cin >> iNum;
A.IndexerSetAtIndex(iLoop,&iNum);
}
A.Dump((char*)" 5 integers ");
int numRows=-1, numColumns=-1;
while (numRows<0)
{
cout << "How many rows :>";
cin >> numRows;
}
numColumns=-1;
while (numColumns<0)
{
cout << "How many columns :>";
cin >> numColumns;
}
DynamicArray2D matrix(numRows,numColumns);
for (int rowLoop=0; rowLoop<numRows; rowLoop++)
{
for (int columnLoop=0; columnLoop<numColumns; columnLoop++)
{
cout << " Please input integer @ row # " << (rowLoop+1) << ": column # " << (columnLoop+1) << " :>";
cin >> iNum;
matrix.IndexerSetAtIndex(rowLoop,columnLoop,&iNum);
}
}
matrix.Dump((char*)"matrix");
}
int main(int argc, char** argv)
{
Go();
return 0;
}
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
header and C++ source code in your other postings. too big to fit here07/07/21