| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 701 人关注过本帖
标题:调用失败?
只看楼主 加入收藏
maiiho
Rank: 1
等 级:新手上路
帖 子:94
专家分:7
注 册:2008-7-17
结帖率:50%
收藏
 问题点数:0 回复次数:3 
调用失败?
错误的在红色部分#include <iostream.h>
#include <string.h>
class student
{
private:
    static int count;                  
    static float allgrade;               
    char *no;
    char *name;
    float grade;
public:
    student(){}
    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 &w)
    {
        cout<<"\n编号="<<w.no<<"\n姓名="<<w.name<<"\n成绩="<<w.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);
    showxx(p2);
    return 0;
}
搜索更多相关主题的帖子: 失败 
2008-10-21 13:49
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(){}
    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;
        allgrade+=grade;
        count++;
    }
    ~student()
    {
        delete []name;
        delete []no;
    }
    void setxx(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;
        allgrade+=grade;
        count++;
    }
    void showxx()
    {
        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.0;
int main()
{
    student p1,p2("95001","Ishimura Maiiho",89);
    p1.setxx("95002","Shimizu Saki",83);
    p2.showxx();
    p1.showxx();
    return 0;
}
2008-10-21 14:08
youhm
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2006-5-25
收藏
得分:0 
问题应该在这里
   
 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++;
    }
2008-10-21 15:23
xiaxiang1986
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2008-3-16
收藏
得分:0 
3#,不是你那样的吧!你看下strcpy()的用法!

呵呵!
2008-10-22 10:41
快速回复:调用失败?
数据加载中...
 
   



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

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