Please help fill in the code to implement an array class for characters. /* Comm
ID: 3878989 • Letter: P
Question
Please help fill in the code to implement an array class for characters. /* Comments help to know what to do in each function. Needs to be in C++
#include // for size_t definition
/**
* @class Array
* Basic implementation of a standard array class for chars.
*/
class Array{
public:
/// Default constructor.
Array (void);
/**
* Initializing constructor.
* @param[in] length Initial size
*/
Array (size_t length);
/**
* Initializing constructor.
* @param[in] length Initial size
* @param[in] fill Initial value for each element
*/
Array (size_t length, char fill);
/**
* Copy constructor
* @param[in] arr The source array.
*/
Array (const Array & arr);
/// Destructor.
~Array (void);
/**
* Assignment operation
* @param[in] rhs Right-hand side of equal sign
* @return Reference to self
*/
const Array & operator = (const Array & rhs);
{
Explanation / Answer
here is your char Array class : ------------------>>>>>>>>>>>>>
#include<iostream>
#define unsigned int size_t //for definition of size_t
#define MAX 20 //for initial size of the Array
//class Array declaration
class Array{
//variable declaration for storage of chars and to store size of size_t
char *arr;
size_t size;
public:
Array(void){//Constructor with no parameter which initialize the array of char to MAX size
arr = new char[MAX];
size = MAX;
}
Array(size_t length){//Constructor with asingle length parameter to initialize the arrray to length
arr = new char[length];
size = length;
}
Array(size_t length,char fill){//constructor with two parameter to initialize the array to length and put the fill character to each char
arr = new char[length];
for(int i = 0;i<length;i++){
arr[i] = fill;
}
size = length;
}
Array(const Array &other){//A copy constructor to copy the value of the other to this object
size = other.size;
for(int i = 0;i<size;i++){
arr[i] = other.arr[i];
}
}
const Array& operator=(const Array &rhs){//a = operator which is same as the copy constructor for copying the value and it is returning a Array const object
size = rhs.size;
for(int i = 0;i<size;i++){
arr[i] = rhs.arr[i];
}
return rhs;
}
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.