c++程序设计第3版谭浩强课后答案
C++编程,要求用指针或引用方法处理:C语言: 输入一行文字 找出其中的大写字母、小写字母、空格、数字以及其他字符各有多少。
c++设计(第3版)题解与上机指导 谭浩强 编著
以下是此题的【c++源代码】,需要【c源代码】请点击进入
#include <iostream>
using namespace std;
int main()
{int upper=0,lower=0,digit=0,space=0,other=0,i=0;
char *p,s[20];
cout<<"input string:";
while ((s[i]=getchar())!='\n') i++;
p=&s[0];
while (*p!='\n')
{if (('A'<=*p) && (*p<='Z'))
++upper;
else if (('a'<=*p) && (*p<='z'))
++lower;
else if (*p==' ')
++space;
else if ((*p<='9') && (*p>='0'))
++digit;
else
++other;
p++;
}
cout<<"upper case:"<<upper<<endl<<"lower case:"<<lower<<endl;
cout<<"space:"<<space<<endl<<"digit:"<<digit<<endl<<"other:"<<other<<endl;
return 0;
}
本文链接:http://www.wb98.com/cjia/post/cjia_6.8.html
本站文章搜索: