在字符串类string中实现一个判断函数,该函数功能是统计某一字符串类对象(仅由单词和空格组成)有多少个单词,同时保存所有单词在字符串中的起始地址(设该字符串不超过100个单词)
#include < iostream. h >
#include < string >
class str{
string s;
int n,a [ 100 ],j ,l;
public:str ( string&a){s=a;n=0;j=

在字符串类string中实现一个判断函数,该函数功能是统计某一字符串类对象(仅由单词和空格组成)有多少个单词,同时保存所有单词在字符串中的起始地址(设该字符串不超过100个单词)
#include < iostream. h >
#include < string >
class str{
string s;
int n,a [ 100 ],j ,l;
public:str ( string&a){s=a;n=0;j=0;l=0;}
....test (....);
int * geta ( ){ return a;}
} ;
请写出test函数的过程(如果需要形式参数,请给出形参类型和数量,以及返回值类型)

INLINE VOID STR::TEST()
{
INT K=0;
FOR(INT I=0;I<S.SIZE( );I++)
{
&NBSP;&NBSP;&NBSP;&NBSP;IF(S[I]==''&&I!=0)
&NBSP;&NBSP;&NBSP;&NBSP;{
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;A[N]=K;
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;N++;
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;K=I+1;
&NBSP;&NBSP;&NBSP;&NBSP;}
}
IF(S[S.SIZE( )-1]!='')
{
&NBSP;&NBSP;&NBSP;&NBSP;A[N]=K;
&NBSP;&NBSP;&NBSP;&NBSP;N++;
}
}

Top