c链表构建学生档案数据库
2017-12-09 14:19
190 查看
#include <iostream>
#include<stdlib.h>
#include <cstring>
using namespace std;
typedef struct node
{ int number;
char name[20] ;
float score;
struct node *next;
}*LinkList;
node*q;
LinkList head=(node*)malloc(sizeof(node));
node*p=head;
void add();
void menu();
void Search();
void Delete();
void sort();
int n=0;
void menu()
{int n;
cout<<"-----------请输入数字选择功能:-----------\n----------------1.添加----------------\n----------------2.查找----------------\n----------------3.删除----------------\n----------------4.排序----------------"<<endl;
cin>>n;
if(n==1)
add();
else if(n==2)
Search();
else if(n==3) Delete();
else if(n==4) sort();
else cout<<"error"<<endl; menu();
}
void add(){cout<<"请输入要插入的信息" <<endl;
q=head;
q=(node*)malloc(sizeof(node));
cout<<"学号"<<endl;
cin>>q->number;
cout<<"姓名" <<endl;
cin>>q->name;
cout<<"成绩"<<endl;
cin>>q->score;
p->next=q;
q->next=NULL;
p=q;
n=n+1;
cout<<"n="<<n<<endl;
menu();
}
void Search()
{int m;cout<<" 请要查找的输入学号"<<endl;
cin>>m;
node *Pointer;
Pointer=head;int j=0;
while(Pointer!=NULL)
{
if(Pointer->number==m)
{
cout<<"你的姓名是"<<Pointer->name<<endl;
cout<<"你的成绩是"<<Pointer->score<<endl;
j=1;
break;
}
Pointer=Pointer->next;
}
if(j!=1)cout<<"查无此人"<<endl;;
menu();
}
void Delete()
{int m;cout<<" 请要删除的输入学号"<<endl;
cin>>m;
node *Pointer;
Pointer=head;
while(Pointer!=NULL)
{
if(Pointer->next==NULL)
{free(Pointer);
break;
}
if(Pointer->next->number==m)
{
Pointer->next=Pointer->next->next;
free(Pointer->next);
break;
}
else cout<<"错误"<<endl;
Pointer=Pointer->next;
}
n=n-1;
menu() ;
}
void sort(){cout<<" 排序"<<endl;
node* p=NULL;
node* q=NULL;
int temp;int m; char bae[20] ;
for(p=head;p!=NULL;p=p->next)
{
for(q=p->next;q!=NULL;q=q->next)
{
if(p->score<q->score)
{
temp=p->score;
p->score=q->score;
q->score=temp;
m=p->number;
p->number=q->number;
q->number=m;
strcpy(bae,p->name);
strcpy(p->name,q->name);
strcpy(q->name,bae);
}
}
} node* w;
int k=1;
for(w=head;w->next!=NULL;w=w->next)
{cout<<"----------------名次" <<k<<"----------------"<<endl;
cout<<"姓名"<<w->name<<endl;
cout<<"学号"<<w->number<<endl;
cout<<"成绩"<<w->score<<endl;k=k+1;}menu() ;
}
int main() {menu();
return 0;
}
#include<stdlib.h>
#include <cstring>
using namespace std;
typedef struct node
{ int number;
char name[20] ;
float score;
struct node *next;
}*LinkList;
node*q;
LinkList head=(node*)malloc(sizeof(node));
node*p=head;
void add();
void menu();
void Search();
void Delete();
void sort();
int n=0;
void menu()
{int n;
cout<<"-----------请输入数字选择功能:-----------\n----------------1.添加----------------\n----------------2.查找----------------\n----------------3.删除----------------\n----------------4.排序----------------"<<endl;
cin>>n;
if(n==1)
add();
else if(n==2)
Search();
else if(n==3) Delete();
else if(n==4) sort();
else cout<<"error"<<endl; menu();
}
void add(){cout<<"请输入要插入的信息" <<endl;
q=head;
q=(node*)malloc(sizeof(node));
cout<<"学号"<<endl;
cin>>q->number;
cout<<"姓名" <<endl;
cin>>q->name;
cout<<"成绩"<<endl;
cin>>q->score;
p->next=q;
q->next=NULL;
p=q;
n=n+1;
cout<<"n="<<n<<endl;
menu();
}
void Search()
{int m;cout<<" 请要查找的输入学号"<<endl;
cin>>m;
node *Pointer;
Pointer=head;int j=0;
while(Pointer!=NULL)
{
if(Pointer->number==m)
{
cout<<"你的姓名是"<<Pointer->name<<endl;
cout<<"你的成绩是"<<Pointer->score<<endl;
j=1;
break;
}
Pointer=Pointer->next;
}
if(j!=1)cout<<"查无此人"<<endl;;
menu();
}
void Delete()
{int m;cout<<" 请要删除的输入学号"<<endl;
cin>>m;
node *Pointer;
Pointer=head;
while(Pointer!=NULL)
{
if(Pointer->next==NULL)
{free(Pointer);
break;
}
if(Pointer->next->number==m)
{
Pointer->next=Pointer->next->next;
free(Pointer->next);
break;
}
else cout<<"错误"<<endl;
Pointer=Pointer->next;
}
n=n-1;
menu() ;
}
void sort(){cout<<" 排序"<<endl;
node* p=NULL;
node* q=NULL;
int temp;int m; char bae[20] ;
for(p=head;p!=NULL;p=p->next)
{
for(q=p->next;q!=NULL;q=q->next)
{
if(p->score<q->score)
{
temp=p->score;
p->score=q->score;
q->score=temp;
m=p->number;
p->number=q->number;
q->number=m;
strcpy(bae,p->name);
strcpy(p->name,q->name);
strcpy(q->name,bae);
}
}
} node* w;
int k=1;
for(w=head;w->next!=NULL;w=w->next)
{cout<<"----------------名次" <<k<<"----------------"<<endl;
cout<<"姓名"<<w->name<<endl;
cout<<"学号"<<w->number<<endl;
cout<<"成绩"<<w->score<<endl;k=k+1;}menu() ;
}
int main() {menu();
return 0;
}
相关文章推荐
- 链表+数据库+Makefile-----学生管理系统小结
- 【数据库】学生档案管理系统(续)
- 【数据库】学生档案管理系统
- 用链表构建学生信息库
- 单链表构建学生信息管理系统(C++)
- 学生管理系统(链表+数据库)学习小结
- (转摘)_《数据库设计入门经典》:构建快速执行的数据库模型_8.5 使用视图
- 使用设计模式构建通用数据库访问类
- redis数据库管理之List(链表)类型
- 使用ASP.NET Web Api构建基于REST风格的服务实战系列教程【二】——使用Repository模式构建数据库访问层
- 用一个异质链表(多态性)保存学生数据
- 经典SQL学习笔记 (十)-学生信息数据库练习
- 用链表编写学生管理系统(涵盖文件的输入输出)
- (一个代码学会c语言操作数据库)linux上通过c语言操作数据库实现基本的学生信息管理系统(增、删、查、改‘显示)
- 构建高性能数据库缓存之redis主从复制
- 链表基础与解析//建立一个拥有3个学生数据的动态链表
- 在 Oracle 数据库上使用 Visual Studio 2005 或 2008 构建 .NET 应用程序
- 学生成绩管理系统(链表的实现)
- 学习札记――seed方法构建初始数据库
- 用文件和链表实现学生信息管理