大虾 帮帮一个编程问题
#include<iostream.h>struct
{
int xuhao;
char xingming[20];
float fenshu;
}studentdata[20];
class student
{
public:
void input();
void queue();
void del();
void search();
void average();
protected:
struct studentdata[20];
}
void student::input()
{
int i,num;char name[20];float sore;
do
{
cout<<"依次输入学号,姓名,分数\n";
cin>>num>>name>>sore;
studentdata[i].xuehao=num;
studentdata[i].xingming=name;
studentdata[i].fenshu=sore;
i++;
}while(studentdata[i].num!=-1);
}
void student::queue()
{
int i,j;struct swap;
for(i=0;i<sizeof(studentdata);i++)
{
for(j=1;j=sizeof(studentdata)-i;j++)
{
if(studentdata[i].xuehao<studentdata[j].xuehao)
{
swap=studentdata[i];
studentdata[i]=studentdata[j];
studentdata[j]=swap;
}
}
}
}
void student::del()
{
int number;
int i;
cin>>number;
for(i=0;i<sizeof(studentdata);i++)
{
if(studentdata[i]=number)
{
studentdata.number=-1;
studentdata.sore=-1;
studentdata.xingming="***";
}
}
}
void student::search();
{
int number;int i;
cin>>number;
for(i=0;i<sizeof(studentdata);i++)
{
if(studentdata[i].xuehao==number)
{
cout<<"学号:"<<studentdata[i].xuehao<<"姓名:"<<studentdata[i].xingming<<"分数:" studentdata.fenshu<<"\n";
}
}
}
void student::average()
{
int i;float aver,all;
for(i=0;i<sizeof(studentdata);i++)
{
all+=studentdata[i];
aver=all/sizeof(studentdata);
}
}
void main()
{
student.ss;
int choose;
cout<<"欢迎来到学生查询系统\n";
cout<<"1.输入学生资料\n"
<<"2.依照学号排序\n"
<<"3.输入你要删除的学生的学号\n"
<<"4.输入你要查询的学生的学号\n"
<<"5.输出学生的平均成绩\n"
<<"6.退出查询系统\n"
for(;;)
{
cin>>choose;
switch(choose)
{
case 1:ss.input();
case 2:ss.queue();
case 3:ss.del();
case 4:ss.search();
case 5:ss.average;
case 6:break;
}
}
}
调试后显示:C:\Documents and Settings\Administrator\a.cpp(17) : error C2059: syntax error : '['
C:\Documents and Settings\Administrator\a.cpp(17) : error C2238: unexpected token(s) preceding ';'
C:\Documents and Settings\Administrator\a.cpp(19) : error C2628: 'student' followed by 'void' is illegal (did you forget a ';'?)
C:\Documents and Settings\Administrator\a.cpp(20) : error C2556: 'class student __thiscall student::input(void)' : overloaded function differs only by return type from 'void __thiscall student::input(void)'
C:\Documents and Settings\Administrator\a.cpp(11) : see declaration of 'input'
C:\Documents and Settings\Administrator\a.cpp(20) : error C2371: 'input' : redefinition; different basic types
C:\Documents and Settings\Administrator\a.cpp(11) : see declaration of 'input'
C:\Documents and Settings\Administrator\a.cpp(26) : error C2143: syntax error : missing ';' before '['
C:\Documents and Settings\Administrator\a.cpp(26) : error C2143: syntax error : missing ';' before '['
C:\Documents and Settings\Administrator\a.cpp(27) : error C2143: syntax error : missing ';' before '['
C:\Documents and Settings\Administrator\a.cpp(27) : error C2143: syntax error : missing ';' before '['
C:\Documents and Settings\Administrator\a.cpp(28) : error C2143: syntax error : missing ';' before '['
C:\Documents and Settings\Administrator\a.cpp(28) : error C2143: syntax error : missing ';' before '['
C:\Documents and Settings\Administrator\a.cpp(30) : error C2275: 'studentdata' : illegal use of this type as an expression
C:\Documents and Settings\Administrator\a.cpp(17) : see declaration of 'studentdata'
C:\Documents and Settings\Administrator\a.cpp(30) : error C2228: left of '.num' must have class/struct/union type
C:\Documents and Settings\Administrator\a.cpp(35) : error C2027: use of undefined type 'studentdata'
C:\Documents and Settings\Administrator\a.cpp(17) : see declaration of 'studentdata'
C:\Documents and Settings\Administrator\a.cpp(37) : error C2027: use of undefined type 'studentdata'
C:\Documents and Settings\Administrator\a.cpp(17) : see declaration of 'studentdata'
C:\Documents and Settings\Administrator\a.cpp(39) : error C2143: syntax error : missing ')' before '['
C:\Documents and Settings\Administrator\a.cpp(39) : error C2143: syntax error : missing ';' before '['
C:\Documents and Settings\Administrator\a.cpp(39) : error C2059: syntax error : ')'
C:\Documents and Settings\Administrator\a.cpp(40) : error C2143: syntax error : missing ';' before '{'
C:\Documents and Settings\Administrator\a.cpp(41) : error C2513: 'struct student::queue::swap' : no variable declared before '='
C:\Documents and Settings\Administrator\a.cpp(41) : error C2275: 'studentdata' : illegal use of this type as an expression
C:\Documents and Settings\Administrator\a.cpp(17) : see declaration of 'studentdata'
C:\Documents and Settings\Administrator\a.cpp(42) : error C2143: syntax error : missing ';' before '['
C:\Documents and Settings\Administrator\a.cpp(42) : error C2143: syntax error : missing ';' before '['
C:\Documents and Settings\Administrator\a.cpp(43) : error C2143: syntax error : missing ';' before '['
C:\Documents and Settings\Administrator\a.cpp(43) : error C2143: syntax error : missing ';' before '['
C:\Documents and Settings\Administrator\a.cpp(53) : error C2027: use of undefined type 'studentdata'
C:\Documents and Settings\Administrator\a.cpp(17) : see declaration of 'studentdata'
C:\Documents and Settings\Administrator\a.cpp(55) : error C2143: syntax error : missing ')' before '['
C:\Documents and Settings\Administrator\a.cpp(55) : error C2143: syntax error : missing ';' before '['
C:\Documents and Settings\Administrator\a.cpp(55) : error C2059: syntax error : ')'
C:\Documents and Settings\Administrator\a.cpp(56) : error C2143: syntax error : missing ';' before '{'
C:\Documents and Settings\Administrator\a.cpp(57) : error C2143: syntax error : missing ';' before '.'
C:\Documents and Settings\Administrator\a.cpp(57) : error C2143: syntax error : missing ';' before '.'
C:\Documents and Settings\Administrator\a.cpp(58) : error C2143: syntax error : missing ';' before '.'
C:\Documents and Settings\Administrator\a.cpp(58) : error C2143: syntax error : missing ';' before '.'
C:\Documents and Settings\Administrator\a.cpp(59) : error C2143: syntax error : missing ';' before '.'
C:\Documents and Settings\Administrator\a.cpp(59) : error C2143: syntax error : missing ';' before '.'
C:\Documents and Settings\Administrator\a.cpp(64) : error C2447: missing function header (old-style formal list?)
C:\Documents and Settings\Administrator\a.cpp(78) : error C2027: use of undefined type 'studentdata'
C:\Documents and Settings\Administrator\a.cpp(17) : see declaration of 'studentdata'
C:\Documents and Settings\Administrator\a.cpp(80) : error C2275: 'studentdata' : illegal use of this type as an expression
C:\Documents and Settings\Administrator\a.cpp(17) : see declaration of 'studentdata'
C:\Documents and Settings\Administrator\a.cpp(81) : error C2027: use of undefined type 'studentdata'
C:\Documents and Settings\Administrator\a.cpp(17) : see declaration of 'studentdata'
C:\Documents and Settings\Administrator\a.cpp(86) : error C2143: syntax error : missing ';' before '.'
C:\Documents and Settings\Administrator\a.cpp(86) : error C2143: syntax error : missing ';' before '.'
C:\Documents and Settings\Administrator\a.cpp(95) : error C2143: syntax error : missing ';' before 'for'
C:\Documents and Settings\Administrator\a.cpp(100) : error C2065: 'ss' : undeclared identifier
C:\Documents and Settings\Administrator\a.cpp(100) : error C2228: left of '.input' must have class/struct/union type
C:\Documents and Settings\Administrator\a.cpp(101) : error C2228: left of '.queue' must have class/struct/union type
C:\Documents and Settings\Administrator\a.cpp(102) : error C2228: left of '.del' must have class/struct/union type
C:\Documents and Settings\Administrator\a.cpp(103) : error C2228: left of '.search' must have class/struct/union type
C:\Documents and Settings\Administrator\a.cpp(104) : error C2228: left of '.average' must have class/struct/union type
执行 cl.exe 时出错.
a.exe - 1 error(s), 0 warning(s)
我基础不大好找不什么错误啊!!