《输入一行英文单词,假定单词由一个或多个空格隔开。统计有几个单词》用C++编程

如题所述

#include<iostream.h>
#include<string.h>

class WORD{
char str[80];
int c;
public:
WORD(char *s)
{
c=0;
strcpy(str,s);
}

void process() //统计单词个数函数
{
char *p=str;
while(*p)
{
while(*p==' '&&*p) p++;
while(*p!=' '&&*p) p++;c++;
}
}

void print()
{
cout<<str<<endl;
cout<<"c="<<c<<endl;
}
};

void main()
{
WORD w("She is a nice girl");
w.process();
w.print();
}
温馨提示:答案为网友推荐,仅供参考
相似回答