#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 20
typedef struct information{
int ID;
char name[20];
int num;
int time;
char book[10];
}xinxi;
typedef struct Node{
xinxi data;
struct Node *next;
}Node,*LinkList;
typedef struct paiming{
char name[20];
int num;
}r[20],z;
void input(LinkList &head);
int Search(LinkList head,int n);
void search(LinkList head);
void update(LinkList head);
void shuju(LinkList head);
void jieshu(LinkList head);
void huangshu(LinkList head);
void xujie(LinkList head);
void zoulian(LinkList head,int n);
void shangchu(LinkList &head);
int main()
{
LinkList head=NULL;
int n;
do{
printf("\n");
printf("1.注冊\n");
printf("2.查找\n");
printf("3.修改\n");
printf("4.查詢大資料\n");
printf("5.借書\n");
printf("6.還書\n");
printf("7.續借\n");
printf("8.洗掉\n");
printf("9.退出\n");
scanf("%d",&n);
switch(n)
{
case 1:input(head);break;
case 2:search(head);break;
case 3:update(head);break;
case 4:shuju(head);break;
case 5:jieshu(head);break;
case 6:huangshu(head);break;
case 7:xujie(head);break;
case 8:shangchu(head);break;
case 9:break;
default:printf("error!");break;
}
}
while(n!=9);
return 0;
}
void input(LinkList &head) //輸入
{
int loc;
LinkList pre,p;
xinxi stu;
printf("輸入學號、姓名、借書數量、借閱時間:\n");
scanf("%d %s %d %d",&stu.ID,stu.name,&stu.num,&stu.time);
p=(LinkList)malloc(sizeof(Node));
p->data=https://bbs.csdn.net/topics/stu;
if(head==NULL){
head=p;
head->next=NULL;
}
else{
loc=Search(head,stu.ID) ;
if(loc==0){
p->next=head->next;
head->next=p;
p->next=NULL;
}
}
}
int Search(LinkList head,int n) //查找相同
{
int flag=0;
LinkList p;
p=head;
while(p!=NULL){
if(p->data.ID==n)
flag=1;
else{
p=p->next;
}
}
return flag;
}
void search(LinkList head) //查詢
{
int flag=1;
int num;
LinkList pre;
pre=head;
printf("輸入查詢學號:");
scanf("%d",&num);
while(pre!=NULL&&flag){
if(pre->data.ID==num)
{
printf("姓名:%s\n借書數量:%d\n借閱時間:%d\n",pre->data.name ,pre->data.num ,pre->data.time );
flag=0;
}
else{
pre=pre->next;
}
}
if(flag)
printf("沒有查詢到!");
}
void update(LinkList head) //修改
{
int num,flag=1;
LinkList pre;
pre=head;
printf("輸入修改學號:");
scanf("%d",&num);
while(pre!=NULL&&flag){
if(pre->data.ID==num)
{
printf("輸入修改的姓名,借閱數量,借閱時間");
scanf("%s %d %d",pre->data.name ,&pre->data.num ,&pre->data.time );
flag=0;
}
else{
pre=pre->next;
}
}
if(flag)
printf("沒有查詢到!");
}
void shuju(LinkList head) //資料排行榜
{
int i=0,j,k,t;
z team;
r p;
LinkList pre;
pre=head;
printf("閱讀資料:\n");
while(pre!=NULL){
printf("%s %d",pre->data.name ,pre->data.num );
pre=pre->next;
}
while(pre!=NULL){
p[i].num=pre->data.num;
strcpy(p[i].name,pre->data.name);
pre=pre->next;
i++;
}
t=i;
for(j=0;j<t;j++){
k=j;
for(i=j+1;i<t;i++)
if(p[k].num >p[i].num )
k=i;
if(k!=j){
team=p[k];
p[k]=p[j];
p[j]=team;
}
}
printf("借閱排行榜:\n");
for(i=t;i>=0;i--){
printf("%s %d",p[i].name ,p[i].num );
}
printf("未還按時換書的人(借書最長一個月):\n");
while(pre!=NULL){
k=30-pre->data.time;
if(k<0)
printf("姓名:%s 逾期天數:%d",pre->data.name ,k);
pre=pre->next;
}
}
void jieshu(LinkList head) //借書
{
int n;
LinkList pre;
pre=head;
printf("輸入學號:");
scanf("%d",&n);
// pre=zoulian(pre,n);
printf("輸入所借書名:\n");
printf("1--book1\n2--book2\n3--book3\n4--book4\n5--book5\n");
scanf("%d",&n);
switch(n)
{
case 1:strcpy(pre->data.book,"book1");
case 2:strcpy(pre->data.book,"book2");
case 3:strcpy(pre->data.book,"book3");
case 4:strcpy(pre->data.book,"book4");
case 5:strcpy(pre->data.book,"book5");
default:printf("查無此書!");break;
}
}
void huangshu(LinkList head){ //還書
int n;
LinkList pre,p;
printf("輸入學號:");
scanf("%d",&n);
// pre=zoulian(pre,n);
strcpy(pre->data.book,"zero");
pre->data.time=pre->data.time-1;
}
void xujie(LinkList head){ //續借
int n,m;
LinkList pre;
pre=head;
printf("輸入學號:\n輸入續借天數:\n");
scanf("%d %d",&n,&m);
// pre=zoulian(pre,n);
pre->data.time=pre->data.time+m;
printf("續借成功,剩余天數:%d",pre->data.time);
}
void shangchu(LinkList &head){ //洗掉
int n,i,j,count=1,flag=0;
LinkList pre,p;
pre=head;
printf("輸入學號:");
scanf("%d",&n);
while(pre!=NULL&&flag){ //跳到當前并定位
if(pre->data.ID==n)
flag=1;
else{
pre=pre->next;
count++;
}
}
if(i==1){
pre=head;
head=head->next;
}
else{
j=0;p=head;
while(p->next&&j<i-1){
p=p->next ;j++;
}
if(!p->next||j>-1)
{
printf("查無此人!");
return;
}
pre=p->next;
p->next=pre->next;
}
}
/*void zoulian(LinkList pre,int n) //跳到到當前位置
{
int count=1,flag=0;
// LinkList p;
// p=pre;
while(pre!=NULL&&flag){
if(pre->data.ID==n)
flag=1;
else{
pre=pre->next;
count++;
}
}
return pre;
}*/
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/19095.html
標籤:基礎類
上一篇:程式作業求幫忙。
