您的位置:首页 > 其它

链表实现的学生管理系统

2009-12-24 21:56 459 查看
身为资深菜鸟第一次在csdn上发布文章,希望各路高手不要见笑。

/* author zhangge 2009 11 30 */
#include"iostream"
#include"string"
#include"stdlib.h"
#include"conio.h"
#include"iomanip.h"
class ssystem;//信息管理系统
class student//学生节点
{
friend class ssystem;
private:
char name[36];
char id[20];
double grade[6];
char origin[36];
char sex[12];
char speciality[36];
student *next;
public:
student(student *p=NULL)
{
next=p;
}
student( char *name1,char *id1,double *grade1,char *origin1,char *sex1,char *speciality1,student *p=NULL)
{
strcpy(name,name1);strcpy(id,id1);
strcpy(origin,origin1);strcpy(speciality,speciality1);
strcpy(sex,sex1);
for(int i=0;i<=5;i++)
grade[i]=grade1[i];
next=p;
}
};
class ssystem
{
private:
student *head;
int number;
public:
ssystem();
~ssystem();
int getnumber();
void insert(char *name1,char *id1,double *grade1,char *origin1,char *sex1,char *speciality1);
void averrank(char *course);
void modify(char *name1,char *id1,double *grade1,char *origin1,char *sex1,char *speciality1);
void erase(char *name1);
void print();
};
ssystem::ssystem()
{
head=new student();
number=0;
}
ssystem::~ssystem()
{
student *p;
while(head!=NULL)
{
p=head;
head=head->next;
delete p;
}
}
int ssystem::getnumber()
{
return number;
}
void ssystem::insert(char *name1,char *id1,double *grade1,char *origin1,char *sex1,char *speciality1)
{
student *s1,*s2,*s3;
s1=new student(name1,id1,grade1,origin1,sex1,speciality1);
if(head->next==NULL)
{
head->next=s1;
number++;
}
else
{
s3=head;
s2=head->next;
while(s2->grade[0]>s1->grade[0]&&s2->next!=NULL)
{
s2=s2->next;
s3=s3->next;
}
if(s2->next!=NULL)
{
s1->next=s3->next;
s3->next=s1;
number++;
}
else
{
if(s2->grade[0]>s1->grade[0])
{
s2->next=s1;
cout<<1<<endl;
number++;
}
else
{
s1->next=s3->next;
s3->next=s1;
cout<<2<<endl;
number++;
}
}
}
}
void ssystem::averrank(char *course="average")
{
student *s1,*s2,*s3,*s4;
int i=0;
s1=head->next;
head->next=NULL;
if(strcmp(course,"math")==0)
i=1;
if(strcmp(course,"c++")==0)
i=2;
if(strcmp(course,"english")==0)
i=3;
if(strcmp(course,"network")==0)
i=4;
if(strcmp(course,"physical")==0)
i=5;
while(s1->next!=NULL)
{
s2=s1;
s1=s1->next;
s2->next=NULL;
//s2=s1;
//s2->next=NULL;(这里的循序不能错)
//s1=s1->next;
if(head->next==NULL)
{
head->next=s2;
}
else
{
s3=head;
s4=head->next;
while(s4->grade[i]>s2->grade[i]&&s4->next!=0)
{
s3=s3->next;
s4=s4->next;
}
if(s4->next!=NULL)
{
s2->next=s3->next;
s3->next=s2;
}
else
{
if(s4->grade[i]>s2->grade[i])
{
s4->next=s2;
}
else
{
s2->next=s3->next;
s3->next=s2;
}
}
}
}
s2=s1;
if(head->next==NULL)
{
head->next=s2;
}
else
{
s3=head;
s4=head->next;
while(s4->grade[i]>s2->grade[i]&&s4->next!=0)
{
s3=s3->next;
s4=s4->next;
}
if(s4->next!=NULL)
{
s2->next=s3->next;
s3->next=s2;
}
else
{
if(s4->grade[i]>s1->grade[i])
{
s4->next=s2;
}
else
{
s2->next=s3->next;
s3->next=s2;
}
}
}
}
void ssystem::erase(char *name1)
{
student *s1,*s2;
s2=head;
s1=head->next;
while(strcmp(s1->name,name1)!=0&&s1!=NULL)
{
s2=s2->next;
s1=s1->next;
}
if(s1==NULL)
cout<<"the student is not found"<<endl;
else
{
s2->next=s1->next;
delete s1;
}
}
void ssystem::print()
{
student *s;
int i=0;
s=head->next;
system("CLS");
cout<<"rank"<<" "<<"id"<<" "<<"name"<<" "<<"sex"<<" "<<"origin"<<" "<<"speciality";
cout<<" "<<"math"<<" "<<"c++"<<" "<<"english"<<" "<<"network"<<" "<<"physical"<<endl;
cout<<endl;
while(s!=NULL)
{
cout<<i++<<"   "<<s->id<<" "<<s->name<<"   "<<s->sex<<"   "<<s->origin<<"   "<<s->speciality;
for(int j=0;j<6;j++)
{
cout<<"    "<<s->grade[j];
}
cout<<endl;
s=s->next;
}
cout<<"*******************************************************************************"<<endl;
}
void ssystem::modify(char *name1,char *id1,double *grade1,char *origin1,char *sex1,char *speciality1)
{
student *s1,*s2;
s2=head;
s1=head->next;
while(strcmp(s1->name,name1)!=0&&s1!=NULL)
{
s2=s2->next;
s1=s1->next;
}
if(s1==NULL)
cout<<"the student is not found"<<endl;
else
{
s2->next=s1->next;
delete s1;
s1=new student(name1,id1,grade1,origin1,sex1,speciality1);
s1->next=s2->next;
s2->next=s1;
}
}
int main()
{
int select,n,i,j;
bool is=true;
char name[36];
char id[20];
double grade[6];
char origin[36];
char sex[12];
char speciality[20];
int marked;
ssystem mys;
loop:
if(is)
system("color 0b");
system("title 张舸的学生管理系统");
cout<<"copyright  belones to zhangge/08network"<<endl;
cout<<"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"<<endl;
cout<<endl;
cout<<"1 add student information"<<endl;
cout<<"2 show rank"<<endl;
cout<<"3 modify student information"<<endl;
cout<<"4 delete student information"<<endl;
cout<<"5 chose display color"<<endl;
cout<<"6 exit"<<endl;
cin>>select;
if(select==1)
{
cout<<"how many student are you going to add"<<endl;
cin>>n;
for(i=0;i<n;i++)
{
grade[0]=0;
cout<<"name"<<endl;
cin>>name;
cout<<"id"<<endl;
cin>>id;
cout<<"sex"<<endl;
cin>>sex;
cout<<"origin"<<endl;
cin>>origin;
cout<<"speciality"<<endl;
cin>>speciality;
cout<<"math"<<endl;
cin>>grade[1];
cout<<"c++"<<endl;
cin>>grade[2];
cout<<"english"<<endl;
cin>>grade[3];
cout<<"network"<<endl;
cin>>grade[4];
cout<<"physical"<<endl;
cin>>grade[5];
for(j=1;j<=5;j++)
grade[0]+=grade[j];
grade[0]/=5;
mys.insert(name,id,grade,origin,sex,speciality);
}
mys.print();
goto loop;
}
if(select==2)
{
int i;
cout<<"please select the methed of rank"<<endl;
cout<<"1 average grade"<<endl;
cout<<"2 math grade"<<endl;
cout<<"3 c++ grade"<<endl;
cout<<"4 english grade"<<endl;
cout<<"5 network grade"<<endl;
cout<<"6 physical grade"<<endl;
cin>>i;
switch(i)
{
case 1:mys.averrank("average");mys.print();break;
case 2:mys.averrank("math");mys.print();break;
case 3:mys.averrank("c++");mys.print();break;
case 4:mys.averrank("english");mys.print();break;
case 5:mys.averrank("network");mys.print();break;
case 6:mys.averrank("physical");mys.print();break;
}
goto loop;
}
if(select==3)
{
cout<<"plese input the student's name"<<endl;
cin>>name;
cout<<"input the new information of the student"<<endl;
grade[0]=0;
cout<<"id"<<endl;
cin>>id;
cout<<"sex"<<endl;
cin>>sex;
cout<<"origin"<<endl;
cin>>origin;
cout<<"speciality"<<endl;
cin>>speciality;
cout<<"math"<<endl;
cin>>grade[1];
cout<<"c++"<<endl;
cin>>grade[2];
cout<<"english"<<endl;
cin>>grade[3];
cout<<"network"<<endl;
cin>>grade[4];
cout<<"physical"<<endl;
cin>>grade[5];
for(j=1;j<=5;j++)
grade[0]+=grade[j];
grade[0]/=5;
mys.modify(name,id,grade,origin,sex,speciality);
goto loop;
}
if(select==4)
{
cout<<"plese inpute the student that you want to erase"<<endl;
cin>>name;
mys.erase(name);
goto loop;
}
if(select==5)
{
int t;
cout<<"choose color "<<endl;
cout<<"1 red"<<endl;
cout<<"2 blue"<<endl;
cout<<"3 white"<<endl;
cout<<"4 yellow"<<endl;
cin>>t;
if(t==1)
{
is=false;
system("color 04");
}
if(t==2)
{
is=false;
system("color 0b");
}
if(t==3)
{
is=false;
system("color 0f");
}
if(t==4)
{
is=false;
system("color 06");
}
goto loop;
}
if(select==6)
exit(0);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: