您的位置:首页 > 理论基础 > 数据结构算法

数据结构课程设计-学生信息管理

2017-12-21 12:12 633 查看
#include <iostream>
#include <string>
#include "touwenjian.h"
int n=0;//用于判断是否输出题目
int x;//用于判断要操作哪步
char a[99],d[99];//用于暂时存储姓名和性别信息
A b,c;//用于暂时存储成绩和学号
linknode *L;//声明一个链表
int m=0;
int mm=0;
using namespace std;
int main()
{
if(n==0)//根据 n来判断是否输出“学生信息管理”。
cout<<"                  学生信息管理"<<endl<<endl<<endl<<endl;
cout<<"1..输入学生信息"<<endl;
cout<<"2..输出学生信息"<<endl;
cout<<"3..添加学生信息"<<endl;
cout<<"4..修改学生信息"<<endl;
cout<<"5..删除学生信息"<<endl;
cout<<"6..查询学生信息"<<endl<<endl<<endl;
cout<<"请输入要输入的操作码:";
cin>>x;//输入判断具体要操作哪步的x
if(x==1)
{
cout<<"姓名:";
cin>>a;//输入姓名
cout<<"成绩:";
cin>>b;//输入成绩
cout<<"学号:";
cin>>c;//输入学号
cout<<"性别:";
cin>>d;//输入性别
shuru(L,a,b,c,d);
n=1;
}
else if(x==2)
{
shuchu(L);
n=1;
}
else if(x==3)
{
tianjia(L);
n=1;
}
else if(x==4)
{
cout<<"1..修改所有信息   2..修改单个信息"<<endl;
cin>>m;
if(m==1)
xiugai(L);
else
{
cout<<"1..修改成绩  2..修改学号  3..修改性别"<<endl;
cin>>mm;
if(mm==1)
xiugaichengji(L);
else if(mm==2)
xiugaixuehao(L);
else
xiugaixingbie(L);
}
n=1;
}
else if(x==5)
{
shanchu(L);
n=1;
}
else
{
chaxun(L);
n=1;
}
return main();
}
#include <iostream>
#include <string.h>
#include <malloc.h>
#include "touwenjian.h"
using namespace std;
void shuru(linknode *&L,char a[],A b,A c,char d[])//用于初次输入学生各项信息
{
linknode *s,*r;
L=(linknode *)malloc(sizeof(linknode));
r=L;
s=(linknode *)malloc(sizeof(linknode));
strcpy(s->mingzi,a);
s->chengji=b;
s->xuehao=c;
strcpy(s->xingbie,d);
r->next=s;
r=s;
r->next=NULL;
}
void shuchu(linknode *L)//输出目前已存储的所有学生信息
{
linknode *p=L->next;
cout<<"姓名        成绩         学号          性别"<<endl;
while(p!=NULL)
{
cout<<p->mingzi<<"        "<<p->chengji<<"           "<<p->xuehao<<"            "<<p->xingbie<<endl;
p=p->next;
}
cout<<endl<<endl;
}
void tianjia(linknode *&L)//在已存储的基础上继续添加学生信息
{
linknode * p=L,* s;
s=(linknode *)malloc(sizeof(linknode));
while(p->next!=NULL)
p=p->next;
char aa[99],dd[99];
A bb,cc;
cout<<"姓名:";
cin>>aa;
cout<<"成绩:";
cin>>bb;
cout<<"学号:";
cin>>cc;
cout<<"性别:";
cin>>dd;
strcpy(s->mingzi,aa);
s->chengji=bb;
s->xuehao=cc;
strcpy(s->xingbie,dd);
s->next=NULL;
p->next=s;
}
void chaxun(linknode *L)//通过输入的姓名来查询已存储的学生信息
{
linknode *p=L;
char aa[99];
cout<<"请输入要查询的姓名:";
cin>>aa;
int t=1;
while(p!=NULL&&t!=99)
{
if(!(strcmp(p->mingzi,aa)))
{
cout<<"姓名        成绩         学号          性别"<<endl;
cout<<p->mingzi<<"        "<<p->chengji<<"           "<<p->xuehao<<"            "<<p->xingbie<<endl<<endl<<endl;
t=99;
}
p=p->next;
}
if(p==NULL)
cout<<"并没有这名学生的信息!"<<endl<<endl<<endl;
}
void xiugai(linknode *&L)//修改学生信息
{
linknode *p=L;
char xx[99];
cout<<"请输入要修改的学生姓名:";
cin>>xx;
char aa[99],dd[99];
A bb,cc;
int t=1;
while(p!=NULL&&t!=99)
{
if(!(strcmp(p->mingzi,xx)))
{
cout<<"已找到该学生数据,接下来请依次输入该学生的数据。"<<endl;
cout<<"成绩:";
cin>>bb;
cout<<"学号:";
cin>>cc;
cout<<"性别:";
cin>>dd;
p->chengji=bb;
p->xuehao=cc;
strcpy(p->xingbie,dd);
t=99;
}
if(t!=99)
p=p->next;
}
if(p==NULL)
cout<<"并没有这名学生的信息!"<<endl<<endl<<endl;
}
void xiugaichengji(linknode *&L)
{
linknode *p=L;
char xx[99];
cout<<"请输入要修改的学生姓名:";
cin>>xx;
char aa[99],dd[99];
A bb,cc;
int t=1;
while(p!=NULL&&t!=99)
{
if(!(strcmp(p->mingzi,xx)))
{
cout<<"已找到该学生数据,输入要修改后的成绩"<<endl;
cout<<"成绩:";
cin>>bb;
p->chengji=bb;
t=99;
}
if(t!=99)
p=p->next;
}
if(p==NULL)
cout<<"并没有这名学生的信息!"<<endl<<endl<<endl;
}
void xiugaixuehao(linknode *&L)
{
linknode *p=L;
char xx[99];
cout<<"请输入要修改的学生姓名:";
cin>>xx;
char aa[99],dd[99];
A bb,cc;
int t=1;
while(p!=NULL&&t!=99)
{
if(!(strcmp(p->mingzi,xx)))
{
cout<<"已找到该学生数据,接下来请输入修改后的学号。"<<endl;
cout<<"学号:";
cin>>cc;
p->xuehao=cc;
t=99;
}
if(t!=99)
p=p->next;
}
if(p==NULL)
cout<<"并没有这名学生的信息!"<<endl<<e
93e1
ndl<<endl;
}
void xiugaixingbie(linknode *&L)
{
linknode *p=L;
char xx[99];
cout<<"请输入要修改的学生姓名:";
cin>>xx;
char aa[99],dd[99];
A bb,cc;
int t=1;
while(p!=NULL&&t!=99)
{
if(!(strcmp(p->mingzi,xx)))
{
cout<<"已找到该学生数据,接下来请依次输入修改后的性别。"<<endl;
cout<<"性别:";
cin>>dd;
strcpy(p->xingbie,dd);
t=99;
}
if(t!=99)
p=p->next;
}
if(p==NULL)
cout<<"并没有这名学生的信息!"<<endl<<endl<<endl;
}
void shanchu(linknode *&L)//删除学生信息
{
linknode *p=L;
char aa[99];
cout<<"请输入删除的学生姓名:";
cin>>aa;
int t=1;
while(p!=NULL&&t!=99)
{
if(!(strcmp(p->next->mingzi,aa)))
{
p->next=p->next->next;
t=99;
cout<<"已删除"<<aa<<"的所有数据"<<endl<<endl<<endl;
}
if(t!=99)
p=p->next;
}
if(p==NULL)
cout<<"并没有这名学生的信息!"<<endl<<endl<<endl;
}
#ifndef TOUWENJIAN_H_INCLUDED
#define TOUWENJIAN_H_INCLUDED
#include <string>
using namespace std;
typedef int A;
typedef struct xinxi
{
char mingzi[99];
A chengji;
A xuehao;
char xingbie[99];
struct xinxi *next;
}linknode;
void shuru(linknode *&L,char a[],A b,A c,char d[]);
void shuchu(linknode *L);
void tianjia(linknode *&L);
void chaxun(linknode *L);
void xiugai(linknode *&L);
void xiugaichengji(linknode *&L);
void xiugaixuehao(linknode *&L);
void xiugaixingbie(linknode *&L);
void shanchu(linknode *&L);
#endif // TOUWENJIAN_H_INCLUDED
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: