

Following the instruction
This is c++ programming
#Answer
DynamicArray.h
#ifndef DYNAMICARRAY_H_INCLUDED
#define DYNAMICARRAY_H_INCLUDED
#endif // DYNAMICARRAY_H_INCLUDED
class DynamicArray {
private:
int arraysize;
int currentsize;
int* arrayPtr, *iterator;
public:
DynamicArray(int isize);
DynamicArray();
~DynamicArray();
bool additem(int item);
int getitem(int index);
int getcurrentsize();
void resize();
};
DynamicArray.cpp
#include <iostream>
#include <algorithm>
#include <cstddef>
using namespace std;
class DynamicArray {
private:
int arraysize;
int currentsize;
int* arrayPtr, *iterator;
public:
DynamicArray(int isize) {
arrayPtr = new int[isize];
currentsize=isize;
arraysize=isize;
iterator = arrayPtr;
}
DynamicArray() {
arraysize = 0;
currentsize = 0;
arrayPtr = nullptr;
iterator = arrayPtr;
}
~DynamicArray() {
delete[] arrayPtr;
arrayPtr = nullptr;
}
bool additem(int item) {
if(*iterator) {
*iterator = item;
++iterator;
}
else {
resize();
*iterator = item;
}
return true;
}
int getitem(int index) {
return (*arrayPtr + index);
}
int getcurrentsize() {
return currentsize;
}
void resize() {
int* temp = new int[arraysize];
currentsize+=arraysize;
std::copy(arrayPtr, arrayPtr + arraysize, temp);
delete [] arrayPtr;
arrayPtr = temp;
iterator = arrayPtr + arraysize;
}
};
int main() {
int isize,temp,i=0,j=0,avg=0,sum=0;
cout<<"Enter size of array: ";
cin>>isize;
DynamicArray d = DynamicArray(isize);
bool b = true;
while(j<2) {
i++;
cout<<"Enter value for array: ";
cin>>temp;
sum+=temp;
d.additem(temp);
if(i == isize) {
avg=sum/isize;
cout<<"Average: "<<avg<<endl;
i=0;
j++;
}
}
return 0;
}
Following the instruction This is c++ programming Lab Tasks: 1. Define a dynamic array class in...
Variable Size Array with Classes, Testing. Study Code and Object Definition Windows of Microsoft Visual Studio described here. As you work on the below project, demonstrate to the instructor the usage of this feature. Create a project titled Lab11_VarArrayTest. Implement the dynamically expanding and contracting array of doubles described in the previous lab as a class. You should use this class definition. The class attributes are a pointer to the dynamically allocated array dAarray and the array size size This...
C++ problem with dynamic arrays is that once the array is created using the new operator the size cannot be changed. For example, you might want to add or delete entries from the array similar to the behavior of a vector. This project asks you to create a class called DynamicStringArray that includes member functions that allow it to emulate the behavior of a vector of strings. The class should have: A private member variable called dynamicArray that references a...
When running the program at the destructor an exception is being thrown. Can someone help me out? vararray.h: #ifndef VARARRAY_H_ #define VARARRAY_H_ class varArray { public: varArray(); // void constructor int arraySize() const { return size; } // returns the size of the array int check(double number); // returns index of element containg "number" or -1 if none void addNumber(double); // adds number to the array void removeNumber(double); // deletes the number from the array ...
Code in C #### Array of pointers 1. Define a structure. 2. Allocate a *dynamic* array of **pointers** to structures. What is the type of the array variable? 3. Sketch the array on the worksheet. 3. Assign values in a loop. 4. Free all dynamic memory. Mind the order to avoid leaving dangling pointers!
C Programming Language 2(a) Define a struct with 1 int array named i, 1 float array named f, and one double array named d, each of size M. (b)Declare array x with N of those structs. (c)Write a void function to traverse array x (using a pointer) assigning to each element in each array d (in each struct in array x) the sum of the corresponding elements in arrays i and f (in the same struct). Use 3 pointers (of...
C++ please, thank you! Design a class named ArrayClass that has an array of floating-point numbers. The constructor should accept an integer argument and allocate the array on the heap to hold that many numbers. The default constructor should allocate an array that can hold one number. When the user attempts to store items, you must make a copy constructor that correctly produces a new copy of an ArrayClass object from an old one. If the user attempts to store...
In C++ and comment so I UNDERSTAND Implement a class named DynamicArray that has the following members: A pointer to hold a dynamically allocated array, of type int. A member variable to hold the size of the array. A default constructor, which will allocate an array of size 10 A parameterized constructor, which takes a size and use the size to allocate array. A copy constructor, which performs deep copy. A copy assignment operator, which performs deep copy and supports...
1. Here are codes to define a stack class based on dynamic array, please complete the copy constructor //--- Definition of Stack copy constructor Stack::Stack(const Stack & original) : myCapacity(original.myCapacity), myTop(original.myTop) { //--- Get new array for copy myArray = new(nothrow) StackElement[myCapacity]; if (myArray != 0) // check if memory available // copy original's array member into this new array { // Please complete the function here } else { cerr << "*Inadequate memory to allocate...
How to initialize a dynamic two-dimensional array with values? (C++) Here's my problem... # include using namespace std; int main() { // Q#5 - dynamic 2d arrays, indexing via subscript operator, pointer arithmetic // tic tac toe board is an array of int pointers // each int pointer in the board points to a row // declare a pointer to an array of int pointers (i.e. a pointer to a pointer of type int) const...
I’m giving you code for a Class called GenericArray, which is an array that takes a generic object type. As usual this is a C# program, make a new console application, and for now you can stick all of this in one big file. And a program that will do some basic stuff with it Generic Array List What I want you to do today: Create methods for the GenericArray, Easy(ish): public void Append (T, value) { // this should...