急急急!C++题答案!望高手指教!

来源:百度知道 编辑:UC知道 时间:2024/07/03 00:52:33
三、程序填空(按空计分)
1. 以下程序的功能是统计一个字符串中字母、数字、空格和其它字符的个数。
#include <iostream.h>
main()
{ int alpha,space,digital,other;
char as[40],*ps;
;
cout<<(“input string:”); cin.getline (as,40);
for(ps=as;*ps;ps++)
if( ) alpha++;
else if( *ps>=‘0’&& *ps<=‘9’)digital++;
else if(____ ___)space++;
else other++;
cout<<“alpha=”<<alpha<<“ digital=”<< digital
<<“ space=”<<space<<“ other=” <<other<<endl;
}

2. 以下程序中函数search()的功能是寻找某个字符在字符串a中出现的次数,函数返回次数。
#include<iostream.h>
int search(char a[],char b)
{ int i,n=0;
for(i=0; ;i++)
if(a[i]==b) ;
;
}
void main()
{ c

1.
#include <iostream.h>
main()
{ int alpha,space,digital,other;
char as[40],*ps;
;
cout<<(“input string:”); cin.getline (as,40);
for(ps=as;*ps;ps++)
if(*ps>='a'&&*ps<='z'||*ps>='A'&&*ps<='Z') alpha++;
else if( *ps>=‘0’&& *ps<=‘9’)digital++;
else if(*ps==' ')space++;
else other++;
cout<<“alpha=”<<alpha<<“ digital=”<< digital
<<“ space=”<<space<<“ other=” <<other<<endl;
}

2.
#include<iostream.h>
int search(char a[],char b)
{ int i,n=0;
for(i=0;a[i]!='\0';i++)
if(a[i]==b) n++;
return n;
}

void main()
{ char tabe[ ]="This README file contains important information ";
cout<<search(tab