2 jooh123 jooh123 于 2016.04.13 16:44 提问

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

/*
创建一个结构数组,用于存储多个学生的学号、姓名、成绩。
输出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
qq_25289489   2016.04.21 21:18

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

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
结构体指针数组完成输入学生姓名学号数学语文成绩修改排序显示等功能
有一个结构体变量stu,内含学生学号,姓名和三门课成绩。要求在main函数中为各位成员赋值,在另一函数print中将他们输出。
第一周:项目3 学生成绩的结构体数组(包括学号、姓名、三门课成绩、总分、均分)
【数据结构上机作业】输入一批学生的成绩(至少包括学生学号、姓名、课程成绩),用单链表存储,输出大于平均成绩的学生信息。
先建立一个Access 学生成绩库student.mdb,在其中建立表chengjibiao,定义其数据格式为学号(int)、姓名(varchar)、出生日期(datetime)、数学(int)、物理
2.6使用二维数组存储学生的数据,包括学号、姓名、操作系统成绩、Java成绩、高数成绩、总分;一行存储一个学生的数据;要求输入若干学生的数据,求出总分;然后按照总分由高到低重新排列;输出排序后的结果
编写一个函数print,打印一个学生的成绩数组,该书组中有五个学生的数据,每个学生的数据包括num(学号)、name(姓名)、score(3门课的成绩)、用主函数输入这些数据,用print函数输出这些
数组排序之对一组学生按照成绩, 学号,年龄, 姓名排序~
定义一个表示学生信息的类Student,要求如下:  (1)类Student的成员变量: sNO 表示学号;sName表示姓名;sSex表示性别;sAge表示年龄;sJava:表示Java课程成绩。
定义一个二维数组用于存储学生的学号,姓名和c#课程的考试成绩,然后输入学号、姓名和c#成绩。最后按c#成绩升序和降序输出成绩单。