#include
#include
#include
#include
#include
#include
const MaxListSize=100;//设置数组长度为100
//student类
class student
{
private:
int num;
int grade[5];
float sum;
float ping;
char name[20];
int age;
public:
student(){}
void setnum(int nu){num=nu;}
int getnum(){int n;n=num;return n;}
void setgrade(int a,int b){grade[b]=a;}
int getgrade(int n){int a;a=grade[n];return a;}
void setname(char *na){strcpy(name,na);}
char *getname(){char *na;na=name;return na;}
void setage(int a){age=a;}
int getage(){int a;a=age;return a;}
friend class SeqList;
float getping();
int getsum();
student (student &s);
};
//求和
int student::getsum()
{
int sum=0;
for(int i=0;i<5;i++)
sum=sum+grade[i];
return sum;
}
//求平均
float student::getping()
{
float sum=0;
for(int i=0;i<5;i++)
sum=sum+grade[i];
sum=sum/5;
return sum;
}
student::student (student &s)
{
num=s.num;
age=s.age;
strcpy(name,s.name);
for(int i=0;i<5;i++)
grade[i]=s.grade[i];
}
typedef student datatype;
//Seqlist类
class SeqList
{
private:
datatype data[MaxListSize];
public:
int size;
int ListSize(){ return size;};
void Find(datatype& item);
void Find3(datatype& item);
void Insert(datatype& item,int pos);
void ClearList();
void luru(int n);
void xianshi(int n);
void xinming(int n);
void xuehao(int a);
void kecheng(int n);
void change(int a);
void del(int n);
void paixu1(datatype array[],int k,int length);
void Find1(datatype& item,int j);
datatype erfen(datatype a[],int key,int n);
void duoyu1();
void Find2(datatype& item);
void zong(int n);
};
//定义查询
void SeqList::Find1(datatype& item,int j)
{
printf("学号:%d",item.getnum());
printf(" 姓名:%s",item.getname());
printf(" 年龄:%d",item.getage());
printf(" 成绩%d:%d",j,item.getgrade(j));
printf("\n");
}
void SeqList::Find2(datatype& item)
{
printf("学号:%d",item.getnum());
printf(" 姓名:%s",item.getname());
printf(" 年龄:%d",item.getage());
printf(" 总成绩:%d",item.getsum());
printf(" 平均成绩:%.2f",item.getping());
printf("\n");
}
//希尔排序
void paixun(datatype array[],int length)
{
int d = length/2; //设置希尔排序的增量
int i ;
int j;
student temp,t;
while(d>=1)
{
for(i=d;i=0 && array[j].getnum()>temp.getnum())
{
t=array[j];
array[j+d]=t;
j=j-d;
}
array[j+d]=temp;
}
d= d/2; //缩小增量
}
}
//seqlist类中查询函数
void SeqList::Find(datatype& item)
{
printf("学号:%d",item.getnum());
printf(" 姓名:%s",item.getname());
printf(" 年龄:%d",item.getage());
for(int j=0;j<5;j++)
printf(" 成绩:%d",item.getgrade(j));
printf(" 总成绩:%d",item.getsum());
printf(" 平均成绩:%.2f",item.getping());
}
void SeqList::Find3(datatype& item)
{
printf("学号:%d",item.getnum());
printf(" 姓名:%s",item.getname());
printf(" 年龄:%d",item.getage());
for(int j=0;j<5;j++)
printf(" 成绩:%d",item.getgrade(j));
printf(" 总成绩:%d",item.getsum());
printf(" 平均成绩:%.2f",item.getping());
}
void SeqList::ClearList ()
{
size =0;
}
SeqList list;
void guanliyuan(int n);
void guanliyuanmain(int n);
void guanliyuan_denglu(int n);
void duoyu1();
void xianshi1(int n);
void duoyu2();
void paixun(datatype array[],int length);
void studentmain(int n);
void zhu();
void main()
{
int a;
do
{
system("cls");
list.ClearList();
printf("\n\n\n");
printf("\t\t\t 欢迎使用学生成绩管理系统 \n ");
printf("\t\t\t******************************\n");
printf("\t\t\t* *\n");
printf("\t\t\t* 1.管理员登陆 *\n");
printf("\t\t\t* 2.学员登录 *\n");
printf("\t\t\t* 3.退出 *\n");
printf("\t\t\t* *\n");
printf("\t\t\t******************************\n\n");
printf("\t\t\t请输入你要操作的序号:\n");
printf("\t\t\t你要输入的序号是:");
scanf("%d",&a);
if(a<0||a>3)
printf("您输入的有误,请重新输入!!!");
switch(a)
{
case 1:guanliyuan_denglu(0);break;
case 2:studentmain(1);break;
case 3:system("cls");cout<<" 感谢使用本系统"<3)
printf("您输入的有误,请重新输入!!!");
switch(a)
{
case 1:guanliyuan_denglu(0);break;
case 2:studentmain(1);break;
case 3:system("cls");cout<<" 感谢使用本系统"<6)
printf("您输入的有误,请重新输入!!!");
switch(a)
{
case 1:list.luru(n);break;
case 2:guanliyuanmain(n);break;
case 3:list.change( n);break;
case 4:list.del(n);break;
case 5:zhu();break;
case 6:system("cls");cout<<" 感谢使用本系统"<4)
printf("您输入的有误,请重新输入!!!");
switch(a)
{
case 1:list.xianshi(n);break;
case 2:xianshi1(n);break;
case 3:guanliyuan(n);break;
case 4:zhu();break;
case 5:system("cls");cout<<" 感谢使用本系统"<>ch;
list.data[size].setname(ch);
printf("\n年龄: ");
cin>>age;
list.data[size].setage(age);
printf("注:(成绩1为数学,成绩2为计算机,成绩3为英语,成绩4为语文,成绩5为思修 \n");
for(j=0;j<5;j++)
{
printf("\n成绩%d: ",j+1);
cin>>grade[j];
list.data[size].setgrade(grade[j],j);
}
list.size++;
}
else if(k==1)
printf("此学号已存在,请查实后再输入!!");
printf("\n如要继续输入学生信息,请选择(y/n): ");
scanf("%s",ch);
}
while(strcmp(ch,"y")==0||strcmp(ch,"Y")==0);
paixun(list.data,list.size);
guanliyuan(n);
}
void SeqList::xianshi(int n)
{
system("cls");
int i;
for(i=0;i6)
printf("您输入的有误,请重新输入!!!");
switch(a)
{
case 1:list.xinming(n);break;
case 2:list.xuehao(n);break;
case 3:list.kecheng(n);break;
case 4:list.zong(n);break;
case 5:zhu();break;
case 6:system("cls");cout<<" 感谢使用本系统"<list.size)
printf("无该人,请确认后在输入!");
else if(strcmp(list.data[i].getname(),key)==0)
Find(list.data[i]);
}
if(n==1)
duoyu1();
else if(n==0)
duoyu2();
}
//二分法
datatype SeqList::erfen(datatype a[],int key,int n)
{
int low=0,high=n-1;
int mid;
while(low<=high)
{
mid=(low+high)/2;
if(a[mid].getnum()==key)
return a[mid];
else if(a[mid].getnum()>n;
stu=erfen(list.data,n,list.size);
Find(stu);
getch();
if(n==1)
duoyu1();
else if(n==0)
duoyu2();
}
//课程
void SeqList::kecheng(int n)
{
system("cls");
int key,j;
student stu[100];
printf("请输入课程代号:");
printf("(1为数学,2为计算机,3为英语,4为语文,5为思修) \n");
cin>>key;
if(key>5||key<1)
printf("输入错误!!");
else
for(j=0;j>n;
for(i=0;i>num;
for(j=i;j>ch;
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0)
{
printf("\n名字:");
cin>>name;
list.data[i].setname(name);
k=1;
}
printf("\n你确定要修改学生年龄吗?(y/n): ");
cin>>ch;
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0)
{
int age;
printf("\n年龄:");
cin>>age;
list.data[i].setage(age);
k=1;
}
printf("\n你确定要修改学生成绩吗?(y/n): ");
scanf("%s",ch);
printf("\n");
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0)
{
printf("注:(成绩1为数学,成绩2为计算机,成绩3为英语,成绩4为语文,成绩5为思修 )\n");
for(j=0;j<5;j++)
{
printf("成绩%d:",j+1);
cin>>grade[j];
list.data[i].setgrade(grade[j],j);
printf("\n");
k=1;
}
}
}break;
}
system("cls");
if(k==1)
Find(list.data[i]);
else if(k==0)
printf("无该学生,或您没执行操作!!!");
paixun(list.data,list.size);
duoyu2();
}
//删除
void SeqList::del(int n)
{
system("cls");
int i,j;
int c;
int k=0;
printf("\n输入你要删除的学生学号 :\n");
printf("num:");
cin>>c;
for(i=0;i=1)
{
for(i=d;i=0 && array[j].getsum()=1)
{
for(i=d;i=0 && array[j].getgrade(k)4) //判断输入的是否大于4或小于0
printf("您输入的有误,请重新输入!!!");
switch(a)
{
//调用geren函数
case 1:list.xianshi(1);break;
case 2:xianshi1(1);break;
case 3:zhu();break;
case 4:system("cls");cout<<" 感谢使用本系统"<3)
printf("您输入的有误,请重新输入!!!");
switch(a)
{
case 1:studentmain(1);break;
case 2:zhu();break;
case 3:system("cls");cout<<" 感谢使用本系统"<3)
printf("您输入的有误,请重新输入!!!");
switch(a)
{
case 1:guanliyuan(0);break;
case 2:zhu();break;
case 3:system("cls");cout<<" 感谢使用本系统"<