| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 787 人关注过本帖
标题:为什么非要把程序中的float改为double才不报错?
只看楼主 加入收藏
maiiho
Rank: 1
等 级:新手上路
帖 子:94
专家分:7
注 册:2008-7-17
结帖率:50%
收藏
 问题点数:0 回复次数:4 
为什么非要把程序中的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;
}
搜索更多相关主题的帖子: float double 
2008-10-21 12:27
maiiho
Rank: 1
等 级:新手上路
帖 子:94
专家分:7
注 册:2008-7-17
收藏
得分:0 
其他错误大家不用管
其他的错误我已经解决了!
2008-10-21 12:28
随心
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:12
帖 子:2577
专家分:250
注 册:2007-8-12
收藏
得分:0 
[bo][un]maiiho[/un] 在 2008-10-21 12:27 的发言:[/bo]

#include <iostream>
#include <string>
using namespace std;
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);
    }
    student()
    {
        count = 0;
        allgrade = 0;
    }
};

int main()
{
    student p1("95001","ishimuramaiiho",88.51);
    student p2;
    p2.setxx("95002","shimizusaki",88.67);
    showxx(p2);    //方法调用有问题,它是一个类中的,能这样调用吗?????
    return 0;
}

// 评语: 问题多多,还需要努力!

天之道,利而不害。圣人之道,为而不争。信言不美,美言不信。善者不辩,辩者不善。知者不博,博者不知。
2008-10-21 13:06
maiiho
Rank: 1
等 级:新手上路
帖 子:94
专家分:7
注 册:2008-7-17
收藏
得分:0 
问题都该了,只有一个问题了
#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()
    {
        char level(float a);
        cout<<"\n\n团队人数="<<count<<"\n总成绩="<<allgrade<<"\n评定级别="<<level(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;
    student p2("95001","ishimuramaiiho",89);
    p1.setxx("95002","shimizusaki",88);
    void student::allxx();
    return 0;
}
        
    
错误信息:
--------------------Configuration: 静态函数访问 - Win32 Debug--------------------
Compiling...
静态函数访问.cpp
G:\Users\Maiiho\Desktop\新建文件夹 (2)\c\静态函数访问.cpp(64) : error C2512: 'student' : no appropriate default constructor available
执行 cl.exe 时出错.

静态函数访问.exe - 1 error(s), 0 warning(s)
2008-10-21 13:35
choco1024
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:183
专家分:140
注 册:2008-8-31
收藏
得分:0 
对象p1应该和p2一样被赋初值,要不然编译也会报错。
2008-10-21 22:37
快速回复:为什么非要把程序中的float改为double才不报错?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.049635 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved