I've tried so hard to do it but I couldn't so I really need help since
I have to send it to my professor tonight so please HELP
class String{
char * const cp; // pointer to the first element
int Alng; // the N# of the elements in the array [max N# of char is Alng -1 ]
public:
String(const char *str, int alng) ;
~String();
const char* getstr()const{ return cp;}
};
class String{
const char *cp; // pointer to the first element
int Clng; // the length of the contents of the array
int Alng; // the N# of the elements in the array [max N# of char is Alng -1 ]
public:
String(const char *str, int alng); // constructor
~String();// destructor
char getstr(){ return cp;}
};
- implement the constructor and destructor
- provide three overloaded operator (two + version, - ) . the effect of these operator as follow
String mst("this is a test",40);
String yst(" message", 15);
mst + yst // to canconat the content of the array of yst to the contents of mst
mst - 3; // cute the last three characters of mst by placing '\0' char
2 + mst; // replace the first two char of mst by 'A' char
- here is a test code and the expected output
void main(){
String mst("this is a test",40);
String yst(" message", 15);
cout<<"========================="<<endl;
cout<< "mst "<<mst.getstr()<<endl;
cout<<"yst "<<yst.getstr()<<endl;
cout<<"========================="<<endl;
mst + yst; // to canconat the content of the array of yst to the contents of mst
cout<< "mst "<<mst.getstr()<<endl;
cout<<"yst "<<yst.getstr()<<endl;
cout<<"========================="<<endl;
mst - 3; // cute the last three characters of mst by placing '\0' char
cout<<"========================="<<endl;
cout<< "mst "<<mst.getstr()<<endl;
cout<<"yst "<<yst.getstr()<<endl;
cout<<"========================="<<endl;
2 + mst; // replace the first two char of mst by 'A' char
cout<<"========================="<<endl;
cout<< "mst "<<mst.getstr()<<endl;
cout<<"yst "<<yst.getstr()<<endl;
cout<<"========================="<<endl;
}
The output:
=========================
mst this is a test
yst message
=========================
mst this is a test message
yst message
=========================
mst this is a test mess
yst message
=========================
mst this is a test mess
yst message
=========================