當前位置:編程學習大全網 - 編程軟體 - 單詞搜索程序設計

單詞搜索程序設計

時間有限。我寫了壹些草圖。讓我們看壹看。不那麽完整。

CWord類

{

公共:

c word(char * s);

void process();

int issub(char * s);

CWord運算符-(CWord & amp;s);

void打印();

私人:

字符串[80];//存儲字符串

int計數;//英語單詞數

};

CWord::CWord(char *s)

{

strcpy_s(str," ");

如果(s!=空)

{

strcpy_s(str,s);

}

count = 0;

}

void CWord::print()

{

cout & lt& lt"字符串是:"

cout & lt& lt“,字數是:”

}

void CWord::process()

{

char * temp = str

temp++;

while(*temp!= '\0')

{

if(* temp = = 32 & amp;& amp*( - temp)!= 32)

{

count++;

}

temp+= 2;

}

if(*( - temp)!= 32)

{

count++;

}

}

int CWord::issub(char* sub_str)

{

//在字符串str中查找S字符串。如果找到,則返回指定字符串的第壹個字符的位置。如果沒有,返回-1。

int pos = 0;

char * src _ str = str

while (*src_str!= '\0')

{

pos++;

if(*src_str == *sub_str)

{

char * temp 1 = src _ str;

char * temp2 = sub _ str

while(*temp2!= ' \ 0 ' & amp& amp*temp1!= '\0')

{

if(*(temp1++)!= *(temp2++))

打破;

}

if(*temp2 == '\0 ')

{

退貨位置;

}

}

src _ str++;

}

return-1;

}

  • 上一篇:以珍愛生命、防止溺水為主題的手抄報
  • 下一篇:鄭州經三路農科路小區周邊配套怎麽樣?
  • copyright 2024編程學習大全網