光头强骂李扒皮:编写一行文字,找出其中大写字母,小写字母,空格,数字以及其他字符各有多少?

来源:百度文库 编辑:高校问答 时间:2024/05/06 07:32:37
请编写出这个函数,谢谢喽!C++的程序,需要一个完整的,谢谢!

程序如下:
#include<iostream>
using namespace std;

int main()
{
int asc[128]={0};
char temp[10000];
cin.getline(temp,10000,'\n');
int i=0;
while(temp[i]!=0)
asc[temp[i++]]++;
for (i=0;i<128;i++)
if (asc[i]!=0) cout<<char(i)<<":"<<asc[i]<<endl;
system("pause");
return 0;
}
编译环境DEV C++.

#include<iostream>
#include<cctype>
using namespace std;

int main()
{
int upper=0,lower=0,space=0,digit=0,others=0;
char temp[10000];
int i=0;

cin.getline(temp,10000,'\n');
while(temp[i])
{
if(isupper(temp[i])) ++upper;
else if(islower(temp[i])) ++lower;
else if(isdigit(temp[i])) ++digit;
else if(temp[i]==' ') ++space;
else ++others;
++i;
}
cout<<"The last line have:"<<endl;
cout<<upper<<" upper case letters."<<endl;
cout<<lower<<" lower case letters."<<endl;
cout<<space<<" spaces."<<endl;
cout<<digit<<" digits."<<endl;
cout<<others<<" other charaters"<<endl;
system("pause");
return 0;
}