Please help fill in the code to implement an array class for characters. /* Comm
ID: 3878994 • 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++
/**
* Set a new size for the array. If new_size is less than the current
* size, then the array is truncated. If new_size if greater then the
* current size, then the array is made larger and the new elements are
* not initialized to anything. If new_size is the same as the current
* size, then nothing happens.
* The array's original contents are preserved regardless of whether the
* array's size is either increased or decreased.
* @param[in] new_size New size of the array
*/
void resize (size_t new_size);
/// Shrink the array to reclaim unused space.
void shrink ();
/**
* Locate the specified character in the array. The index of the first
* occurrence of the character is returned. If the character is not
* found in the array, then -1 is returned.
* @param[in] ch Character to search for
* @return Index value of the character
* @retval -1 Character not found
*/
int find (char ch) const;
/**
* @overload
* This version allows you to specify the start index of the search. If
* the start index is not within the range of the array, then the
* std::out_of_range exception is thrown.
* @param[in] ch Character to search for
* @param[in] start Index to begin search
* @return Index value of first occurrence
* @retval -1 Character not found
* @exception std::out_of_range Invalid index
*/
int find (char ch, size_t start) const;
/**
* Test the array for equality.
* @param[in] rhs Right hand side of equal to sign
* @retval true Left side is equal to right side
* @retval false Left side is not equal to right side
*/
bool operator == (const Array & rhs) const;
/**
* Test the array for inequality.
* @param[in] rhs Right-hand size of not equal to sign
* @retval true Left side is not equal to right side
* @retval false Left size is equal to right side
*/
bool operator != (const Array & rhs) const;
Explanation / Answer
~> void shrink()
~> int array[size], key,i;
for(int j=0;j<size;j++){
cout<<"Enter "<<j<<" Element: ";
cin>>array[j];
}
for(int a=0;a<size;a++){
cout<<"array[ "<<a<<" ] = ";
cout<<array[a]<<endl;
}
cout<<"Enter Key To Search in Array";
cin>>key;
for(i=0;i<size;i++){
if(key==array[i]){
cout<<"Key Found At Index Number : "<<i<<endl;
break;
}
}
if(i != size){
cout<<"KEY FOUND at index : "<<i;
}
else{
cout<<"Out of range exception ";
}
return 0;
}
~> int find (char ch, size_t start) const;
~> bool equality( int D[],int E[], int size)
{
int *p=new int[size];
for (int i=0;i<size;i++)
{
p[i]=E[i];
}
for(int i=0;i<size;i++)
{
bool found=false;
for(int j=0;j<size;j++)
{
if(D[i]==p[j])
{
p[j]=-1;
found=true;
break;
}
}
if (found==false)
return found;
}
return true;
}
int main()
{
int A[]={2,2,2,1,2,2};
int B[]={2,2,1,2,2,2};
cout << equality(D,E,6)<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.