主题:程序出错!请各位帮我看下>
#include<iostream.h>
#include<stdlib.h>
class student
{
public:
int xuhao;
char name[9];
char sex[3];
int age;
float rxcj;
char jtzz;
void print()//输出
{
cout<<"学号"<<'\t'<<"姓名"<<"\t"<<"性别"<<'\t'<<"年龄"<<'\t'<<"入学成绩"<<'\t'<<"家庭住址"<<endl;
}
void chucuo()//出错的时候
{
cout<<"你输入数据错误请重新输入:"<<endl;
}
void input(student s[],int n)//输入数据
{
int i;
cout<<" 请输入数据:"<<endl;
print();
for(i=0;i<n;i++)
cin>>s[i].xuhao>>s[i].name>>s[i].sex>>s[i].age>>s[i].rxcj>>s[i].jtzz;
}
void paisu(student s[],int n)//按学号排序
{
int i,j;
student temp;
for(i=0;i<=n-1;i++)
{
for(j=i+1,j<n;j++;)
if(s[i].xuhao>s[j].xuhao)
{
temp=s[j];
s[j]=s[i];
s[i]=temp;
}
}
}
void shuchu(student s[],int n)//输出结果
{
int i;
print();
for(i=0;i<n;i++)
cout<<s[i].xuhao<<s[i].name<<s[i].sex<<s[i].age<<s[i].rxcj<<s[i].jtzz<<endl;
}
void chazhao(student s[],int n)//查找信息
{
int i, j;
cout<<"请输入要查找的学号:"<<endl;
cin>>j;
for(i=0;i<n;i++)
{
if(j=s[i].xuhao)
{
print();
cout<<s[i].xuhao<<'\t'<<s[i].name<<'\t'<<s[i].sex<<'\t'<<s[i].age<<'\t'<<s[i].rxcj<<'\t'<<s[i].jtzz<<endl;
}
else
chucuo();
}
}
void shanchu(student s[],int n)//删除
{
int i,xuhao;
cout<<"请输入将要删除的学号:"<<endl;
cin>>xuhao;
for(i=0;i<n;i++)
if(xuhao==s[i].xuhao)
{
for(;i<n;i++)
s[i]=s[i+1];
--n;
}
else
{
chucuo();
}
}
};
void main()
{
cout<<"################################入学档案##################################"<<endl;
cout<<" 08软件入学档案室 "<<endl;
cout<<"##########################################################################"<<endl;
student s;
int y,i;
while(1)
{
cout<<"请选择 1排序 2查找 3 删除 0退出"<<endl;
switch(i)
{
case 0:exit(0);break;
case 1:
{
s[i].paisu(s,y);
}break;
case 2:
{
s[i].chazhao(s,y);
}break;
case 3:
{
s[i].shanchu(s,y);
}break;
default:
break;
}
}
char sfjx;
cout<<"是否继续(Y/N)"<<endl;
cin>>sfjx;
if(sfjx=='n'||sfjx=='N')
exit(0);
}
错误提示是:
--------------------Configuration: xiugai2 - Win32 Debug--------------------
Compiling...
xiugai2.cpp
E:\作业\li1\xiugai2.cpp(103) : error C2676: binary '[' : 'class student' does not define this operator or a conversion to a type acceptable to the predefined operator
E:\作业\li1\xiugai2.cpp(103) : error C2228: left of '.paisu' must have class/struct/union type
E:\作业\li1\xiugai2.cpp(107) : error C2676: binary '[' : 'class student' does not define this operator or a conversion to a type acceptable to the predefined operator
E:\作业\li1\xiugai2.cpp(107) : error C2228: left of '.chazhao' must have class/struct/union type
E:\作业\li1\xiugai2.cpp(111) : error C2676: binary '[' : 'class student' does not define this operator or a conversion to a type acceptable to the predefined operator
E:\作业\li1\xiugai2.cpp(111) : error C2228: left of '.shanchu' must have class/struct/union type
Error executing cl.exe.
xiugai2.exe - 6 error(s), 0 warning(s)
#include<stdlib.h>
class student
{
public:
int xuhao;
char name[9];
char sex[3];
int age;
float rxcj;
char jtzz;
void print()//输出
{
cout<<"学号"<<'\t'<<"姓名"<<"\t"<<"性别"<<'\t'<<"年龄"<<'\t'<<"入学成绩"<<'\t'<<"家庭住址"<<endl;
}
void chucuo()//出错的时候
{
cout<<"你输入数据错误请重新输入:"<<endl;
}
void input(student s[],int n)//输入数据
{
int i;
cout<<" 请输入数据:"<<endl;
print();
for(i=0;i<n;i++)
cin>>s[i].xuhao>>s[i].name>>s[i].sex>>s[i].age>>s[i].rxcj>>s[i].jtzz;
}
void paisu(student s[],int n)//按学号排序
{
int i,j;
student temp;
for(i=0;i<=n-1;i++)
{
for(j=i+1,j<n;j++;)
if(s[i].xuhao>s[j].xuhao)
{
temp=s[j];
s[j]=s[i];
s[i]=temp;
}
}
}
void shuchu(student s[],int n)//输出结果
{
int i;
print();
for(i=0;i<n;i++)
cout<<s[i].xuhao<<s[i].name<<s[i].sex<<s[i].age<<s[i].rxcj<<s[i].jtzz<<endl;
}
void chazhao(student s[],int n)//查找信息
{
int i, j;
cout<<"请输入要查找的学号:"<<endl;
cin>>j;
for(i=0;i<n;i++)
{
if(j=s[i].xuhao)
{
print();
cout<<s[i].xuhao<<'\t'<<s[i].name<<'\t'<<s[i].sex<<'\t'<<s[i].age<<'\t'<<s[i].rxcj<<'\t'<<s[i].jtzz<<endl;
}
else
chucuo();
}
}
void shanchu(student s[],int n)//删除
{
int i,xuhao;
cout<<"请输入将要删除的学号:"<<endl;
cin>>xuhao;
for(i=0;i<n;i++)
if(xuhao==s[i].xuhao)
{
for(;i<n;i++)
s[i]=s[i+1];
--n;
}
else
{
chucuo();
}
}
};
void main()
{
cout<<"################################入学档案##################################"<<endl;
cout<<" 08软件入学档案室 "<<endl;
cout<<"##########################################################################"<<endl;
student s;
int y,i;
while(1)
{
cout<<"请选择 1排序 2查找 3 删除 0退出"<<endl;
switch(i)
{
case 0:exit(0);break;
case 1:
{
s[i].paisu(s,y);
}break;
case 2:
{
s[i].chazhao(s,y);
}break;
case 3:
{
s[i].shanchu(s,y);
}break;
default:
break;
}
}
char sfjx;
cout<<"是否继续(Y/N)"<<endl;
cin>>sfjx;
if(sfjx=='n'||sfjx=='N')
exit(0);
}
错误提示是:
--------------------Configuration: xiugai2 - Win32 Debug--------------------
Compiling...
xiugai2.cpp
E:\作业\li1\xiugai2.cpp(103) : error C2676: binary '[' : 'class student' does not define this operator or a conversion to a type acceptable to the predefined operator
E:\作业\li1\xiugai2.cpp(103) : error C2228: left of '.paisu' must have class/struct/union type
E:\作业\li1\xiugai2.cpp(107) : error C2676: binary '[' : 'class student' does not define this operator or a conversion to a type acceptable to the predefined operator
E:\作业\li1\xiugai2.cpp(107) : error C2228: left of '.chazhao' must have class/struct/union type
E:\作业\li1\xiugai2.cpp(111) : error C2676: binary '[' : 'class student' does not define this operator or a conversion to a type acceptable to the predefined operator
E:\作业\li1\xiugai2.cpp(111) : error C2228: left of '.shanchu' must have class/struct/union type
Error executing cl.exe.
xiugai2.exe - 6 error(s), 0 warning(s)