3rd day Operation Poedu mystring realization

Source: Internet
Author: User

Job Requirements

Code:

#define_crt_secure_no_warnings#include<iostream>#include<cstring>classmystring{Char*_str; int_len; Public: MyString () {_str=New Char[ -]; _len= -; } MyString (Const Char*str) {        if(str = =NULL) {_str=New Char[1]; *_str =' /'; }        Else        {            int_len =strlen (str); _str=New Char[_len +sizeof(Char)];        strcpy (_str, str); }            }    ~MyString () {Delete[]_str; }    Char*GetString () {return_str; }    //Set String    voidSetString (Const Char*str) {        Delete[]_str; int_len =strlen (str); _str=New Char[_len +sizeof(Char)];                    strcpy (_str, str); }    //get the character by subscript    CharGetChar (intindex) {        if(Index<=strlen (_STR) && index >=0)            return_str[index]; return 0; }    //To find the string lengthUnsignedintGetstringlens () {unsignedintindex =0;  while(_str[index]) {index++; }        returnindex; }     //   Find the length of the array unsigned int  getarrylens () { 
     
      return 
      sizeof(_str)/ 
      sizeof(_str[
      0 
      ]); }    //Batch modify one of the characters to be some other character    Char* Mycharreplace (CharDestCharsource) {         while(*_str!=' /')        {            if(*_str = =dest) {                *_str =source; }            *_str++; }        return_str; }    //append character at end    voidMyaddend (Charc) {CharTmp[] = {c,' /' };    Mystring::myaddend (TMP);        }; //append a string at the end    voidMyaddend (Char*str) {_str= Strncat (_str, str, strlen (str) +sizeof(Char)); }    //append an integer at the end    voidMyaddend (intnum) {        Chartmp[255]={0}; sprintf (TMP,"%d", num);    Mystring::myaddend (TMP); }    //Append floating-point number at the end    voidMyaddend (Doublenum) {        Chartmp[255] = {0 }; sprintf (TMP,"%8.3LF", num);    Mystring::myaddend (TMP); }    //Append mystring at the end    voidMyaddend () {_str= Strncat (_str, _str, strlen (_STR) +sizeof(Char)); }    //Pop a character from the beginning    CharPopuphead () {intindex =0; CharTMP =_str[index];  while(_str[index]!=0) {_str[index]= _str[index +1]; Index++; }        returntmp; }    //Pop a character from the end    CharPopupend () {intindex =0;  while(_str[index]! =0) {Index++; }        CharTMP = _str[index-1]; _str[index-1] =0; returntmp; }};intMain () {MyString demo1 ("I love you china! ");//MyString Demo2 ();MyString Demo ("I Love Mark"); Demo. SetString ("I love Haozaiyi"); Std::cout<< Demo. GetString () <<"  "<<demo. GetChar (Ten) <<Std::endl; Std::cout<< Demo. Getstringlens () <<"  "<< Demo. Getarrylens () <<Std::endl; Demo. Myaddend ('y'); Std::cout<< Demo. GetString () <<Std::endl; Demo. Myaddend ("AAAAA"); Std::cout<< Demo. GetString () <<Std::endl; Demo. Myaddend (123456); Std::cout<< Demo. GetString () <<Std::endl; Demo. Myaddend (123456.789); Std::cout<< Demo. Getarrylens () <<Std::endl; Std::cout<< Demo. Popuphead () << demo. Popupend () <<Std::endl; Std::cout<< Demo. Popuphead () << demo. Popupend () <<Std::endl; Std::cout<< Demo. Popuphead () << demo. Popupend () <<Std::endl; Std::cout<< Demo. Popuphead () << demo. Popupend () <<Std::endl; Std::cout<< Demo. Mycharreplace ('o','@') <<"   "<< Demo. GetString () <<Std::endl; return 0;}

Highlighted section, the code does not meet the job requirements. There are bugs to be resolved.

3rd day Operation Poedu mystring realization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.