Question
A array is an Abstract Data Type (ADT) with operations such as get , set , and size . This assignment focuses upon building and
A array is an Abstract Data Type (ADT) with operations such as get , set ,
and size . This assignment focuses upon building and using an array. Your task
is to implement an array template of integers and characters in C++. This
array will be different from C++ built-in arrays in the following ways:
The initial size of the array can be a run-time parameter, to implement
this you'll need to use the C++ new and delete operators.
Operations on the array will be range-checked thus, if you try to get or
set an array element that is out of range the operation will return a "failure"
status.
Your task is to write C++ methods that operate upon objects of class Array.
Array.h, Array.cpp, and main.cpp are included below.
The Array.h includes class declaration of ADT Array.
The main.cpp is an empty test driver allows you to test your code.
The Array.cpp is where you will add the methods to implement the Array ADT.
================================================================
#ifndef Array_h
#define Array_h
#include
template
//! Constructor (uninitialized) // Dynamically create an uninitialized array. // Throw
//! Constructor (initialized) // Dynamically initialize an array. // Throw
//! Copy constructor // Perform initialization by using another instance. // Throw
//! Assignment operator '=' // Assignment operator performs an assignment by // making a copy of the contents of parameter // e.g., *this == s will return true. // Note that // if the
//! Destructor // Clean up the array (e.g., delete dynamically allocated memory) ~Array (void);
// === Set/get method ===
//! Transformer (Setter) // Set an item in the array at location index. // Return -1 if index is larger than the size() of the array, // else return 0; int set (const T& new_item, size_t index);
//! Observer (Getter) // Get an item in the array at location index. // Return -1 if index is larger than the size() of the array, // else return 0; int get (T& item, size_t index) const;
//! Item retrieving operator '[index]' // Returns a reference to the
//! Item setting operator '[index]' // Set an item in the array at location index without // checking for range errors; T& operator[] (size_t index);
//! Returns the current size of the array size_t size (void) const;
//! Comparison (equality) operator '==' // Compare this array with for equality. // Return true if the size()'s of the two arrays are equal and // all the elements from 0 ... size() are equal, else false. bool operator== (const Array& s) const;
//! Comparison (inequality) operator '!=' // Compare this array with for inequality // such that <*this> != is always the complement of the // boolean return value of <*this> == . bool operator!= (const Array& s) const;
private: //! Within range checking // Returns true if
//! Maximun size of the array // i.e., the total number of
//! Current size of the array // This starts out being == to //
//! Pointer to the array's storage buffer T* array_; };
#endif //Array_h
===================================================
#include "Array.h" #include
template
template
template
template
template
template
template
template
template
template
template
template
template
=================================================
#include "Array.h" #include "Array.cpp"
#include
int main(int argc, char* argv[]) { cout << " " <<" "; return 0; }
=================================================
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started