Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi everyone I posted this assignment couple days ago but no one can solve it ple

ID: 3708198 • Letter: H

Question

Hi everyone I posted this assignment couple days ago but no one can solve it please I need help with this assignment on c++

CISP 400 C++ Programming

ExpandArray class
For this project you will create a template class ExpandArray. It will be a fully functional type. It will contain the following:
// Constructors and Destructor

ExpandArray( int i = 0, float p = .5 );

// i is the index of the first element in your ExpandArray

// p is the percentage that this ExpandArray will grow or shrink

ExpandArray( const T*, unsigned s, int i = 0, float p = .5 );

// i is the index of the first element in your ExpandArray

// p is the percentage that this ExpandArray will grow or shrink

// s is the number of items pointed to by T*

ExpandArray( const ExpandArray& );

~ExpandArray( );//[1]
ExpandArray& operator=( const ExpandArray& );

// Insert the array or a pointer to an array into an out stream

friend ostream& operator<<( ostream&, const ExpandArray& );

friend ostream& operator<<( ostream&, const ExpandArray* );

// access the item at index 0 <= i < size (assuming standard indexing[2])

T& operator[]( int i );

const T& operator[]( int i ) const;

// Returns a sub array beginning at index first and going to index last-1

ExpandArray operator( )( int first, int last )const;

// Append either a new item or another ExpandArray beginning at index size

void append( const T& ); //[3]

void append( const ExpandArray& );

// return the number of items in the array

unsigned size( ) const

// Remove the item at index 0 <= i < size (assuming standard indexing)

void remove( int i );

// Remove the items from index first through index last-1

void remove( int first, int last );

// Remove the item at index size-1 (assuming standard indexing)

void remove( );

// Insert at index 0 <= i < size (assuming standard indexing)

void insert( int i, const T& );

// Insert at index 0 (assuming standard indexing)

void insert( const T& );

I need only  ExpandArray.h

Explanation / Answer

here is your file most of the function i implemented due to lack of time some are missing : ---------->>>>>>>>>>

#ifndef __EXPAND_ARRAY_H
#define __EXPAND_ARRAY_H
#include<iostream>

using namespace std;

template<class T>
class ExpandArray{
T *data;
unsigned int size_;
int first;
unsigned int capacity_;
float exp;
void expand();
void shrink();
public:
  // Constructors and Destructor
  ExpandArray( int i = 0, float p = .5 );
  // i is the index of the first element in your ExpandArray
  // p is the percentage that this ExpandArray will grow or shrink
  ExpandArray( const T*, unsigned s, int i = 0, float p = .5 );
  // i is the index of the first element in your ExpandArray
  // p is the percentage that this ExpandArray will grow or shrink
  // s is the number of items pointed to by T*
  ExpandArray( const ExpandArray& );
  ~ExpandArray( );//[1]
  ExpandArray& operator=( const ExpandArray& );
  // Insert the array or a pointer to an array into an out stream
  friend ostream& operator<<<>( ostream&, const ExpandArray<T>& );
  // access the item at index 0 <= i < size (assuming standard indexing[2])
  T& operator[]( int i );
  const T& operator[]( int i ) const;
  // Returns a sub array beginning at index first and going to index last-1
  ExpandArray operator( )( int first, int last )const;
  // Append either a new item or another ExpandArray beginning at index size
  void append( const T& ); //[3]
  void append( const ExpandArray& );
  // return the number of items in the array
  unsigned size( )const;
  // Remove the item at index 0 <= i < size (assuming standard indexing)
  void remove( int i );
  // Remove the items from index first through index last-1
  void remove( int first, int last );
  // Remove the item at index size-1 (assuming standard indexing)
  void remove( );
  // Insert at index 0 <= i < size (assuming standard indexing)
  void insert( int i, const T& );
  // Insert at index 0 (assuming standard indexing)
  void insert( const T& );
};
template<class T>
void ExpandArray<T>::append(const T &ele){
size_++;
if(size_ >= capacity_){
  expand();
}
data[size_-1] = ele;
}

template<class T>
void ExpandArray<T>::append(const ExpandArray<T> &oth){
for(int i = 0;i<oth.size();i++){
  append(oth[i]);
}
}
template<class T>
const T& ExpandArray<T>::operator[](int i)const{
return (*this)[i];
}
template<class T>
T& ExpandArray<T>::operator[](int i){
if(i < 0 || i >= size_){
  return (T)NULL;
}

return data[i];
}
template<class T>
unsigned ExpandArray<T>::size()const{
return size_;
}
template<class T>
ExpandArray<T>::ExpandArray(int i,float p){
first = i;
exp = p;
capacity_ = 10;
size_ = 0;
data = new T[10];
}

template<class T>
void ExpandArray<T>::expand(){
capacity_ = capacity_ + (int)(capacity_*exp);
T *new_data = new T[capacity_];
for(int i = 0;i<size_;i++){
  new_data[i] = data[i];
}
delete[] data;
data = new_data;
}

template<class T>
ExpandArray<T>::ExpandArray(const T *oth,unsigned s,int i,float p){
capacity_ = s + 10;
size_ = s;
first = i;
exp = p;
data = new T[capacity_];
for(int i = 0;i<s;i++){
  data[i] = oth[i];
}
}

template<class T>
ExpandArray<T>::ExpandArray(const ExpandArray<T> &oth){
*this = oth;
}

template<class T>
ExpandArray<T>::~ExpandArray(){
delete[] data;
}

template<class T>
ExpandArray<T>& ExpandArray<T>::operator=(const ExpandArray<T> &oth){
if(this == &oth){
  return *this;
}
size_ = oth.size_;
capacity_ = oth.capacity_;
first = oth.first;
exp = oth.exp;
delete[] data;
data = new T[capacity_];
for(int i = 0;i<size_;i++){
  data[i] = oth.data[i];
}

return *this;
}

template<class T>
void ExpandArray<T>::insert(int i,const T &ele){
if(i < 0 || i >= size_){
  return;
}
if(size_ >= capacity_){
  expand();
}
for(int j = size_;j > i;j--){
  data[j] = data[j-1];
}
data[i] = ele;
size_++;
}

template<class T>
void ExpandArray<T>::insert(const T &ele){
insert(0,ele);
}

template<class T>
void ExpandArray<T>::shrink(){
capacity_ = capacity_ - (int)(capacity_*exp);
T *new_data = new T[capacity_];
for(int i = 0;i<size_;i++){
  new_data[i] = data[i];
}
delete[] data;
data = new_data;
}

#endif

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote