Question: In C++ For this assignment, you will use the arraydb class that was used as an example in class. You are to change the arraydb
In C++
For this assignment, you will use the arraydb class that was used as an example in class. You are to change the arraydb class to be a template class. Instead of only allowing arrays of type doubles, your program should allow any type to be used for the array in the class.
Implement iterators in the class. You are to test your program with all of the basic types and make sure it works.

arraydb.cpp
#include "arraydb.hpp" #include
//Default constructor ArrayDb::ArrayDb (void) { arr_ptr = NULL; size = 0; }
ArrayDb::ArrayDb (unsigned int n, double val) { arr_ptr = new double[n]; if (arr_ptr == NULL) { cout
ArrayDb::ArrayDb (const double *pn, unsigned int n) { arr_ptr = new double[n]; size = n; for (int i = 0; i
// Copy constructor ArrayDb::ArrayDb (const ArrayDb & a) { size = a.size; arr_ptr = new double[size]; for (int i = 0; i
ArrayDb::~ArrayDb (void) { if (arr_ptr != NULL) delete [] arr_ptr; }
double & ArrayDb::operator[] (int i) { //cout = size) { cerr
}
const double & ArrayDb::operator[] (int i) const { cout = size) { cerr
ArrayDb & ArrayDb::operator=(const ArrayDb & a) { if (this == &a) return *this;
delete arr_ptr; size = a.size; arr_ptr = new double [size]; for (int i = 0; i
}
ostream & operator
}
void display (ArrayDb & ar) { cout
#ifndef __ARITHARR_HPP__ #ifndef __LIMARR_HPP__ int main (void) { unsigned int regions; cout > regions;
// Create an "array" of that size ArrayDb tons(regions); cout > tons[i]; // tons.operator[](i) } cout
// Array assignment - calls the overloaded operator= dup = tons; cout
// Pass the array without passing size display (dup);
double wts[5] = {155.2, 189.6, 174.3, 256.9, 203.5};
// Initialize an ArrayDb to an array ArrayDb bod (wts,5); cout
//try to exceed array limit cout
return 0; } #endif #endif
arraydb.hpp #ifndef #define ARRAYDBHPP -ARRAYDB-HPP- - - . #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
