c++程序设计第3版谭浩强课后答案
C++编程:有一篇文章,共有3行文字,每行有个80字符.要求分别统计出其中英文大写字母、小写字母、空格以及其它字符的个数。
以下是此题的【c++源代码】,需要【c源代码】请点击进入
#include <iostream>
using namespace std;
int main()
{int i,j,upper,lower,digit,space,other;
char text[3][80];
upper=lower=digit=space=other=0;
for (i=0;i<3;i++)
{cout<<"please input line "<<i+1<<endl;
gets(text[i]);
for (j=0;j<80 && text[i][j]!='\0';j++)
{if (text[i][j]>='A'&& text[i][j]<='Z')
upper++;
else if (text[i][j]>='a' && text[i][j]<='z')
lower++;
else if (text[i][j]>='0' && text[i][j]<='9')
digit++;
else if (text[i][j]==' ')
space++;
else
other++;
}
}
cout<<"upper case:"<<upper<<endl;
cout<<"lower case:"<<lower<<endl;
cout<<"digit :"<<digit<<endl;
cout<<"space :"<<space<<endl;
cout<<"other :"<<other<<endl;
return 0;
}
本文链接:http://www.wb98.com/cjia/post/cjia_5.10.html
本站文章搜索: