考试报名管理
考试报名系统是对考试报名管理的简单模拟,用菜单选择方式完成下列功能:输入考生信息;输出考生信息;查询考生信息;添加考生信息;修改考生信息;删除考生信息。每条考生信息由准考证号、姓名、性别、年龄、报考类别等信息组成。
要求:定义一个专用的类型 ElemType,用于描述考生信息,数据结构用一个类描述,命名为List,包括数据、关系和基本操作;数据结构的存储结构用链式结构实现.
#include<iostream>
#include<string>
#include<stdio.h>
#include<windows.h>
using namespace std;
int n;
struct student
{
int num;
char name[20];
char sex;
int age;
char leibie[10];
student *next;
};
class LIST
{
public:
//student *creat();
void creat();
void menu_find();
void find(student *head,int num);
void menu_change();
void change(student *head,int num);
void menu_del();
student *delet(student *head,int num);
void print();
void menu_insert();
student *insert(student *head,student *stu);
private:
student *head;
};
LIST list;
////////////////主菜单////////////////////
void menu()
{
system("cls");
cout<<"************************欢迎进入考生管理系统************************"<<endl;
cout<<"** **"<<endl;
cout<<"** 1.创建考生信息 2.查找考生信息 **"<<endl;
cout<<"** 3.修改考生信息 4.删除考生信息 **"<<endl;
cout<<"** 5.插入考生信息 6.显示考生信息 **"<<endl;
cout<<"** 7.退出 **"<<endl;
cout<<"********************************************************************"<<endl;
cout<<" "<<char(1)<<" 孙淑敏 薛影影 孙梦瑶 马会英 马睿晗"<<endl<<endl;
cout<<"请输入目录序号:"<<endl;
}
/////////////////创建考生信息/////////////////
void LIST::creat()
{
cout<<" ****输入以0结束!****"<<endl<<endl;
student *p1,*p2;
n=0;
p1=p2=new student;
cout<<"请输入考生: 准考证号 姓名 性别 年龄 报考类别"<<endl;
cin>>p1->num;
if(p1->num==0)
{
system("pause");
menu();
return;
}
cin>>p1->name>>p1->sex>>p1->age>>p1->leibie;
list.head=NULL;
while(p1->num!=0)
{
n=n+1;
if(n==1)
list.head=p1;
else
p2->next=p1;
p2=p1;
p1=new student;
cout<<"请输入考生:准考证号 姓名 性别 年龄 报考类别!"<<endl;
cin>>p1->num;
if(p1->num==0)
break;
cin>>p1->name>>p1->sex>>p1->age>>p1->leibie;
}
if(p1->num==0)
system("pause");
p2->next=NULL;
list.head=head;
menu();
}
///////////////查找考生信息///////////////
void LIST::menu_find()
{
cout<<" ****输入以0结束!****"<<endl<<endl;
int f_num;
cout<<"请输入您要查找考生的准考证号: "<<endl;
cin>>f_num;
while(f_num!=0)
{
list.find(list.head,f_num);
cout<<"请输入您要查找考生的准考证号: "<<endl;
cin>>f_num;
}
if(f_num==0)
system("pause");
menu();
}
void LIST::find(student *head,int num)
{
student *p1,*p2;
if(head==NULL)
{
cout<<" ****当前没有考生信息!****"<<endl<<endl;
return ;
}
p1=head;
while(num!=p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(num==p1->num)
{
cout<<"您要查找的考生为:"<<endl
<<"************************************************"<<endl;
cout<<"准考证号:"<<p1->num<<'\n'
<<"姓 名:"<<p1->name<<'\n'
<<"性 别:"<<p1->sex<<'\n'
<<"年 龄:"<<p1->age<<'\n'
<<"报考类别:"<<p1->leibie<<endl;
cout<<"************************************************"<<endl<<endl;
return ;
}
else if(p1->next==NULL)
{
cout<<" ****找不到该考生信息!****"<<endl<<endl;
return ;
}
}
///////////////修改考生信息///////////////
void LIST::menu_change()
{
cout<<" ****输入以0结束!****"<<endl;
int xg_num;
cout<<"请输入您要修改的考生的准考证号:"<<endl;
cin>>xg_num;
while(xg_num!=0)
{
list.change(head,xg_num);
cout<<"请输入您要修改的考生的准考证号:"<<endl;
cin>>xg_num;
}
if(xg_num==0)
system("pause");
menu();
}
void LIST::change(student *head,int num)
{
student *p1,*p2;
if(head==NULL)
{
cout<<" ****当前没有考生信息!****"<<endl;
return ;
}
p1=head;
while(num!=p1->num)
{
p2=p1;
p1=p1->next;
}
if(num==p1->num)
{
cout<<"您要修改的考生当前信息:"<<endl;
cout<<"**************************************************************"<<endl;
cout<<" 准考证号:"<<p1->num<<'\n'
<<" 姓 名:"<<p1->name<<'\n'
<<" 性 别:"<<p1->sex<<'\n'
<<" 年 龄:"<<p1->age<<'\n'
<<" 报考类别:"<<p1->leibie<<endl;
cout<<"**************************************************************"<<endl;
cout<<" ****请重新输入该考生的信息!****"<<endl<<endl;
cout<<"请重新输入该考生: 准考证号 姓名 性别 年龄 报考类别!"<<endl;
int xg_num;
char xg_name[20];
char xg_sex;
int xg_age;
char xg_leibie[10];
cin>>xg_num>>xg_name>>xg_sex>>xg_age>>xg_leibie;
p1->num=xg_num;
strcpy(p1->name,xg_name);
p1->sex=xg_sex;
p1->age=xg_age;
strcpy(p1->leibie,xg_leibie);
cout<<" ****修改成功!****"<<endl<<endl;
return ;
}
else
{
cout<<" ****找不到该考生信息!****"<<endl<<endl;
return ;
}
}
///////////////显示考生信息///////////////
void LIST::print()
{
student *p;
p=list.head;
if(list.head!=NULL)
do
{
cout<<"************************************************"<<endl;
cout<<"准考证号:"<<p->num<<'\n'
<<"姓 名:"<<p->name<<'\n'
<<"性 别:"<<p->sex<<'\n'
<<"年 龄:"<<p->age<<'\n'
<<"报考类别:"<<p->leibie<<endl;
p=p->next;
}while(p!=NULL);
if(list.head==NULL)
cout<<" ****当前没有考生信息!****"<<endl;
cout<<"************************************************"<<endl;
system("pause");
menu();
}
//////////////////删除考生信息///////////////
void LIST::menu_del()
{
cout<<" ****输入以0结束!****"<<endl;
int del_num;
cout<<"请输入您要删除的考生准考证号:"<<endl;
cin>>del_num;
while(del_num!=0)
{
head=list.delet(head,del_num);
cout<<"请输入您要删除的考生准考证号:"<<endl;
cin>>del_num;
}
if(del_num==0)
system("pause");
menu();
}
student *LIST::delet(student *head,int num)
{
student *p1,*p2;
if(head==NULL)
{
cout<<" ****当前没有考生信息!****"<<endl;
return (head);
}
p1=head;
while(num!=p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(num==p1->num)
{
if(p1==head)
head=p1->next;
else
p2->next=p1->next;
cout<<" ****学号为"<<num<<"的考生信息已删除!****"<<endl;
n=n-1;
}
else
cout<<" ****找不到该考生信息!****"<<endl;
return head;
}
//////////////////插入考生信息////////////////////
void LIST::menu_insert()
{
student *stu;
cout<<" ****输入以0结束!****"<<endl;
stu=new student;
cout<<"请输入考生: 准考证号 姓名 性别 年龄 报考类别!"<<endl;
cin>>stu->num;
if(stu->num==0)
{
system("pause");
menu();
return;
}
cin>>stu->name>>stu->sex>>stu->age>>stu->leibie;
while(stu->num!=0)
{
head=list.insert(head,stu);
stu=new student;
cout<<"请输入考生: 准考证号 姓名 性别 年龄 报考类别!"<<endl;
cin>>stu->num;
if(stu->num==0)
break;
cin>>stu->name>>stu->sex>>stu->age>>stu->leibie;
cout<<" ****插入考生信息成功!****"<<endl;
}
if(stu->num==0)
system("pause");
menu();
}
student *LIST::insert(student *head,student *stu)
{
student *p0,*p1,*p2;
p1=head;
p0=stu;
if(head==NULL)
{
head=p0;
p0->next=NULL;
}
else
{
while((p0->num>p1->num)&&(p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}
if(p0->num<=p1->num)
{
if(head==p1)
head=p0;
else
p2->next=p0;
p0->next=p1;
}
else
{
p1->next=p0;
p0->next=NULL;
}
}
n=n+1;
return (head);
}
//////////////////////////////////////////////////////////
int main()
{
menu();
int num;
while(cin>>num)
{
switch(num)
{
case 1:
{
list.creat();
};continue;
case 2:
{
list.menu_find();
};continue;
case 3:
{
list.menu_change();
};continue;
case 4:
{
list.menu_del();
};continue;
case 5:
{
list.menu_insert();
};continue;
case 6:
{
list.print();
};continue;
case 7:
{
cout<<" ****欢迎下次光临!****"<<endl;
exit(0);
};
}
}
return 0;
}
/**************************************************
101 sunshumin f 19 li
102 xueyingying m 20 wen
104 mahuiying m 20 wen
106 maruihan f 19 li
108 sunmengyao m 18 li
105 sunsm f 23 wen
106 xueyy m 22 li
**************************************************/原文:http://blog.csdn.net/sunshumin/article/details/39031331