救助!c++程序错误分析

maomaoxt 2002-08-02 08:23:54
本人有一段c++程序,不知编译后的错误的意思,请大家帮忙,谢谢。程序的目的是求五位学生四门课程的总分以及平均分。程序如下:
#include <iostream.h>
class student
{public:
student(char *p[10],int x1,int x2,int x3,int x4)
{name=p;
s[0]=x1;
s[1]=x2;
s[2]=x3;
s[3]=x4;}
int sum(int x1,int x2,int x3,int x4)
{return (x1+x2+x3+x4);}
private:
int s[4],char *name[10];};
int aver(int x1,int x2,int x3,int x4)
{return (x1+x2+x3+x4)/4;}
int maxsum(student a[5])
{int temp;
temp=a[0].sum(int x1,int x2,int x3,int x4);
for(int i=1;i<=3;i++)
{if (temp<a[i].sum(int x1,int x2,int x3,int x4))
temp=a[i].sum(int x1,int x2,int x3,int x4);
return temp;}
void main
{student *a;
a=new student[5];
for(int i=0;i<5;i++)
{
{for(int j=0;j<4;j++)
cin>>s[j]>>',';}
cin>>*name;
cout<<endl;
}
for(int i=0;i<5;i++)
{cout<<i<<"every student sum scores=";
cout<<a[i].sum(int x1,int x2,int x3,int x4)<<' ';
cout<<endl;}
for(int i=0;i<4;i++)
{cout<<"averscore"<<i<<"=";
cout<<aver(a[0].s[i],a[1].s[i],a[2].s[i],a[3].s[i])<<endl;}
cout<<"maxsum student score="<<maxsum<<endl;
delete []a;}
编译后错误如下:
--------------------Configuration: Cpp555class - Win32 Debug--------------------
Compiling...
Cpp555class.cpp
E:\Debug\Cpp555class.cpp(13) : warning C4518: 'char ' : storage-class or type specifier(s) unexpected here; ignored
E:\Debug\Cpp555class.cpp(13) : warning C4228: nonstandard extension used : qualifiers after comma in declarator list are ignored
E:\Debug\Cpp555class.cpp(4) : error C2440: '=' : cannot convert from 'char *[]' to 'int *[10]'
There are no conversions to array types, although there are conversions to references or pointers to arrays
E:\Debug\Cpp555class.cpp(18) : error C2144: syntax error : missing ')' before type 'int'
E:\Debug\Cpp555class.cpp(18) : error C2660: 'sum' : function does not take 0 parameters
E:\Debug\Cpp555class.cpp(18) : error C2059: syntax error : ')'
E:\Debug\Cpp555class.cpp(20) : error C2144: syntax error : missing ')' before type 'int'
E:\Debug\Cpp555class.cpp(20) : error C2660: 'sum' : function does not take 0 parameters
E:\Debug\Cpp555class.cpp(20) : error C2059: syntax error : ')'
E:\Debug\Cpp555class.cpp(24) : error C2182: 'main' : illegal use of type 'void'
E:\Debug\Cpp555class.cpp(24) : error C2601: 'main' : local function definitions are illegal
E:\Debug\Cpp555class.cpp(24) : error C2063: 'main' : not a function
E:\Debug\Cpp555class.cpp(42) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

Cpp555class.exe - 11 error(s), 2 warning(s)



...全文
58 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lanfengjiyue 2002-08-03
  • 打赏
  • 举报
回复
同志!
kwok_1980 2002-08-02
  • 打赏
  • 举报
回复
#include <string>
#include <iostream>
using namespace std;
class student
{public:
student(char *p[10],int x1,int x2,int x3,int x4)
{name=p;
s[0]=x1;
s[1]=x2;
s[2]=x3;
s[3]=x4;}
int sum(int x1,int x2,int x3,int x4)
{return (x1+x2+x3+x4);}
private:
int s[4];char *name[10];//把逗号改为分号
};

int aver(int x1,int x2,int x3,int x4)
{
return (x1+x2+x3+x4)/4;
}

int maxsum(student a[5])
{
int temp;
temp=a[0].sum(int x1,int x2,int x3,int x4);//这些参
//数哪里来????
for(int i=1;i<=3;i++)
{
if (temp<a[i].sum(int x1,intx2,intx3,intx4))//这些参数哪里来????

temp=a[i].sum(int x1,int x2,int x3,int x4);
return temp;
}
}

void main() //main()函数漏了括号
{
student *a;
a=new student[5];
for(int i=0;i<5;i++)
{
{
for(int j=0;j<4;j++)
cin>>s[j]>>',';}
cin>>*name;//*name可以这样用吗????private
cout<<endl;
}

for(int i=0;i<5;i++)
{
cout<<i<<"every student sum scores=";
cout<<a[i].sum(int x1,int x2,int x3,int x4)<<' ';
//这些参数哪里来????
cout<<endl;}
for(int i=0;i<4;i++)
{
cout<<"averscore"<<i<<"=";
cout<<aver(a[0].s[i],a[1].s[i],a[2].s[i],a[3].s[i])<<endl;
//可以这样用吗????private
}
cout<<"maxsum student score="<<maxsum<<endl;
delete []a;
}


老大!你连class基本的概念都没有搞懂,
main()函数有少一个括号,嗨!
不行啊!我改了改,越改越多!改不下去啊!
你还要回头看看概念吧!(并没有得罪的意思)
真的!你吧class的基本概念弄懂先吧!

GOOD LUCK!!!


aileen_long 2002-08-02
  • 打赏
  • 举报
回复
int s[4],char *name[10];}; //把s[4]后面的,改成;
return temp;} // 还少一个}
void main // 少()

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧