pleaseee Help.. C++ code on a project..


Design a CharArray class that contains a dynamically allocated array of characters.

The class should have the following private member variables:

pArray
A char * that holds the location of the dynamically allocated array.

iSize
An int that holds the size of the array.


The class should have the following public member functions:

Constructor
Accepts a size, allocates an array of that size and sets the array to null. The size and array pointer should be stored in the appropriate member variables.

Copy Constructor
Accepts a pass-by-reference CharArray object. Copies the iSize member variable. Allocates a new character array for the newly created object and copies in the values from the old object.

Destructor
Frees the memory held by the array and updates the member variables appropriately.

void setItem (int loc, char value);
Stores a character in any element of the array. The loc is base 0.

char getItem (int loc);
Retrieves a character from any element of the array. The loc is base 0.

void strCpy (char * cstr, int len);
Copies characters from cstr into the array for this object, starting at location 0, for length len, but not past iSize.

bool strCmp (char * cstr);
Returns true if cstr is the same as the array for this object, returns false otherwise.



I have written the following code;
#ifndef CHAROFRRAY_H
#define CHAROFRRAY_H

//class declaration
class Charofrray
{
private:
//holds the location of the dynamically allocated array.
char *pArrray;

public:
// Accepts a size, allocates an array of that size and sets the array to null.
Charofrray(int size );



//Copy constructor, Accepts a pass-by-reference Char Array object.
Charofrray( Charofrray & object);

//Destructor, Frees the memory held by the array and updates the member variables appropriately.
~Charofrray();


void setItem (int loc, char value);
//Stores a character in any element of the array. The loc is base 0.

char getItem (int loc);
//Retrieves a character from any element of the array. The loc is base 0.

void strCpy (char * cstr, int len);
//Copies characters from cstr into the array for this object, starting at location 0, for length len, but //not past iSize.

bool strCmp (char * cstr);
//Returns true if cstr is the same as the array for this object, returns false otherwise

};

#endif



#include "Charofrray.h"
#include<iostream>
#include<cstdlib>
using namespace std;

int main()
{
//costructor
Charofrray::Charofrray(int size )
{
size = new int;

cout<<"default constructor";
}


//Copy constructor, Accepts a pass-by-reference Char Array object.
Charofrray( Charofrray & object);
{

}


//Destructor, Frees the memory held by the array and updates the member variables appropriately.
Charofrray::~Charofrray()
{
delete[]pArrray;
}

//Stores a character in any element of the array. The loc is base 0.
void Charofrray::setItem (int loc, char value)

//Retrieves a character from any element of the array. The loc is base 0.
char Charofrray::getItem (int loc)
{
return loc;
}
//Copies characters from cstr into the array for this object,
//starting at location 0, for length len, but not past iSize.
void Charofrray::strCpy (char * cstr, int len)

//Returns true if cstr is the same as the array for this object, returns false otherwise
bool Charofrray::strCmp (char * cstr)
{
bool status;

int i=0;

while(


else
status=false;

return status;

}

I need help on finishing the second function
Topic archived. No new replies allowed.