Order Now  +1 678 648 4277 

Trustworthy Array Class Interface Assignment Help

Are you struggling with the concepts of array class interface? Do you need a C++ assignment experts to assist you? Well, if you answered yes to any of these questions then you are already at the right place. We have introduced an exceptional array class interface assignment help service that covers all the areas related to this topic. You can get in touch with our experienced tutors at any time and have your project completed before your due date. Stop procrastinating! Avail of our array class interface homework help today.

Table Of Contents
  • Array Class Encapsulating A Fixed-size Dynamic Array
  • Array Class Interface
  • C++ Code Solution

Array Class Encapsulating A Fixed-size Dynamic Array

Design a class, Array, that encapsulates a fixed-size dynamic array of signed integers.
Write a program that creates an Array container of size 100 and fills it with random numbers in the range [1..999]. (Use std::rand() with std::srand(1).) When building the array, if the random number is evenly divisible by 3 or 5, store it as a negative number.
Within your pa12.cpp source code file, write a function for each of the following processes.
1. Print the array ten values to a line. Make sure the values are aligned in columns. Each column should have a width of 5.
2. Return the sum of all values in the array.
3. Return the address of the smallest value in the array.
Demonstrate each of the functions above and several of the Array class member functions in your main function.

Array Class Interface

///
/// @file Array.h (Array class interface)
/// @author
/// @date 2020-09-20
///
/// @note DO NOT MODIFY THIS FILE.
///
#ifndef ARRAY_H_
#define ARRAY_H_
#include
class Array {
public:
/// Default constructor. Constructs a new container with 'count' copies of
/// elements with value 'value'.
/// @param count The number of elements.
/// @param value Value to fill each element.
Array(std::size_t count, int value = 0);
/// Copy constructor. Constructs the Array with a copy of the
/// contents of 'other'.
/// @param other Array to copy.
Array(const Array& other);
/// Free the resources used by the container.
virtual ~Array();
/// Returns a reference to the element at specified position 'pos'.
/// @param pos Position of the element to return.
/// @return Reference to the requested element.
int& at(std::size_t pos);
const int& at(std::size_t pos) const;
/// Returns a reference to the first element in the container.
/// Calling front on an empty container is undefined.
/// @note For a container c, the expression 'c.front()' is equivalent
/// to '*c.begin()'.
/// @return Reference to the first element.
int& front();
const int& front() const;
/// Returns a reference to the last element in the container.
/// Calling back on an empty container is undefined.
/// @note For a container c, the expression return 'c.back()' is equivalent
/// to '{ auto tmp = c.end(); --tmp; return *tmp; }'
/// @return Reference to the last element.
int& back();
const int& back() const;
/// Returns a pointer to the first element of the container.
/// If the container is empty, the returned pointer will be equal to 'end()'
/// @return Pointer to the first element.
int* begin() { return m_list; }
const int* begin() const { return m_list; }
/// Returns a pointer to the element following the last element of the
/// container. This element acts as a placeholder; attempting to dereference
/// this pointer is undefined.
/// @return Pointer to the element following the last element.
int* end() { return m_list + size(); }
const int* end() const { return m_list + size(); }
/// Checks if the container has no elements, i.e., whether
/// 'begin() == end()'.
/// @return true if the container is empty, false otherwise.
bool empty() const;
/// Returns the number of elements in the container, i.e., the distance
/// between 'begin()' and 'end()'.
/// @return The number of elements in the container.
std::size_t size() const { return m_size; }
/// Assigns the given value 'value' to all elements in the container.
/// @param value The `value` to assign to the elements.
void fill(int value);
/// Exchanges the contents of this container with another.
/// @param other Container to exchange the contents with.
void swap(Array& other);
protected:
std::size_t m_size; ///< Number of elements allocated.
int* m_list; ///< Pointer to base of array.
};
// Non-Member Function(s)
/// Compares the contents of two arrays. Returns true if the contents of
/// lhs and rhs are equal, that is, whether each element in lhs compares
/// equal with the element in rhs at the same position.
/// Otherwise, returns false.
/// @param lhs Container to compare.
/// @param rhs Container to compare.
/// @return true if lhs and rhs compare equal, otherwise false.
bool equal(const Array& lhs, const Array& rhs);
#endif // ARRAY_H_
/* EOF */
Requirements
You must use the interface provided above. Do not modify any function signatures. (I have provided a copy of this interface file for you in the /home/shared/cs202/pa12/ directory; copy it. Do not modify it.) Do not use any form of base+offset addressing within repetition structures (i.e., use pointers to traverse the array.
Name the source code file containing your main function pa12.cpp. Create a Makefile with targets to build the entire project, each object file, and to clean the project directory.

C++ Code Solution

#include "Array.h"
/// Default constructor. Constructs a new container with 'count' copies of
/// elements with value 'value'.
/// @param count The number of elements.
/// @param value Value to fill each element.
Array::Array(std::size_t count, int value)
{
 m_size = count;
 m_list = new int[m_size];
 for (int i = 0; i < m_size; i++)
  m_list[i] = value;
}
/// Copy constructor. Constructs the Array with a copy of the
/// contents of 'other'.
/// @param other Array to copy.
Array::Array(const Array& other)
{
 m_size = other.m_size;
 m_list = new int[m_size];
 for (int i = 0; i < m_size; i++)
  m_list[i] = other.m_list[i];
}
/// Free the resources used by the container.
Array::~Array()
{
 delete[] m_list;
 m_list = NULL;
 m_size = 0;
}
/// Returns a reference to the element at specified position 'pos'.
/// @param pos Position of the element to return.
/// @return Reference to the requested element.
int& Array::at(std::size_t pos)
{
 return m_list[pos];
}
const int& Array::at(std::size_t pos) const
{
 return m_list[pos];
}
/// Returns a reference to the first element in the container.
/// Calling front on an empty container is undefined.
/// @note For a container c, the expression 'c.front()' is equivalent
/// to '*c.begin()'.
/// @return Reference to the first element.
int& Array::front()
{
 return m_list[0];
}
const int& Array::front() const
{
 return m_list[0];
}
/// Returns a reference to the last element in the container.
/// Calling back on an empty container is undefined.
/// @note For a container c, the expression return 'c.back()' is equivalent
/// to '{ auto tmp = c.end(); --tmp; return *tmp; }'
/// @return Reference to the last element.
int& Array::back()
{
 return m_list[m_size - 1];
}
const int& Array::back() const
{
 return m_list[m_size - 1];
}
/// Checks if the container has no elements, i.e., whether
/// 'begin() == end()'.
/// @return true if the container is empty, false otherwise.
bool Array::empty() const
{
 return m_size == 0;
}
/// Assigns the given value 'value' to all elements in the container.
/// @param value The `value` to assign to the elements.
void Array::fill(int value)
{
 for (int i = 0; i < m_size; i++)
  m_list[i] = value;
}
/// Exchanges the contents of this container with another.
/// @param other Container to exchange the contents with.
void Array::swap(Array& other)
{
 int *temp_m_list = m_list;
 m_list = other.m_list;
 other.m_list = temp_m_list;
 int temp_m_size = m_size;
 m_size = other.m_size;
 other.m_size = temp_m_size;
}
// Non-Member Function(s)
/// Compares the contents of two arrays. Returns true if the contents of
/// lhs and rhs are equal, that is, whether each element in lhs compares
/// equal with the element in rhs at the same position.
/// Otherwise, returns false.
/// @param lhs Container to compare.
/// @param rhs Container to compare.
/// @return true if lhs and rhs compare equal, otherwise false.
bool equal(const Array& lhs, const Array& rhs)
{
    if(lhs.size() != rhs.size())
        return false;
    for(std::size_t i = 0; i < lhs.size(); i++)
        if(lhs.at(i) != rhs.at(i))
            return false;
    return true;
}