Question: In C++ arraydb.hpp #ifndef __ARRAYDB_HPP__ #define __ARRAYDB_HPP__ #include using namespace std; template class ArrayDb { unsigned int size; protected: Type *arr_ptr; public: // Default constructor
In C++

arraydb.hpp
#ifndef __ARRAYDB_HPP__ #define __ARRAYDB_HPP__
#include using namespace std;
template class ArrayDb { unsigned int size; protected: Type *arr_ptr;
public: // Default constructor ArrayDb(void);
// Create a constructor that will accept the size of the array // and a value to initialize the array. Default initialization = 0 ArrayDb(unsigned int n, Type val = 0.0); // Initialize the array to another array given the length of the array ArrayDb(const Type *pn, unsigned int n); // Copy constructor ArrayDb(const ArrayDb & a); ~ArrayDb (void);
//Get array size unsigned int get_ary_size(void) const { return size; }
// Methods Type & operator[] (int i); const Type & operator[] (int i) const; ArrayDb & operator= (const ArrayDb & a); template friend ostream & operator &a); };
#endif
arraydb.cpp
#include "arraydb.hpp" #include using namespace std;
//Default constructor template ArrayDb::ArrayDb (void) { arr_ptr = NULL; size = 0; }
template ArrayDb::ArrayDb (unsigned int n, Type val) { arr_ptr = new Type[n]; if (arr_ptr == NULL) { cout template ArrayDb::ArrayDb (const Type *pn, unsigned int n) { arr_ptr = new Type[n]; size = n; for (int i = 0; i // Copy constructor template ArrayDb::ArrayDb (const ArrayDb & a) { size = a.size; arr_ptr = new Type[size]; for (int i = 0; i template ArrayDb::~ArrayDb (void) { cout template Type & ArrayDb::operator[] (int i) { //cout = size) { cerr } template const Type & ArrayDb::operator[] (int i) const { cout = size) { cerr template ArrayDb & ArrayDb::operator=(const ArrayDb & a) { if (this == &a) return *this;
delete arr_ptr; size = a.size; arr_ptr = new Type [size]; for (int i = 0; i
}
template ostream & operator &a) { cout }
template void display (ArrayDb & ar) { cout main.cpp
#include
#include arraydb.cpp
using namespace std;
int main (void) { unsigned int regions; cout > regions;
// Create an "array" of that size ArrayDb tons(regions); cout > tons[i]; // tons.operator[](i) } cout dup;
// 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; }
Description For this assignment, you are going to start with the arraydb class with templates. Instead of checking for errors and terminating the program, you are going to check for errors and throw exceptions when necessary. You will modify the arraydb class to eliminate any code that checks for errors and exits. You will need to write a Out_of_bounds_exception class for the out of bounds error. You are to redefine the what method and print out an approprie error for your program. You will write a main function that will test the arraydb class for errors. There are 2 types of errors in the arraydb function. You will need to figure out a way to cause both errors to occur and to be able to catch them in your program. One part of your test code will need to ask the user for an index. If the index is out of range, your program must use a try/catch block to catch the error and correct it. (Hint: Remember that C++ does throw some errors of its own. If C++ generates an error, you shouldn't duplicate it.) Description For this assignment, you are going to start with the arraydb class with templates. Instead of checking for errors and terminating the program, you are going to check for errors and throw exceptions when necessary. You will modify the arraydb class to eliminate any code that checks for errors and exits. You will need to write a Out_of_bounds_exception class for the out of bounds error. You are to redefine the what method and print out an approprie error for your program. You will write a main function that will test the arraydb class for errors. There are 2 types of errors in the arraydb function. You will need to figure out a way to cause both errors to occur and to be able to catch them in your program. One part of your test code will need to ask the user for an index. If the index is out of range, your program must use a try/catch block to catch the error and correct it. (Hint: Remember that C++ does throw some errors of its own. If C++ generates an error, you shouldn't duplicate it.)