源程序:
#include
#include
#include
#include
#include
const MaxListSize=100;
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;
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 erfeng(datatype a[],int key,int n);
void duoyu1();//返回目录
void Find2(datatype& item);//返回目录2
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; //缩小增量
}
}
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:exit(0);break;
}
}
while(a!=0);
}
void zhu()
{
int a;
do
{
system("cls");
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:exit(0);break;
}
}
while(a!=0); //0 3 退出
}
void guanliyuan_denglu(int n)
{
system("cls");//清屏
char z[10],sun[10]={'\0'},c;
int i=0;
printf("\t\t\n\n\n\n");
printf("\t\t\t 欢迎使用学生信息查询系统 \n ");
printf("\t*************************************************************\n\n\n");
printf("\t\t\t 请输入管理员账号:");
scanf("%s",&z);
printf("\t\t\t 请输入管理员密码:");
while(1)
{
c=getch();
if(c != '\r')
{
printf("*");
sun[i]=c;
i++;
}
else break;
}
if(strcmp("boss",z)==0&&strcmp("10086",sun)==0)
guanliyuan(n);
else
{
printf("\t\t\t您输入的有误!!!");
}
}
void guanliyuan(int n)
{
int a;
do
{
system("cls");
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* 4.删除系统 *\n");
printf("\t\t\t* 5.返回主菜单 *\n");
printf("\t\t\t* 6. 退出 *\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>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:exit(0);break;
}
}
while(a!=0);
system("cls");
}
void guanliyuanmain(int n) //学生
{
int a;
do
{
system("cls");
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* 4.返回主菜单 *\n");
printf("\t\t\t* 5.退出 *\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>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:exit(0);break;
}
}
while(a!=0);
}
void SeqList::luru(int n)
{
system("cls");
int j,num,age,grade[5],k=0;
char ch[20];
do
{ k=0;
system("cls");
printf("\n输入学生信息:\n");
printf("\n学号: ");
scanf("%d",&num);
for(int i=0;i<=list.size;i++)
if(list.data[i].getnum()==num)
k=1;
if(k==0)
{
list.data[size].setnum(num);
printf("\n姓名: ");
cin>>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:exit(0);break;
}
}while(a!=0);
}
void SeqList::xinming(int n)
{
system("cls");
char key[20];
printf("请输入姓名:");
scanf("%s",key);
for(int i=0;ilist.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::erfeng(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=erfeng(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:exit(0);break;
}
}
while(a!=0);
}
void SeqList::duoyu1()
{
int a;
do
{
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\n");
printf("\t\t\t请输入你要操作的序号:\n");
printf("\t\t\t你要输入的序号是:");
scanf("%d",&a);
if(a<0||a>3)
printf("您输入的有误,请重新输入!!!");
switch(a)
{
case 1:studentmain(1);break;
case 2:zhu();break;
case 3:exit(0);break;
}
}while(a!=0);
system("cls");
}
void duoyu2()
{
int a;
do
{
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\n");
printf("\t\t\t请输入你要操作的序号:\n");
printf("\t\t\t你要输入的序号是:");
scanf("%d",&a);
if(a<0||a>3)
printf("您输入的有误,请重新输入!!!");
switch(a)
{
case 1:guanliyuan(0);break;
case 2:zhu();break;
case 3:exit(0);break;
}`
}while(a!=0);
system("cls");
}