|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<iostream.h>
#include<stdio.h>
#include <string.h>
class Count
{
public:
Count(char,char);
void StartCount(char *str,char *p);
void ShowCount();
~Count(){};
private:
char *itsStr,*itsP;
};
void Count::StartCount(char *str,char *p)
{
itsStr=str;
itsP=p;
}
void ShowCount()
{
int i,count=0;
for(i=0;itsStr[i]!='\0';i++)
{
if(itsStr[i]==*itsP)
{
count++;
}
}
cout<<"字母a的个数: "<<count<<endl;
}
int main()
{
//Count mycount;
char str[1024];
char *p=new char;
cout<<"请输入一串英文字符: "<<endl;
gets(str);
cout<<"请输入要统计的字母: "<<endl;
scanf("%c",p);
StartCount(str,p);
ShowCount();
delete new char;
return 0;
} |
|