Files
  • main.cpp
  • arraydb.cpp
  • arraydb.hpp
  • makefile
  • outofbounds.hpp
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "arraydb.cpp"
#include <iostream>
using namespace std;

#ifndef __ARITHARR_HPP__
#ifndef __LIMARR_HPP__

template <class Type>
void display (ArrayDb<Type> & ar)
{
   cout << "Func!\n";
   cout << ar;
   cout << "Func!\n";
}

int main (void)
{

  ArrayDb<int> test;

   unsigned int regions;
   cout << "Enter number of regions: ";
   cin >> regions;

   // Create an "array" of that size
   ArrayDb<double> tons(regions);
  
   cout << "Enter the regional sales in tons:\n";
   int i;
   for (i = 0; i < regions; i++)
   {
      cout << "Region " << (i+1) << ":  ";
      cin >> tons[i];
      // tons.operator[](i)
   }
   
   cout << tons;
   
    // Default object
   ArrayDb<double> dup;

   // Array assignment - calls the overloaded operator=
   dup = tons;
   cout << "Here's the original data:\n" << tons;
   cout << "Here's the copy :\n" << dup;

   // 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<double> bod (wts,5);
   
   cout << "Here are the weights:\n" << bod;

   //try to exceed array limit
   cout << "Index: value \n";

  try
  {
    cout << "Testing Out of Bounds Error with ranges!" << endl;
    for (int i = -2; i < 4 ; i++ )
      cout << "In index " << i << " " << tons[-1] << endl;
  }

  catch (OutOfBounds& i)
  {     
      cout << "\nOut of bounds caught!" << endl;
      cout << i.what() << endl << endl;     
  }

    cout << "FINISHED!\n";
   return 0;
}
#endif
#endif