jooh123 2016-04-13 08:44 采纳率: 0%
浏览 2175

求大神帮忙解疑/*创建一个结构数组,用于存储多个学生的学号、姓名、成绩。

/*
创建一个结构数组,用于存储多个学生的学号、姓名、成绩。
输出1:最高分学生的学号、姓名。
输入2:所有学生的平均分
*/
#include
using namespace std;
struct student
{
char num [40];
char name [40];
float score[40];
float ave;
};

student stu;

int main()
{
//定义变量
int i,maxi,n,temp;
float sum,max,average;
//输入数据
cout<<"please input the number of student:";
cin>>n;
for(i=1;i {
cout cin>>stu.num>>endl;
cout<<"请输入第"< cin>>stu.name>>endl;
cout<<"请输入第"< cin>>stu.score>>endl;
}
//数据处理
average =0;
sum=0;
maxi=0;
sum=0;
for(i=0;i {
sum+=stu[i].score;
if(stu[i].score>stu[i+1].score)
{
temp=stu[i].score;
stu[i].score= stu[i+1].score
stu[i+1].score=temp
}
}
average=sum/n;

//数据输出
cout<<"NO.   name   score\n";
for (i=0;i<n;i++)
{
    cout<<setw(3)<<stu[i].num<<stu[i].name<<stu[i].score
        <<stu[i+1].score;
}

error C2679: binary '>>' : no operator defined which takes a right-hand operand of type '' (or there is no acceptable conversion)

C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(31) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type '' (or there is no acceptable conversion)
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(33) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'float [40]' (or there is no acceptable conversion)
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(42) : error C2676: binary '[' : 'struct student' does not define this operator or a conversion to a type acceptable to the predefined operator
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(42) : error C2228: left of '.score' must have class/struct/union type
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(43) : error C2676: binary '[' : 'struct student' does not define this operator or a conversion to a type acceptable to the predefined operator
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(43) : error C2228: left of '.score' must have class/struct/union type
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(43) : error C2676: binary '[' : 'struct student' does not define this operator or a conversion to a type acceptable to the predefined operator
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(43) : error C2228: left of '.score' must have class/struct/union type
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(45) : error C2676: binary '[' : 'struct student' does not define this operator or a conversion to a type acceptable to the predefined operator
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(45) : error C2228: left of '.score' must have class/struct/union type
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(46) : error C2676: binary '[' : 'struct student' does not define this operator or a conversion to a type acceptable to the predefined operator
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(46) : error C2228: left of '.score' must have class/struct/union type
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(46) : error C2676: binary '[' : 'struct student' does not define this operator or a conversion to a type acceptable to the predefined operator
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(47) : error C2228: left of '.score' must have class/struct/union type
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(47) : error C2146: syntax error : missing ';' before identifier 'stu'
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(47) : error C2676: binary '[' : 'struct student' does not define this operator or a conversion to a type acceptable to the predefined operator
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(47) : error C2228: left of '.score' must have class/struct/union type
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(48) : error C2143: syntax error : missing ';' before '}'
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(59) : error C2065: 'setw' : undeclared identifier
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(59) : error C2676: binary '[' : 'struct student' does not define this operator or a conversion to a type acceptable to the predefined operator
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(59) : error C2228: left of '.num' must have class/struct/union type
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(59) : error C2676: binary '[' : 'struct student' does not define this operator or a conversion to a type acceptable to the predefined operator
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(59) : error C2228: left of '.name' must have class/struct/union type
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(59) : error C2676: binary '[' : 'struct student' does not define this operator or a conversion to a type acceptable to the predefined operator
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(60) : error C2228: left of '.score' must have class/struct/union type
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(60) : error C2676: binary '[' : 'struct student' does not define this operator or a conversion to a type acceptable to the predefined operator
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(60) : error C2228: left of '.score' must have class/struct/union type
C:\Users\user\Desktop\新建文件夹\Lab4_3.cpp(63) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.

Lab4_3.exe - 1 error(s), 0 warning(s)

  • 写回答

1条回答

  • qq_25289489 2016-04-21 13:18
    关注

    你的student不是数组啊,怎么会有stu[i]!!!

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题