Розробка власного класу STRING
Курсовой проект - Компьютеры, программирование
Другие курсовые по предмету Компьютеры, программирование
en>=len) return clsString ("");
char *tempstr=new char [subLen+1];
if (subLen==0) subLen=len-index;
strncpy (tempstr,symb+index,subLen);
tempstr [subLen] =\0;
clsString temp (tempstr);
delete [] tempstr;
return temp;
}
(3) . (4) .
(6) - , (8) .
(9) (10) .
(n) =n*m, n- , m- .
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
(11)
(12)
(13)
(14)
(15) int clsString:: find (const clsString& comp, int pos)
{
bool Notequal=1;
if (comp. len>pos+this->len) return - 1;
int fin=this->len-comp. len;
for (; (pos<=fin) &&Notequal; pos++)
{
int k=0;
for (int j=pos; k<comp. len; k++,j++)
if (this->symb [j] ! =comp. symb [k]) break;
if (k==comp. len) Notequal=0;
}
if (Notequal) return - 1;
else return pos;
}
Notequal (3) : . fin (5) . (10) , .
2.3
:
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
(11)
(12)
(13)
(14)
(15)
(16)
(17)
(18)
(19)
(20)
(21)
(22)
(23)
(24)
(25)
(26)
(27)
(28)
(29)
(30)
(31)
(32)
(33)
(34)
(35)
(36)
(37)
(38)
(39) This program will test my work
This is a small driver
Testing in process
This is a small driver
Enter string
Enter string
Good day! This is a very good day! I have already done my work!
Good day! This is a very good day! I have already done my work!
s1 is "Testing in process" and s2 is "This is a small driver"
The results of comparing is:
s2==s1 yields false
s2! =s1 yields true
s2>s1 yields true
s2<s1 yields false
s2<=s1 yields false
s2>=s1 yields true
s1 += s2 yields s1 = Testing in processThis is a small driver
s1 after s1 [0] = t and s1 [1] =E
tEsting in processThis is a small driver
find and delete in s1 s2
tEsting in process
**********************************************************
s1 is "112211221122" and s2 is "334433443344334"Insert to s1 5 symbols from s2.
Start position 0:
33443112211221122
Insert to s1 5 symbols from s2. Start position 5:
11221334431221122
Insert to s1 5 symbols from s2. Start position end of s1:
11221122112233443
2007
12.3456789012
...
, :
(1)
(2)
(3)
(4)
(5)
(6)
(7) clsString* temp=new clsString ("This program will test my work");
cout <<*temp<<endl;
*temp= (clsString)"This is a small driver";
clsString test1 ("Testing in process");
clsString test2;
clsString test3 (*temp);
cout<<*temp<<endl<<test1<<endl<<test2<<endl<<test3;
(1) "This program will test my work". . (2), ( /). (3), . . (4) , (5). (6).