#include<iostream>
#include<string.h>
using namespace std;
class KB
{
private:
char *s;
int k;
public:
KB(const char *ss)
{
s=new char[strlen(ss)+1];
strcpy(s,ss);
}
int sz(char m)//判断字符是不是数字
{
if(m>='0'&&m<='9')
return 1;
else
return 0;
}
int zm(char m)//判断字符是不是字母
{
if(m>='a'&&m<='z'||m>='A'&&m<='Z')
return k=1;
else
return k=0;
}
void fun()//功能函数 确定k的值
{
char *p;
if(sz(*s))
{
k=0;
return;//因为是void所以不能写return 0;
}
for(p=s;*p;p++)
{
if(zm(*p))
continue;
if(sz(*p))
continue;
if(*p=='-')
continue;
break;
}//跳出循环有两种可能 一是*p的值为假, 而是遇到不是字母数字下划线字符
if(*p)
k=0;
else
k=1;
}
void print()
{
if(k==1)
cout<<s<<'\t'<<"是标识符"<<endl;
if(k==0)
cout<<s<<'\t'<<"不是标识符"<<endl;
}
};
int main()
{
KB zk1("j-+-+kj"),zk2("dhj%h5");
zk1.fun() ;
zk1.print() ;
zk2.fun() ;
zk2.print() ;
}