主题:[原创]学生信息管理
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;
class student
{
public:
int no;
string sex;
string name;
student *next;
};
class stuqueue
{
public:
student *front,*rear;
void inistuqueue(stuqueue &s){
student *ss;
ss=new student;
ss->next=NULL;
s.front=ss;
s.rear=ss;
}
void input(stuqueue &s){
student *ss;
int no;string sex;string name;
ss=new student;
cout<<"输入学生学号:";cin>>no;
check(s, no);
cout<<"输入性别:";cin>>sex;
cout<<"输入姓名:";cin>>name;
ss->no=no;
ss->sex=sex;
ss->name=name;
s.rear->next=ss;
s.rear=ss;
s.rear->next=NULL;
}
void print(stuqueue &s){
student *p;
p=s.front->next;
cout<<" 学生学号 性别 姓名"<<endl;
while(p!=NULL)
{cout<<" "<<p->no<<" "<<p->sex<<" "<<p->name<<endl;
p=p->next;
}
}
student *locate(stuqueue s,int no){
student *p;
p=s.front->next;
while((p!=NULL)&&(p->no!=no))
p=p->next;
return p;
}
void check(stuqueue s,int no)
{ student *p;
p=locate(s,no);
if(p!=NULL)
{cout<<"学号重复,请重新输入学生学号:";cin>>no;
check(s, no);}
}
void search(stuqueue s){
int no;
cout<<"要查询的学号:";
cin>>no;
student *p;
p=locate(s,no);
if(p==NULL)
{cout<<"查无此人"<<endl;}
else
{cout<<"学生学号,性别, 姓名"<<endl;
cout<<" "<<p->no<<" "<<p->sex<<" "<<p->name<<endl;
}
}
void gengxin(stuqueue &s){
int no;
string sex,name;
cout<<"输入要更新同学的学号";
cin>>no;
student *p;
p=locate(s,no);
if(p==NULL){
cout<<"学号错误,请重新输入";
cin>>no;
gengxin( s);}
else
cout<<"输入性别:";cin>>sex;
cout<<"输入姓名:";cin>>name;
p->sex=sex;
p->name=name;
}
void del(stuqueue &s){
int no;
student *p,*q;
cout<<"输入要删除的学号:";
cin>>no;
q=s.front;
p=s.front->next;
while((p!=NULL)&&(p->no!=no))
{q=p;p=p->next;}
if(p==NULL)cout<<"要删除的人不存在"<<endl;
else
{
q->next=p->next;
delete p;
}
}
};
void menu(stuqueue stu){
int n;
cout<<"功能选项(1-6)";
cin>>n;
while(n)
{
switch(n){
case 1: stu.input(stu);//输入/添加
break;
case 2: stu.gengxin(stu);//更新
break;
case 3: stu.search(stu);//查询
break;
case 4: stu.del(stu);//删除
break;
case 5: stu.print(stu);//输出
break;
case 6: exit(0);
break;
}
cout<<"功能选项(1-6)";
cin>>n;
}
}
void main(){
cout<<" 学生信息管理系统 "<<endl;
cout<<"-------------------------------------------"<<endl;
cout<<"1 -输入/添加学生信息 2 - 更新学生信息"<<endl;
cout<<"3 -查询学生信息 4 - 删除学生信息"<<endl;
cout<<"5 -输出学生信息 6 - 退出学生管理"<<endl;
cout<<"-------------------------------------------"<<endl;
stuqueue stu;
stu.inistuqueue(stu);
menu( stu);
}
#include<string>
#include<stdlib.h>
using namespace std;
class student
{
public:
int no;
string sex;
string name;
student *next;
};
class stuqueue
{
public:
student *front,*rear;
void inistuqueue(stuqueue &s){
student *ss;
ss=new student;
ss->next=NULL;
s.front=ss;
s.rear=ss;
}
void input(stuqueue &s){
student *ss;
int no;string sex;string name;
ss=new student;
cout<<"输入学生学号:";cin>>no;
check(s, no);
cout<<"输入性别:";cin>>sex;
cout<<"输入姓名:";cin>>name;
ss->no=no;
ss->sex=sex;
ss->name=name;
s.rear->next=ss;
s.rear=ss;
s.rear->next=NULL;
}
void print(stuqueue &s){
student *p;
p=s.front->next;
cout<<" 学生学号 性别 姓名"<<endl;
while(p!=NULL)
{cout<<" "<<p->no<<" "<<p->sex<<" "<<p->name<<endl;
p=p->next;
}
}
student *locate(stuqueue s,int no){
student *p;
p=s.front->next;
while((p!=NULL)&&(p->no!=no))
p=p->next;
return p;
}
void check(stuqueue s,int no)
{ student *p;
p=locate(s,no);
if(p!=NULL)
{cout<<"学号重复,请重新输入学生学号:";cin>>no;
check(s, no);}
}
void search(stuqueue s){
int no;
cout<<"要查询的学号:";
cin>>no;
student *p;
p=locate(s,no);
if(p==NULL)
{cout<<"查无此人"<<endl;}
else
{cout<<"学生学号,性别, 姓名"<<endl;
cout<<" "<<p->no<<" "<<p->sex<<" "<<p->name<<endl;
}
}
void gengxin(stuqueue &s){
int no;
string sex,name;
cout<<"输入要更新同学的学号";
cin>>no;
student *p;
p=locate(s,no);
if(p==NULL){
cout<<"学号错误,请重新输入";
cin>>no;
gengxin( s);}
else
cout<<"输入性别:";cin>>sex;
cout<<"输入姓名:";cin>>name;
p->sex=sex;
p->name=name;
}
void del(stuqueue &s){
int no;
student *p,*q;
cout<<"输入要删除的学号:";
cin>>no;
q=s.front;
p=s.front->next;
while((p!=NULL)&&(p->no!=no))
{q=p;p=p->next;}
if(p==NULL)cout<<"要删除的人不存在"<<endl;
else
{
q->next=p->next;
delete p;
}
}
};
void menu(stuqueue stu){
int n;
cout<<"功能选项(1-6)";
cin>>n;
while(n)
{
switch(n){
case 1: stu.input(stu);//输入/添加
break;
case 2: stu.gengxin(stu);//更新
break;
case 3: stu.search(stu);//查询
break;
case 4: stu.del(stu);//删除
break;
case 5: stu.print(stu);//输出
break;
case 6: exit(0);
break;
}
cout<<"功能选项(1-6)";
cin>>n;
}
}
void main(){
cout<<" 学生信息管理系统 "<<endl;
cout<<"-------------------------------------------"<<endl;
cout<<"1 -输入/添加学生信息 2 - 更新学生信息"<<endl;
cout<<"3 -查询学生信息 4 - 删除学生信息"<<endl;
cout<<"5 -输出学生信息 6 - 退出学生管理"<<endl;
cout<<"-------------------------------------------"<<endl;
stuqueue stu;
stu.inistuqueue(stu);
menu( stu);
}