| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 724 人关注过本帖
标题:求高手帮忙改错下,急啊!!!(不明白错误什么意思)
只看楼主 加入收藏
px200
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2013-4-16
结帖率:60%
收藏
已结贴  问题点数:10 回复次数:6 
求高手帮忙改错下,急啊!!!(不明白错误什么意思)
#include<iostream>
#include<string>
using namespace std;
class Date{
public:
    Date();
    Date(char *name,int x,char y,int m,int e,int c,int co);
    void setdate(char *name,int x,char y,int m,int e,int c,int z);
    void showstudent();
    void aver(int Average,int m,int e,int c,int z);
private:
    string Name;
    int ID;
    char Sex;
    int Math;
    int English;
    int C;
    int Computer;
    int Average;
   
};
Date::setdate(char *name,int x,char y,int m,int e,int c,int z)
{
 name=new char[10];
 cin>>name>>x>>y>>m>>e>>c>>z;
 delete []name;
}
Date::Date()
{}
void Date::showstudent()
{cout<<Name<<"  "<<ID<<"  "<<Sex<<"  "<<Math<<"  "<<English<<"  "<<C<<"  "<<Computer<<" "<<Average<<endl;}
void Date::aver(int Average,int m,int e,int c,int co)
{
    Average=(m+e+c+co)/4;
}
Date::Date(char *name,int x,char y,int m,int e,int c,int z)
{
    Name=name;
    ID=x;
    Sex=y;
    Math=m;
    English=e;
    C=c;
    Computer=z;
}


int main()
{
    int q;
    cout<<"Please Input the Number of Students:"<<endl;
    cin>>q;
    cout<<"Please input"<<" "<<q<<" "<<"student info: Name  ID  Sex  Math  English  C  Computer"<<endl;
    Date *stu=new Date[q];
    for(int j=0;j<q;j++)
    {
        stu[j].setdate();
    }
    cout<<endl<<"Student Information you input:"<<endl;
    cout<<"Name  ID  Sex  Math  English  C  Computer  Average"<<endl;
    for(int i=0;i<q;i++)
    {
        stu[i].showstudent();
    }
    delete []stu;
    return 0;
}


下面这是错误提示信息
D:\VC++\program work\program work\lab5\lab-5.cpp(23) : error C2556: 'int __thiscall Date::setdate(char *,int,char,int,int,int,int)' : overloaded function differs only by return type from 'void __thiscall Date::setdate(char *,int,char,int,int,int,int
)'
        D:\VC++\program work\program work\lab5\lab-5.cpp(8) : see declaration of 'setdate'
D:\VC++\program work\program work\lab5\lab-5.cpp(23) : error C2371: 'setdate' : redefinition; different basic types
        D:\VC++\program work\program work\lab5\lab-5.cpp(8) : see declaration of 'setdate'
D:\VC++\program work\program work\lab5\lab-5.cpp(57) : error C2660: 'setdate' : function does not take 0 parameters
Error executing cl..obj - 3 error(s), 0 warning(s)
搜索更多相关主题的帖子: namespace void English private include 
2013-04-17 21:41
邓士林
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:淮河河畔
等 级:贵宾
威 望:61
帖 子:2392
专家分:13384
注 册:2013-3-3
收藏
得分:3 
1、Date::Date(char *name,int x,char y,int m,int e,int c,int z)这样写是不对的,在类外定义函数还应该有函数类型,正确:void Date::setdate(char *name,int x,char y,int m,int e,int c,int z)
2、 stu[j].setdate();你调用函数,应该有参数啊!参数没有写

Maybe
2013-04-17 22:54
未未来
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:182
专家分:157
注 册:2012-11-6
收藏
得分:3 
错误应该就一楼说的吧
2013-04-18 00:08
px200
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2013-4-16
收藏
得分:0 
回复 2楼 邓士林
#include<iostream>
#include<string>
using namespace std;
class Date{
public:
    Date();
    Date(char *name,int x,char y,int m,int e,int c,int z);
    void setdate(char *name,int x,char y,int m,int e,int c,int z);
    void showstudent();
    void aver(int Average,int m,int e,int c,int z);
private:
    string Name;
    int ID;
    char Sex;
    int Math;
    int English;
    int C;
    int Computer;
    int Average;
   
};
void Date::setdate(char *name,int x,char y,int m,int e,int c,int z)
{
 name=new char[10];
 cin>>name>>x>>y>>m>>e>>c>>z;
 delete []name;
}
Date::Date()
{}
void Date::showstudent()
{cout<<Name<<"  "<<ID<<"  "<<Sex<<"  "<<Math<<"  "<<English<<"  "<<C<<"  "<<Computer<<" "<<Average<<endl;}
void Date::aver(int Average,int m,int e,int c,int z)
{
    Average=(m+e+c+z)/4;
}
Date::Date(char *name,int x,char y,int m,int e,int c,int z)
{
    Name=name;
    ID=x;
    Sex=y;
    Math=m;
    English=e;
    C=c;
    Computer=z;
}


int main()
{
    int q;
    cout<<"Please Input the Number of Students:"<<endl;
    cin>>q;
    cout<<"Please input"<<" "<<q<<" "<<"student info: Name  ID  Sex  Math  English  C  Computer"<<endl;
    Date *stu=new Date[q];
    for(int j=0;j<q;j++)
    {
        stu[j].setdate(char *name,int x,char y,int m,int e,int c,int z);
    }
    cout<<endl<<"Student Information you input:"<<endl;
    cout<<"Name  ID  Sex  Math  English  C  Computer  Average"<<endl;
    for(int i=0;i<q;i++)
    {
        stu[i].showstudent();
    }
    delete []stu;
    return 0;
}


这是我改过的,但又出来下面这三个错,我刚学C++不明白,求指教
D:\VC++\program work\program work\lab5\lab-5.cpp(57) : error C2144: syntax error : missing ')' before type 'char'
D:\VC++\program work\program work\lab5\lab-5.cpp(57) : error C2660: 'setdate' : function does not take 0 parameters
D:\VC++\program work\program work\lab5\lab-5.cpp(57) : error C2059: syntax error : ')'
Error executing cl.exe.

lab-5.exe - 3 error(s), 0 warning(s)
2013-04-18 08:12
zhuxiaoneng
Rank: 4
等 级:业余侠客
威 望:2
帖 子:51
专家分:215
注 册:2013-4-10
收藏
得分:3 
怎么最近老有人问这个问题啊,是一个人的多个马甲吗??
修改了下
程序代码:
#include<iostream>
#include<string>
using namespace std;

class Date{
public:
    //构造函数 
    Date();

    //带参数的构成函数,既然Name是string的,这个地方也改成string类型
    //Date(char *name,int x,char y,int m,int e,int c,int z);
    Date(const string& name, int id,char sex,int math,int english, int c,int computer);

    //设置数据成员
    void setdate(const string& name, int id,char sex,int math,int english, int c,int computer);

    //显示数据成员
    void showstudent();

    //求平均成绩,因为Math、English、C、Computer已经是数据成员,所以不用传递参数,返回值为四门功课的平均成绩
    //void aver(int Average,int m,int e,int c,int z);
    double aver();

private:
    string Name;
    int ID;
    char Sex;
    int Math;
    int English;
    int C;
    int Computer;
    int Average;
};

Date::Date()
{

}

Date::Date(const string& name, int id,char sex,int math,int english, int c, int computer)
{
    Name = name;
    ID = id;
    Sex = sex;
    Math = math;
    English = english;
    C = c;
    Computer = computer;
}

void Date::setdate(const string& name, int id,char sex,int math,int english, int c, int computer)
{
    Name = name;
    ID = id;
    Sex = sex;
    Math = math;
    English = english;
    C = c;
    Computer = computer;
}

void Date::showstudent()
{
    cout << Name << "  " << ID << "  " << Sex <<"  " <<Math << "  " << English << "  " << C
         << "  " << Computer << " " << aver() << endl;
}

double Date::aver()
{
    return (Math + English + C + Computer) / 4.0;
}

int main()
{
    int q;
    cout << "Please Input the Number of Students:" << endl;
    cin >> q;

    Date *stu = new Date[q]; //用不带参数的构造函数,申请了q个学生对象

    //声明一组变量,用来存放学生的信息
    string name;
    int id;
    char sex;
    int math;
    int english;
    int c;
    int computer;
    
    cout << "Please input student info: Name ID Sex Math English C Computer" << endl;

    for(int j = 0; j < q; j++)
    {
        cin >> name >> id >> sex >> math >> english >> c >> computer;    //接受输入参数 每输入完一个学生的信息后,要回车
        stu[j].setdate(name, id, sex, math, english, c, computer);        //设置第j个学生的信息
    }

    cout<< "Student Information you input: Name ID Sex Math English C Computer Average" << endl;

    for(int i = 0; i < q; i++)
    {
        stu[i].showstudent();
    }
    
    delete[] stu;
    return 0;
}


[ 本帖最后由 zhuxiaoneng 于 2013-4-18 09:45 编辑 ]
2013-04-18 09:29
px200
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2013-4-16
收藏
得分:0 
回复 5楼 zhuxiaoneng
恩 对了 非常感谢!
2013-04-18 13:14
马小柯
Rank: 2
等 级:论坛游民
帖 子:17
专家分:14
注 册:2013-4-10
收藏
得分:3 
只做小小改动
#include<iostream>
 #include<string>
 using namespace std;
 class Date{
 public:
     Date();
     Date(char *name,int x,string y,int m,int e,int c,int co);
     void setdate();
     void showstudent();
     void aver();
 private:
     string Name;
     int ID;
     string Sex;
     int Math;
     int English;
     int C;
     int Computer;
     double Average;
     
};
 void Date::setdate()
 {
// Name=new char[10];
 cin>>Name>>ID>>Sex>>Math>>English>>C>>Computer;
 }
 Date::Date()
 {}
 void Date::showstudent()
 {cout<<Name<<"  "<<ID<<"  "<<Sex<<"  "<<Math<<"  "<<English<<"  "<<C<<"  "<<Computer<<" "<<Average<<endl;}
 void Date::aver()
 {
     Average=(Math+English+C+Computer)/4.0;
 }
 Date::Date(char *name,int x,string y,int m,int e,int c,int z)
 {
     Name=name;
     ID=x;
     Sex=y;
     Math=m;
     English=e;
     C=c;
     Computer=z;
 }
int main()
 {
     int q;
     cout<<"Please Input the Number of Students:"<<endl;
     cin>>q;
     cout<<"Please input"<<" "<<q<<" "<<"student info: Name  ID  Sex  Math  English  C  Computer"<<endl;
     Date *stu=new Date[q];
     for(int j=0;j<q;j++)
     {
         stu[j].setdate();
         stu[j].aver();
     }
     cout<<endl<<"Student Information you input:"<<endl;
     cout<<"Name  ID  Sex  Math  English  C  Computer  Average"<<endl;
     for(int i=0;i<q;i++)
     {
         stu[i].showstudent();
     }
     delete stu;
     return 0;
 }
 
2013-04-18 14:26
快速回复:求高手帮忙改错下,急啊!!!(不明白错误什么意思)
数据加载中...
 
   



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

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