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

4000 数据结构课程设计学生信息管理系统

2017-12-21 14:47 155 查看
*版权所有(C)2017,刘浩
**文件名称:cj
*文件标识:无
*内容摘要:该代码用于获取满足后缀要求的第一个文件
*其它说明:无
*当前版本:V1.0
*作者:刘浩
*完成日期:20171221
**修改记录1:
*修改日期:20171221
*版本号:V1.0
*修改人:刘浩
*修改内容:创建


算法库:

#ifndef cj_H_INCLUDED
#define cj_H_INCLUDED


#define MaxSize 50
typedef struct
{
char name[20];
int id;
int score;
}ElemType;
typedef struct
{
ElemType data[MaxSize];
int length;
} SqList;
void CreateList(SqList *&L, ElemType a[], int n);//创建CreateList(L,a[],n)
void DispList(SqList *L);//输出DispList(L)
void GetElem(SqList *L,ElemType e);//按学号查找GetElem(L,e)
int LocateElem(SqList *L, ElemType e, ElemType s);//修改成绩LocateElem(L,e,s)
void ListInsert(SqList *&L,ElemType e);//添加信息ListInsert(L,e)
void ListDelete(SqList *&L,ElemType &e);//删除信息ListDelete(L,e)
void getname(SqList *L, ElemType e);//按姓名查找getname(L,e)
#endif


#include <stdio.h>
#include <malloc.h>
#include <string>
#include <iostream>
#include "cj.h"
using namespace std;


*功能描述:创建顺序表CreateList(L,a[],n)

*输入参数:a[],n

*输出参数:L

*返回值:0

*其他说明:把信息输入进数组,通过循环把数组中储存的信息传递给线性表;

void CreateList(SqList *&L, ElemType a[], int n)
{
int i;
L=(SqList *)malloc(sizeof(SqList));
for (i=0; i<n; i++)
{
strcpy(L->data[i].name,a[i].name);
L->data[i].id =a[i].id;
L->data[i].score =a[i].score;
}
L->length=n;
}


*功能描述://输出DispList(L)

*输入参数:无

*输出参数:L

*返回值:0

*其他说明:通过循环,把线性表总存储的信息输出

void DispList(SqList *L)
{
int i;

cout<<"学号  姓名  成绩"<<endl;
for (i=0; i<L->length; i++)
{
cout<<L->data[i].id<<"     ";
cout<<L->data[i].name<<"    ";
cout<<L->data[i].score<<"     ";
printf("\n");
}

}


*功能描述:按学号查找GetElem(L,e)

*输入参数:e

*输出参数:l->data

*返回值:0

*其他说明:通过循环把e。id与线性表中的id比较找出所需要的信息,然后输出;如果有输出则j++;如果j=0的话,则表示线性表中不存在该id。

//
void GetElem(SqList *L,ElemType e)
{
int i;int j=0;
cout<<"学号  姓名  成绩"<<endl;
for(i=0;i<L->length;i++)

{

if(L->data[i].id==e.id)
{

cout<<L->data[i].id<<"     ";
cout<<L->data[i].name<<"    ";
cout<<L->data[i].score<<"     ";
printf("\n");
j++;
}

}
if ( j==0)
cout<<"此学生不存在";

}


*功能描述://修改成绩LocateElem(L,e,s)

*输入参数:e,s

*输出参数:无

*返回值:0

*其他说明:如果线性表中存在于e。id相等的信息,则把s。score的值复制给L;完成信息修改

int LocateElem(SqList *L, ElemType e,ElemType s)
{
int i=0;
for(i;i<L->length;i++)

{

if(L->data[i].id==e.id)
{
L->data[i].score=s.score;
}

}
return 0;

}


*功能描述://按姓名查找getname(L,e)

*输入参数:e

*输出参数:L

*返回值:0

*其他说明:如果e。name和线性表L中的信息相等,则输出线性表相对i中的信息data

void getname(SqList *L, ElemType e)
{
int i;int j=0;
cout<<"学号  姓名  成绩"<<endl;
for(i=0;i<L->length;i++)
{
if(!(strcmp(L->data[i].name,e.name)))
{
cout<<L->data[i].id<<"     ";
cout<<L->data[i].name<<"    ";
cout<<L->data[i].score<<"     ";
printf("\n");
j++;
}
}
if (j==0)
{
cout<<"此学生不存在";
}
}


*功能描述://添加信息ListInsert(L,e)

*输入参数:e

*输出参数:无

*返回值:0

*其他说明:线性表长度L->length加一,然后在末尾添加新的信息;

void ListInsert(SqList *&L,ElemType e)
{

int i=0;
L->length++;
L->data[L->length-1].id=e.id;
strcpy(L->data[L->length-1].name,e.name);
L->data[L->length-1].score=e.score;

}


*功能描述://删除信息ListDelete(L,e)

*输入参数:e

*输出参数:

*返回值:0

*其他说明:判断是否存在,如果存在,则通过循环找出对应位置,通过把L->data[I]的值赋值为L->data[I+1],通过覆盖来实现信息删除

void ListInsert(SqList *&L,ElemType e)
{

int i=0;
L->length++;
L->data[L->length-1].id=e.id;
strcpy(L->data[L->length-1].name,e.name);
L->data[L->length-1].score=e.score;

}

函数:

#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <stdlib.h>
#include "cj.h"
#include <iostream>
using namespace std;
int main()
{
SqList *sq;
int i;
int j;
int n;
ElemType x[50];
L:
cout<<"1.录入信息     2.查询成绩     3.添加    4.删除信息   5.更改成绩  6. 退出"<<endl;
cin>>i;


*功能描述:信息输出创建

*输入参数:n 、x

*输出参数:

*返回值:0

*其他说明:输入n通过控制循环把信息输给数组,通过创建函数实现函数CreateList(L,a[],n)创建

#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <stdlib.h>
#include "cj.h"
#include <iostream>
using namespace std;
int main()
{
SqList *sq;
int i;
int j;
int n;
ElemType x[50];
L:
cout<<"1.录入信息     2.查询成绩     3.添加    4.删除信息   5.更改成绩  6. 退出"<<endl;
cin>>i;


*功能描述:信息输出创建

*输入参数:k,r

*输出参数:

*返回值:0

*其他说明:控制按键,通过输入123分别实现函数输出DispList(L),GetElem(L,e),getname(L,e)

else if(i==2)
{

cout<<"  1 查询所有"<<endl;
cout<<" 2按学号查询"<<endl;
cout<<" 3按姓名查询"<<endl;
cout<<endl;
int k;
cin>>k;
cout<<endl;
if (k==1)
{
DispList(sq);

}
else if (k==2)
{
ElemType e;
cout<<"请输入学号:";
cin>>e.id;

GetElem(sq,e);

}


*功能描述:信息添加

*输入参数:g,r

*输出参数:

*返回值:0

*其他说明:实现void ListInsert(SqList *&L,ElemType e)

else if(k==3)
{
ElemType r;
cout<<"请输入姓名:";
cin>>r.name;
getname(sq, r);

}

goto L;
}

else if (i==3)
{

ElemType g;
cout<<endl<<"请添加学生信息:"<<endl;
cout<<"姓名:";
cin>>g.name ;
int t;

cout<<"学号: ";
cin>>g.id   ;
for(t=sq->length-1;t>=0;t--)
{
if (sq->data[t].id==g.id)
{
cout<<"学号被使用!"<<endl;

goto L;
}
}

cout<<"成绩: ";
cin>>g.score  ;
ListInsert(sq,g);

cout << "成功添加学生成绩信息成绩。"<<endl;
goto L;

}

其他说明:实现ListDelete(L,e)
其他说明:实现ListDelete(L,e)


其他说明:实现ListDelete(L,e)
else if (i==4){ ElemType f; cout<<"请输入要删除的学号"<<endl;cin>>f.id;GetElem(sq,f); ListDelete(sq,f);cout<<"删除成功"<<endl; goto L;}

其他说明:实现LocateElem(L,e,s)

else if (i==5)
{
ElemType s;
ElemType z;
cout<<"请输入要修改学生的学号 "<<endl;
cin>>z.id;
cout<<endl;
GetElem(sq,z);
cout<<"请输入修改的成绩"<<endl;
cin>>s.score;
LocateElem(sq, z, s);
cout<<"当前成绩"<<endl;
GetElem(sq,z);
goto L;

}


其他说明 : 退出
else
cout<<"已退出";
return 0;
}


















                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: