为什么非要把程序中的float改为double才不报错?
#include <iostream.h>#include <string.h>
class student
{
private:
static int count; //人数
static float allgrade; //成绩
char *no;
char *name;
float grade;
public:
student(char *no1,char *name1,float grade1) //构造
{
no=new char[strlen(no1)+1];
strcpy(no,no1);
name=new char[strlen(name1)+1];
strcpy(name,name1);
grade=grade1;
grade+=allgrade;
count++;
}
~student()
{
delete []name;
delete []no;
}
void setxx(char *no1,char *name1,float grade1)
{
no=new char[strlen(no1)+1];
strcpy(no1,no);
name=new char[strlen(name1)+1];
strcpy(name1,name);
grade=grade1;
grade+=allgrade;
count++;
}
void showxx(student &)
{
cout<<"\n编号="<<no<<"\n姓名="<<name<<"\n成绩="<<grade<<endl;
}
void allxx()
{
cout<<"\n\n团队人数="<<count<<"\n总成绩="<<allgrade<<"\n评定级别="<<level(float allgrade)<<endl;
}
char level(float a)
{
char temp;
if(a>0&&a<30)
temp='D';
if(a>30&&a<60)
temp='C';
if(a>60&&a<90)
temp='B';
if(a>90&&a<120)
temp='A';
return(temp);
}
};
int student::count=0;
float student::allgrade=0;
int main()
{
student p1("95001","ishimuramaiiho",88.51);
student p2;
p2.setxx("95002","shimizusaki",88.67);
showxx(p2);
return 0;
}