下面是我写的一个简单投票系统的代码,老是出现问题,请高手给改正一下吧
#include <iostream.h>#include <string.h>
#include "cvote.h"
class Cvote
{
public:
int count[50];
char* name[]={"zhao","li","zhang"};
void elect(char*);
int get(char*);
};
void Cvote::elect(char *name1)
{
int i=0;
while(*name)
{
if(strcmp(name[i],name1)==0)
count[i]+=1;
i++;
name++;
}
}
int Cvote::get(char *name2)
{
int i=0;int p;
while(*name)
{
if(strcmp(name[i],name2)==0)
p=count[i]; i++;
name++;
return p;
}
int main()
{
Cvote cv;
int i;
cv.elect(name,"zhao");
cv.elect(name,"zhangsan");
cv.elect(name,"zhangsan");
i=cv.get(name,"zhangsan");
cout<<i<<endl;
return 0;
}
[ 本帖最后由 meimeng515 于 2009-10-6 15:10 编辑 ]