C Language Design Book registration system and car park management System example sharing _c language

Source: Internet
Author: User
Tags current time strcmp

Book Registration Management System

The book Registration management system should have the following functions:
(1), through the keyboard to enter a book information;
(2), given the book number, display the information of the book;
(3), given the name of the author, display all the book information written by the author;
(4), a given publishing house, display all the library information;
(5), given the book number, delete the information of the book;
(6), provide some statistics of various types of information functions.

The complete implementation code for the program is as follows:

#include "stdio.h" #include "stdlib.h" #include "string.h" typedef struct BOOK {int book_id;  Book number char book_name[20];    Book name Char name[20];    Author name Char press[20]; 
Publishing house struct book *next; 
}book; 
Book *head=null;  int length; 
  The length of the linked list void Create () {book *p1,*p2; 
  length=0; 
  p1= (Book *) malloc (sizeof (book)); 
  p1->book_id=-1; 
  if (head==null) head=p1; 
  printf ("Please enter the book number, name, author name, publisher information: \ n"); 
    while (1)//library number 0, exit {p2= (book *) malloc (sizeof); scanf ('%d%s%s '%s ', &p2->book_id,p2->book_name,p2->name,p2->press); Enter book information if (p2->book_id==0) {printf ("Book Information input complete!") 
      \ n "); 
    Break } length++; 
    The length of the linked list p1->next=p2; 
    p2->next=null; 
  p1=p1->next; 
} return; 
  } void Display () {book *p=head->next; 
  printf ("All the book information in the list is as follows: \ n"); 
    while (P!=null) {printf ("%d%s%s%s\n", p->book_id,p->book_name,p->name,p->press); p=p->next; 
} return; 
  void search () {int num,x,flag1=0,flag2=0; 
  Char name[20],press[20]; 
  Book *p=head->next; 
  printf ("1, find by book number \ n"); 
  printf ("2, find by author name \ n"); 
  printf ("3, look up according to the publisher \ n"); 
  printf ("Please select Features:"); 
  scanf ("%d", &x); 
    if (x==1) {printf ("The book number to look for is:"); 
 
    scanf ("%d", &num); 
        while (P!=null) {if (p->book_id==num) {printf (the information for books numbered%d is as follows: \ n ", num); 
        printf ("%d%s%s%s\n", p->book_id,p->book_name,p->name,p->press); 
      Return 
    } p=p->next; } if (P==null) printf ("No such record!") 
  \ n "); 
    else if (x==2) {printf ("The name of the author to look for is:"); 
    scanf ("%s", name); while (P!=null) {if (strcmp (p->name,name) ==0) {if (flag1==0) printf ("The book information written by author%s is as 
        Under: \ n ", name); 
        Flag1=1; 
      printf ("%d%s%s%s\n", p->book_id,p->book_name,p->name,p->press); 
    } p=p->next; 
    }if (flag1==0) printf ("Library does not have author%s written book!\n", name); 
    else if (x==3) {printf ("The publisher to look for is:"); 
    scanf ("%s", press); while (P!=null) {if (strcmp (p->press,press) ==0) {if (flag2==0) printf ("Publisher for%s" diagram 
        The book information is as follows: \ n ", press); 
        Flag2=1; 
      printf ("%d%s%s%s\n", p->book_id,p->book_name,p->name,p->press); 
    } p=p->next; 
  } if (flag2==0) printf ("Library does not have publishing house%s written book!\n", press); 
} return; 
  } void Delete () {int num; 
  Book *p,*q; 
  q=head,p=head->next; 
  printf ("Please enter the book number to delete: \ n"); 
 
  scanf ("%d", &num); 
      while (P!=null) {if (p->book_id==num) {q->next=p->next; 
      Free (p); 
      length--; printf (delete succeeded!) 
      \ n "); 
    return; 
    } p=p->next; 
  q=q->next; } if (P==null) {printf ("Cannot find the book number to delete!") 
    \ n "); 
  return; } void Menu () {printf ("________________________________________________________________\n ");        printf ("| 
  Book Registration Management system |\n ");        printf ("| 
  0, exit the system |\n ");        printf ("| 
  1, the input book Information |\n ");        printf ("| 
  2, display book Information |\n ");        printf ("| 
  3, inquires the book Information |\n ");        printf ("| 
  4, delete the book Information |\n "); 
  printf ("________________________________________________________________\n"); 
return; 
  int main (void) {int A; 
  menu (); 
    while (1) {printf ("Please select the appropriate feature:"); 
    scanf ("%d", &a); 
    Switch (a) {case 0:return 0; 
      Case 1:create (); 
      menu (); 
    Break 
        Case 2:if (head) {display (); 
      menu (); else {printf ("Book Information is empty, please enter book information!") 
        \ n "); 
      menu (); 
    } break; 
        Case 3:if (head) {search (); 
      menu (); else {printf ("Book Information is empty, please enter book information!") 
        \ n "); 
      menu (); } bReak; 
        Case 4:if (head) {Delete (); 
      menu (); else {printf ("Book Information is empty, please enter book information!") 
        \ n "); 
      menu (); 
    } break; 
    Default:break; 
  } system ("Pause"); 
return 0; 

 }


Parking Management System
A car park is a long, narrow passageway that can park n cars, and there is only one door available for cars to enter and exit. The car in the car park in the order of arrival time, in turn by the north to the south of the arrangement (the door at the southernmost end, the first car to arrive is parked at the northernmost end of the car park, and if the car park is full of n cars, then the car can only wait on the sidewalk outside the door, and once the car is gone, the first car on the sidewalk can be opened. When a car in the parking lot is going to leave, after it entered the vehicle must first exit the park to make way for it, waiting for the car outside the gate, other vehicles in the original order into the yard, each car parked in the parking lot when it left the car parks must be in accordance with the length of its stay to pay fees. Try to prepare the simulation program for the parking lot to be managed according to the above requirements.
Basic requirements:
Simulating the car park by stack, simulating the sidewalk outside the yard by the queue and simulating the input data sequence from the terminal. Each group of input data includes three data items: Car "arrival" or "departure" information, car license number, and time of arrival or departure. The output information for each set of input data is as follows: If the vehicle arrives, it outputs the car's parking position in the car park or on the sidewalk, and if the vehicle leaves, the time of the car's stay in the car park and the fee payable (no charge for the time spent on the sidewalk). The stack is implemented in order structure, and the queue is realized by the linked list structure.

The complete implementation code is as follows:

The first method:

#include "stdio.h" #include "stdlib.h" #include "string.h" #define MAX 2//garage capacity #define price 0.05//per car per minute Ty  
  pedef struct timing//time node {int hour;  
int min; 
}time;  
  typedef struct NODE//vehicle information Node {char num[10];  
  Time reach;  
Time leave; 
}carnode;  
  typedef struct NODE//analog station {Carnode *stack[max+1];  
int top; 
}seqstackcar;  
  typedef struct CAR {Carnode *data;  
struct car *next;  
}queuenode;  
  typedef struct NODE//analog channel {Queuenode *head;  
Queuenode *rear; 
 
}linkqueuecar; void Initstack (Seqstackcar *); Initialize stack int initqueue (LINKQUEUECAR *); Initialization of the sidewalk int arrival (Seqstackcar *,linkqueuecar *); Vehicles arrive at void leave (Seqstackcar *,seqstackcar *,linkqueuecar *); The vehicle leaves void list (seqstackcar,linkqueuecar);  
  Display stored at information int main (void) {Seqstackcar enter,temp;  
  Linkqueuecar wait;  
  int ch;  Initstack (&enter);   Initialization of the station Initstack (&TEMP);   Initialize the temporary stack initqueue (&wait);  Initialize channel while (1) {
    printf ("\ n 1.  
    The car arrive\n "); printf ("2.  
    The car leave\n "); printf ("3.  
    The schedule\n "); printf ("4.  
    Exit\n ");  
      while (1) {scanf ("%d", &ch);  
      if (ch>=1 && ch<=4) break;  
    else printf ("\nplease choose:1|2|3|4.");  Switch (CH) {case 1:arrival (&enter,&wait); 
    The vehicle arrives at break;  Case 2:leave (&enter,&temp,&wait); 
    The vehicle leaves the break;  Case 3:list (enter,wait);  List printing information case 4:exit (0);  
    Exit main program Default:break;  
  }} void Initstack (Seqstackcar *s)//initialize stack {int i;  
  s->top=0;  
for (i=0;i<=max;i++) s->stack[s->top]=null;  
  int Initqueue (Linkqueuecar *q)//initialization Sidewalk {q->head= (Queuenode *) malloc (sizeof (Queuenode));  
    if (q->head!=null) {q->head->next=null;  
    q->rear=q->head;return 1;  
else return-1;  
  } void Print (Carnode *p,int room)//print out the information of the outbound car {int a1,a2,b1,b2;  
  printf ("\nplease input thedepart time:/**:* * *");  
  scanf ("%d:%d",& (p->leave.hour),& (p->leave.min));  
  printf ("\nthe number of the car:");  
  Puts (p->num);  
  printf ("\nthe time" car arrive:%d:%d ", p->reach.hour,p->reach.min);  
  printf ("The Depart Time:%d:%d", p->leave.hour,p->leave.min);  
  a1=p->reach.hour;  
  a2=p->reach.min;  
  b1=p->leave.hour;  
  b2=p->leave.min;  
  printf ("\nthe fee:%2.1f Yuan", ((B1-A1) *60+ (B2-A2)) *price);  
Free (p);  
  } int Arrival (Seqstackcar *enter,linkqueuecar *w)//vehicle arrival in {Carnode *p;  
  Queuenode *t;  
  p= (Carnode *) malloc (sizeof (Carnode));  
  Flushall ();  
  printf ("\ninput the" of the car (example: Shaanxi A1234): ");  
  Gets (P->num);  
    if (Enter->top<max)//Depot not full, car into the yard {enter->top++;  
    printf ("\nthe place", enter->top); printf ("\nthe time"Car arrive:/**:* * ");  
    scanf ("%d:%d",& (p->reach.hour),& (p->reach.min));  
    enter->stack[enter->top]=p;  
  return 1;  
    else//The garage is full, the car into the sidewalk {printf ("\ n the car must be waiting on the sidewalk!");  
    t= (Queuenode *) malloc (sizeof (Queuenode));  
    t->data=p;  
    t->next=null;  
    w->rear->next=t;  
    w->rear=t;  
  return 1;  
  } void Leave (Seqstackcar *enter,seqstackcar *temp,linkqueuecar *w)//vehicle departure {int I, room;  
  Carnode *p,*t;  
  Queuenode *q; Determine if there is a car in the yard if (enter->top>0)//have a car {while (1)//Enter the information to leave the vehicle {printf (\ n Please enter the car in the location of the yard/1--%d/: ", E  
      Nter->top);  
      scanf ("%d", &room);  
    if (room>=1&&room<=enter->top) break;  
      while (Enter->top>room)//vehicle departure {temp->top++;  
      temp->stack[temp->top]=enter->stack[enter->top];  
      enter->stack[enter->top]=null;  
    enter->top--; } P=enter->stack[enter->top];  
    enter->stack[enter->top]=null;  
    enter->top--;  
      while (temp->top>=1) {enter->top++;  
      enter->stack[enter->top]=temp->stack[temp->top];  
      temp->stack[temp->top]=null;  
    temp->top--;  
    } print (P,room); Determine if there is a vehicle on the channel and whether the station is full if ((w->head!=w->rear) &&enter->top<max)//Sidewalk vehicles Enter the yard {Q=w->head  
      ->next;  
      t=q->data;  
      enter->top++;  
      printf ("\ nthe road's%s car enters the yard at position%d.", t->num,enter->top);  
      printf ("\ n Please enter the current time/**:*/");  
      scanf ("%d:%d",& (t->reach.hour),& (t->reach.min));  
      w->head->next=q->next;  
      if (q==w->rear) w->rear=w->head;  
      enter->stack[enter->top]=t;  
    Free (q);  
  else printf ("There's no car in the sidewalk. \ n"); else printf ("There's no car in the yard.");  
  No car} void List1 (Seqstackcar *s)//list show yard information {int i; if (s->top>0)//Judge whether there is a car in the station ("N-yard:");  
    printf ("\ n location arrival time license plate number");  
      for (i=1;i<=s->top;i++) {printf ("%d", I);  
      printf ("%d:%d", s->stack[i]->reach.hour,s->stack[i]->reach.min);  
    Puts (s->stack[i]->num);  
else printf ("There is no car in the yard");  
  } void List2 (Linkqueuecar *w)//list shows sidewalk information {Queuenode *p;  
  p=w->head->next;  
    if (w->head!=w->rear)//Determine if there is a car on the channel {printf ("\ n wait for the number of the vehicle is:");  
      while (P!=null) {puts (p->data->num);  
    p=p->next;  
else printf ("There is no car in the sidewalk.");  
  } void List (Seqstackcar s,linkqueuecar W) {int flag,tag;  
  flag=1;  
    while (flag) {printf ("\ n Select 1|2|3:");  
    printf ("\n1." \n2. Sidewalk \n3. Back \ n ");  
      while (1) {scanf ("%d", &tag);  
      if (tag>=1 | | tag<=3) break;  
    else printf ("\ n Please select 1|2|3:"); Switch (TAG) {Case 1:list1 (&s);  Break 
      The list shows the yard information Case 2:list2 (&AMP;W);  Break 
      The list shows the sidewalk information case 3:flag=0; 
    Break 
    Default:break;  }  
  }  
}

 
The second method:

#include "stdio.h" #include "stdlib.h" #define SIZE typedef struct {int hour;  
int min;   }time; 
  The time structure of the vehicle is typedef struct {int num; 
  int position; 
  Time t;  
float money;   }car;  
  Vehicle information typedef struct {car elem[size+1];    int top;      Point to the first empty slot in the sidewalk Stack;  
  Create a stack typedef struct NODE {car data;  
struct Node *next; 
 
}cqueuenode; 
  Establishment of the aisle procedure: typedef struct {Cqueuenode *front;  
Cqueuenode *rear;  }linkqueue; The set of the sidewalk//Sidewalk Initialization program void Initqueue (Linkqueue *q) {q->front= (cqueuenode*) malloc (sizeof (Cqueuenode));  
    The pointer converts to a pointer to a cqueuenode type of data if (q->front!=null) {q->rear=q->front; 
  q->front->next=null;  
  {Cqueuenode *newnode enterqueue (linkqueue *q,car *t)} int  Newnode= (cqueuenode*) malloc (sizeof (Cqueuenode));  
    Apply space to the sidewalk if (newnode!=null) {newnode->data.num=t->num;  
    newnode->data.t.hour=t->t.hour; Newnode->data.t.min=t->t.min;  
    newnode->next=null;  
    q->rear->next=newnode;  
    q->rear=newnode;  
  return 1;  
else return 0; 
} void Initstack (Stack *s) {s->top=0;  
  }//Ensure that the stack is empty void Push (Stack *s,car *r)//car in the sidewalk {s->top++;  
  s->elem[s->top].num=r->num;  
  r->position=s->elem[s->top].position=s->top;  
  s->elem[s->top].t.hour=r->t.hour;  
s->elem[s->top].t.min=r->t.min; 
The int isempty (stack* S)//judge whether the garage is empty {return (s->top==0?1:0); 
The int isfull (Stack *s)//judge whether the garage is full {return (s->top==size?1:0);  
  } int GetTop (Stack *s,car *n)//car departure garage {n->num=s->elem[s->top].num;  
  n->position=s->elem[s->top].position;  
  n->t.hour=s->elem[s->top].t.hour;  
  n->t.min=s->elem[s->top].t.min; 
return 1;  
  int Deletequeue (linkqueue *q,car *x) {Cqueuenode *p;   if (q->front==q->rear) return 0; Judge the sidewalk as empty p=q->front->next;   Put the car in the sidewalk into the garage q->front->next=p->next;  
  if (q->rear==p) q->rear=q->front;  
  x->num=p->data.num;  
  x->t.hour=p->data.t.hour;  
  x->t.min=p->data.t.min;   Free (p);  
Release temporary pointer return 1; } void in (Stack *s,linkqueue *q,car*r) {if (Isfull (S)) {printf ("The garage is full, please wait!")  
    ");   Enterqueue (Q,R);  
    Car into the sidewalk} else {Push (s,r);    printf ("\ n you are in position%d", r->position); 
    Location of print car} void TaM (Cars *r,int h,int m) {if (m>r->t.min) {r->t.min+=60; 
  r->t.hour-=1; 
  } h=r->t.hour-h; 
  m=r->t.min-m; 
  printf ("Parking%d hours%d minutes \ n", h,m); 
  printf ("Charge 30 yuan per hour \ n");  
  H=h*60;m=h+m;  
  r->money=0.5*m;   printf ("Please pay the amount%.2f \ n", R->money);  
  Output owner due amount} void out (Stack *s,stack *s0,car *r,linkqueue *q) {int tag=s->top;  
  Car x; if (IsEmpty (S)) printf ("No This car!")  
  ");  
 else {for (; R->num!=s->elem[tag].num && tag>0;tag--)   {Push (S0,&s->elem[tag]);  
    s->top--;  
      } if (R->num==s->elem[tag].num) {TaM (r,s->elem[tag].t.hour,s->elem[tag].t.min);  
      s->top--; for (; s0->top>0;  
      s0->top--) Push (S,&s0->elem[s0->top]);  
        if (s->top<size && q->front!=q->rear)//judge whether the garage has this car, have to find this car and then exit {Deletequeue (q,&x);  
      Push (S,&AMP;X); If the car in the aisle does not need to be charged for the tag==0 ("not to enter the car park, the amount is 0 yuan!")  
      "); for (; s0->top>0;   
    s0->top--) Push (S,&s0->elem[s0->top]);  
  }} void Print1 (Stack *s) {int tag;  
  Car x;  
  printf ("Parking lot: \ n"); if (IsEmpty (S)) printf ("No car!")  
  "); for (tag=s->top; s->top>0; s->top--) if (GetTop (s,&x))//display the information and arrival time of a car in the garage printf ("License plate number%d, location%d, Arrival/Departure Time%d:%d\n", x.num,x.posit  
  Ion,x.t.hour,x.t.min);  
s->top=tag; } void Print2 (Linkqueue *Q) {Cqueuenode *p;  
  p=q->front->next; for (;p!=null;p=p->next)//display aisle boarding information and arrival time printf ("Wait for license plate number%d, Arrival/Departure Time%d:%d", P->data.num,p->data.t.hour,p-&gt  
;d ata.t.min);  
  } void Print () {printf ("\n*********************************** welcome *************************************\n");  
  printf ("\ n select: \ n");  
  printf ("\ n 1: Arrival");  
  printf ("\ n 2: Leave");  
  printf ("\ n 3: Search");  
  printf ("\ n 4: Exit \ n"); 
printf ("\ n"); 
  int main (void) {int n,m,i=1,j,flag=0; 
  Car c[10];    Stack S,s0;   Set stack s,so linkqueue Q;  Sidewalk Initstack (&s);  Stack s Initstack (&AMP;S0); 
  Temporary stack S0 initqueue (&q);  
    while (1) {print ();  
    scanf ("%d", &m);  
      Switch (m) {case 1:printf ("\ n Please enter the license number:");  
      scanf ("%d", &c[i].num);  
      printf ("Please enter arrival/Departure time:");  
      scanf ("%d:%d", &c[i].t.hour,&c[i].t.min);   In (&s,&q,&c[i]); i++; 
    The condition of the vehicle is break; Case 2:printf ("\ n Please enter the license number:");  
      scanf ("%d", &n);  
      for (j=0;j<10;j++) if (n==c[j].num) break;  
      printf ("Please enter arrival/Departure time:");  
      scanf ("%d:%d", &c[j].t.hour,&c[j].t.min);  Out (&AMP;S,&AMP;S0,&AMP;C[J],&AMP;Q);       
    The condition of the vehicle is break;   Case 3:print1 (&s);   Output garage in the car information Print2 (&AMP;Q);      Output the information break of aisle boarding; 
      Terminate case 4:flag=1;  
    Break  
    default:printf ("Input error, please enter 1,2,3 or 4");   } if (flag) break;  
End program} return 0; 

 }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.