题目内容
设英文单词是连在一起的英文字母,下列程序求键盘输入的一串字符中单词的个数。例如,“ I’m aboy. ”中有4个单词。程序设计如下所示,请完善程序。(1)函数int f(char c),若字符c是英文字母返回1,否则返回0。(2)函数int count(char*s),求字符串s 的单词个数并返回。(3)在主函数中输入一个字符串,测试count 函数。[程序]#includeusing namespace std;int f(char c){return ((c>='A'&&c<='Z') _____(1)_____ (c>='a'&&c<='z'));}int count(char*s){int words=0;while(*s){if(f(*s)&&!f(*(s+1)))words++;_____(2)_____;}return words;}int main(){char text[100];cout<<"请输入一个字符串:\n";_____(3)_____;cout<
查看答案
搜索结果不匹配?点我反馈