Use C language to build the Address Book management system and the teaching arrangement system code example _c language

Source: Internet
Author: User
Tags define null sorted by name strcmp

Address Book Management system
the realization of the Address book input information, save information, insert, delete, sort, find, a single display and other functions.

The complete code is as follows:

#include <stdio.h> #include <malloc.h>//Get a pointer to the first byte of the memory area of size,//#include <string.h> #include < 
stdlib.h>//Standard library function//#define NULL 0 #define LEN sizeof (struct address_list)//compute byte//int n;   struct Address_list {char name[30];   Name Char work[30]; Occupational Char handset[30];  Mobile phone char email[30]; e-mail Char address[30]; 
Mailing address struct address_list *next; 
}; struct address_list *shifang (struct address_list *head); 
  Release the memory function declaration//CREATE function, not the leading node of the linked list struct address_list *creat (void) {struct address_list *head,*p1,*p2; 
  Char name[20]; 
  n=0; 
  p1= (struct address_list *) malloc (LEN);  P2=P1; 
  Force Memory Conversion printf ("Please enter the contents of the Address book!\n the name entered as 0 when the creation completed!\n"); 
  printf ("Please enter your name:"); 
  Gets (name); 
    if (strcmp (name, "0")!=0) {strcpy (p1->name,name);   printf ("Please enter Occupation:"); 
    Gets (p1->work);   printf ("Please enter your mobile phone:"); 
    Gets (P1->handset); printf ("Please enter e-mail:"); 
    Gets (P1->email); printf ("Please enter mailing address:"); 
    Gets (p1->address); Head=nuLL;  while (1) {n=n+1; 
      Records the number of address book numbers if (n==1) head=p1; 
      else p2->next=p1; 
      P2=P1; 
      printf ("Please enter your name:"); 
      Gets (name); 
      if (strcmp (name, "0") ==0) {break; 
        else {p1= (struct address_list *) malloc (LEN); 
        strcpy (P1->name,name); printf ("Please enter Occupation:"); 
        Gets (p1->work); printf ("Please enter your mobile phone:"); 
        Gets (P1->handset); printf ("Please enter e-mail:"); 
        Gets (P1->email); printf ("Please enter mailing address:"); 
      Gets (p1->address); 
    }} p2->next=null; 
  return head; 
else return 0; 
  }//Output function void print (struct address_list *head) {struct address_list *p; 
    if (head!=null) {p=head; 
    printf ("This address book now has%d people: \ n", n); 
    printf ("---name-------professional--------mobile phone-------Email-------mailing address)"; 
    printf ("==================================\n"); 
      Do {printf ("= =%s", p->name); printf (""); printf ("%s", p->work); prIntf (""); printf ("%s", P->handset); 
      printf (""); printf ("%s", P->email); 
      printf (""); printf ("%s", p->address); 
      printf ("\ n"); 
    p=p->next; 
    }while (P!=null); 
  printf ("==================================\n"); 
else printf ("Address Book is empty, cannot output!\n"); 
  }//Add function struct address_list *insert (struct address_list *head) {struct address_list; 
  Char name[20]; 
  P1=head; 
  printf ("Please enter added content: \ n"); printf ("Please enter your name:"); 
  Gets (name); 
    if (strcmp (name, "0") ==0) {printf ("name cannot be 0, increase failure!\n"); 
  return (head); 
    else {p0= (struct address_list *) malloc (LEN); 
    strcpy (P0->name,name); printf ("Please enter Occupation:"); 
    Gets (p0->work); printf ("Please enter your mobile phone:"); 
    Gets (P0->handset); printf ("Please enter e-mail:"); 
    Gets (P0->email); printf ("Please enter mailing address:"); 
    Gets (p0->address); 
    n=n+1; 
      if (head==null) {head=p0; 
      p0->next=null; 
    return head; } else {while (strcmp (P0->name,p1->name) >0&& (p1->next!=null)) {p2=p1; 
      p1=p1->next; 
        } if (strcmp (p0->name,p1->name) <0 | | strcmp (p0->name,p1->name) ==0) {if (HEAD==P1) 
        {head=p0; 
        else {p2->next=p0; 
      } p0->next=p1; 
        else {p1->next=p0; 
      p0->next=null; 
    return head; 
  }} struct address_list* delete_txl (struct address_list *head) {struct address_list *p,*q; 
  Char name[30]; 
    if (head==null) {printf ("Address Book is empty, cannot display!\n"); 
  return head; 
  } P=head; 
  printf ("Please enter the name of the person you want to delete:"); 
  Gets (name); 
    if (strcmp (head->name,name) ==0) {head=head->next; 
    Free (p); printf (the delete operation was successful!) 
    \ n "); 
  return head; 
    else {q=head,p=head->next; while (P!=null) {if (strcmp (p->name,name) ==0) {q->next=p->next; 
        Free (p); printf (the delete operation was successful!) 
        \ n "); 
      return head; 
      } p=p->next; 
    q=q->next; 
  }}//Display function struct address_list *display (struct address_list *head) {struct address_list *p1,*p2; 
  Char name[30]; 
  int m; 
    if (head==null) {printf ("Address Book is empty, cannot display!\n"); 
  return head; 
  } P1=head; 
  m=0; 
  printf ("Please enter the name of the person you want to display:"); 
  Gets (name); 
      while (P1!=null) {while (strcmp (p1->name,name))!=0 && p1->next!=null) {p2=p1; 
    p1=p1->next; 
      } if (strcmp (p1->name,name) ==0) {m++; 
      printf ("%s's newsletter is as follows: \ n", name); 
      printf ("---name--------professional--------mobile phone-------Email------mailing address)"; 
      printf ("==================================\n"); 
      printf ("= =%s", p1->name);p rintf (""); 
      printf ("%s", P1->work);p rintf (""); 
      printf ("%s", P1->handset);p rintf (""); 
      printf ("%s", P1->email);p rintf (""); printf ('%s ', p1->address); 
      printf ("\ n"); 
    printf ("==================================\n"); 
  } p1=p1->next; 
  } if (m==0) {printf ("This person is not!\n in this address book"); 
return (head); 
  }///Sort function struct address_list *paixu (struct address_list *head) {struct address_list *p1,*p2; 
  int i,j; 
    struct Address_list1 {char name[30]; 
    Char work[30]; 
    Char handset[30]; 
    Char email[30]; 
  Char address[30]; 
  }; 
  struct Address_list1 px[200]; 
  struct Address_list1 temp; 
    if (head==null) {printf ("Address Book is empty, unable to sort!\n"); 
  return (head); 
  } P1=head; 
    for (i=0;i<n,p1!=null;i++) {strcpy (px[i].name,p1->name); 
    strcpy (px[i].work,p1->work); 
    strcpy (Px[i].handset,p1->handset); 
    strcpy (Px[i].email,p1->email); 
    strcpy (px[i].address,p1->address); 
    P2=P1; 
  p1=p1->next; 
  } Head=shifang (head); 
for (j=0;j<n-1;j++) {for (i=j+1;i<n;i++) {if (strcmp (px[i].name,px[j].name) <0)      {Temp=px[i]; 
        PX[I]=PX[J]; 
      Px[j]=temp; 
  }} p1= (struct address_list *) malloc (LEN); 
  P2=P1; 
  strcpy (P1->name,px[0].name); 
  strcpy (p1->work,px[0].work); 
  strcpy (P1->handset,px[0].handset); 
  strcpy (P1->email,px[0].email); 
 
  strcpy (p1->address,px[0].address); 
  HEAD=P1; 
    for (i=1;i<n;i++) {p1= (struct address_list *) malloc (LEN); 
    strcpy (P1->name,px[i].name); 
    strcpy (p1->work,px[i].work); 
    strcpy (P1->handset,px[i].handset); 
    strcpy (P1->email,px[i].email); 
    strcpy (p1->address,px[i].address); 
    p2->next=p1; 
  P2=P1; 
  } p2->next=null; 
  printf ("Sorted by name: \ n"); 
  Print (head); 
return (head); 
  }//Name lookup function struct address_list *search (struct address_list *head) {struct address_list *p1,*p2; 
  int m; 
  Char name[30]; 
    if (head==null) {printf ("The Address book is empty, cannot be sorted to find!\n"); 
  return (head); 
  } P1=head; 
  printf ("********************\n"); PRINTF ("* * Please enter the name you want to find **\n"); 
  printf ("********************\n"); 
  m=0; 
  Gets (name); 
      while (P1!=null) {while (strcmp (p1->name,name)!=0&&p1->next!=null) {p2=p1; 
    p1=p1->next; 
      } if (strcmp (p1->name,name) ==0) {m++; 
      printf ("What you're looking for is: \ n"); 
      printf ("+++++++++++++++++++++++++++++++++++\n"); 
      printf ("+ +%s%s%s%s\n", p1->name,p1->work,p1->handset,p1->email,p1->address); 
    printf ("+++++++++++++++++++++++++++++++++++\n"); 
 
    } p1=p1->next; 
    if (m==0) {printf ("This person is not!\n in this address book"); 
  } break; 
return (head); 
  }//Free memory function struct address_list *shifang (struct address_list *head) {struct address_list *p1; 
    while (head!=null) {p1=head; 
    head=head->next; 
  Free (p1); 
return (head); 
  }//File write function void Save (struct address_list *head) {file *fp; 
  struct Address_list *p1; 
  Char tong[30]; if (head==null) {printf ("Address Book is empty, unable to store!\n"); 
  Return 
  printf ("Please enter the saved filename:"); 
  Gets (Tong); 
  Fp=fopen ("(Tong). txt", "w"); 
    if (fp==null) {printf ("Cannot open file\n"); 
  Return 
  } P1=head; 
  fprintf (FP, "name Professional mobile phone email address \");  
  for (;p 1!=null;) 
    {fprintf (FP, '%s%s%s%s\n ', p1->name,p1->work,p1->handset,p1->email,p1->address); 
  p1=p1->next; 
  printf ("Save Complete!\n"); 
Fclose (FP); 
  }//File readout function struct address_list *load (struct address_list *head) {file *fp; 
  Char tong[30]; 
  struct Address_list *p1,*p2; 
  printf ("Please enter the filename to be exported:"); 
  Gets (Tong); 
  Fp=fopen ("(Tong). txt", "R"); 
    if (fp==null) {printf ("This address book name does not exist, cannot output!\n"); 
  return (head); 
  else {Head=shifang (head); 
  } p1= (struct address_list *) malloc (LEN); FSCANF (FP, "%s%s%s%s%s",&p1->name,&p1->work,&p1->handset,&p1->email,&p1-> 
  address); if (feof (FP)!=0) {printf ("file isEmpty, unable to open!\n "); 
  return (head); 
    else {rewind (FP); 
    P2=P1; 
    HEAD=P1; 
    n=0; while (feof (FP) ==0) {fscanf (FP, "%s%s%s%s%s",&p1->name,&p1->work,&p1->handset,&p1-> 
      email,&p1->address); 
      if (feof (FP)!=0) break; 
      p2->next=p1; 
      P2=P1; 
      p1= (struct address_list *) malloc (LEN); 
    n=n+1; 
    } p2->next=null; 
    P1=head; 
    head=head->next; 
    n=n-1; 
    Free (p1); 
    Print (head); 
    printf ("Open!\n"); 
  return (head); 
Fclose (FP); 
  }//Integrated operation function struct address_list *menu (struct address_list *head) {char num[10]; 
    while (1) {printf ("*********************\n"); 
    printf ("* * * 1 name search ****\n"); 
    printf ("* * * 2 single display ****\n"); 
    printf ("* * * 3 increase ****\n"); 
    printf ("* * * 4 exit ****\n"); 
    printf ("*********************\n"); 
    printf ("Please enter the action you selected:"); 
    Gets (num); 
      Switch (*num) {case ' 1 ': {  Head=search (head); 
      Name lookup print (head); 
    } break;             Case ' 2 ': {Head=display (head); 
    Show} break;              Case ' 3 ': {Head=insert (head); 
      Add print (head); 
    } break; 
    Case ' 4 ': return head; 
      default:printf ("Operation error, this item does not exist!\n"); 
    Break 
  } if (strcmp (num, "6") ==0) break; 
return head; 
  }//Main function void main () {struct address_list *head=null; 
  Char num[10]; 
  printf ("*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"); 
  printf ("*=* Program Description *=*\n");  printf ("*=* please save the created Address Book in time!") 
  *=*\n "); 
  printf ("*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"); 
    while (1) {printf ("************************\n"); 
    printf ("* * * 1 Create Address Book ****\n"); 
    printf ("* * 2 sorted by name ****\n"); 
    printf ("* * * 3 integrated Operation ****\n"); 
    printf ("* * * 4 save ****\n"); printf ("* * * 5 open ****\n");  
    printf ("* * * 6 delete ****\n"); 
    printf ("* * * 7 exit ****\n"); 
    printf ("************************\n"); 
    printf ("Please enter the action you selected:"); 
    Gets (num);                Switch (*num) {case ' 1 ': {if (head==null) {head=creat (); 
        Create print (head); 
          else {Head=shifang (head);                Head=creat (); 
        Re-create the print (head); 
    }} break;                Case ' 2 ': {Head=paixu (head); 
    sort} break;               Case ' 3 ': {Head=menu (head); 
    Integrated operation} break;                  Case ' 4 ': {Save (head); 
      File Save print (head); 
    } break;               Case ' 5 ': {head=load (head); 
    File output} break;              Case ' 6 ': {HEAD=DELETE_TXL (head); 
      Delete print (head); } bReak; 
      Case ' 7 ': Head=shifang (head); 
    Break 
      default:printf ("Operation error, this item does not exist!\n"); 
    Break 
  } if (strcmp (num, "7") ==0) break; 

 } 
}

Karaoke Management system

#include "stdlib.h" #include "stdio.h" #define MAX typedef struct {int s[max][max];//with two-dimensional array storage teacher professional expertise I NT D[max]; 
The teaching task}mgraph with one dimensional array storage arrangement; 
Mgraph G;   
  int creat (int *k,int N)//initialization, assigns the adj of both two-dimensional array s and one-dimensional array D to 0 {int i,j;   
    for (i=1;i<=n;i++) {g.d[i]=0;   
    k[i]=0;  
  for (j=1;j<=n;j++) g.s[i][j]=0;   
  printf ("n");   
  printf ("Number of accounts successfully identified as%d/n", N); 
return 1;   
  int techer_speciality (int n) {int k,i;   
  printf ("Please enter teacher professional specialist number (1-%d) 0 for end input:/n", N);   
    for (i=1;i<=n;i++) {printf ("Enter the specialty number%d for teacher number:", i);   
      do {scanf ("%d", &k); 
        if (k>n) {printf ("Out of range, reenter:"); 
      Continue 
    else g.s[i][k]=1;   
  }while (k); printf ("Set success!")   
  /n ");   
Return 1;//Set Success! 
  int serch (int i,int j,int N) {for (; j<=n;j++) {if (g.s[i][j]==1) break;   
} return J; int serch_error (int *k,inT n)//Run {int t,i,j when all teachers have been arranged; static int b=0; b detect whether there are two or more than two majors only one teacher can be granted for (j=1;j<=n;j++) if (k[j]==0)//exists There are no teachers to teach for (i=1;i<=n;i++)//which teacher 
          This account can be delegated and this account currently does not have a teacher teaching if (g.s[i][j]==1) {if (b!=i) b=i; else return 0; if (b!=i) B=i records the first subject that has not been taught but a teacher can teach a teacher subscript//If you run this function again and another subject that is not taught by this teacher can be delegated, that is, there are//multiple subjects only this teacher can be delegated, that is, the teacher calling this function   
          There are no subjects to grant.   
          T=g.d[i]; if (g.d[i]==0) return 0; 
          May have behind the teacher has not been arranged, return and so on all teachers have been arranged before the g.d[i]=j; 
          K[j]=i; 
          k[t]=0;   
        Return 1;//have, let this teacher teach this class, the lesson that originally teaches cancels, reschedule. return 0;   
  (no subjects are not arranged) or (there are subjects not arranged but no teachers have this expertise)} int Anpai (int *k,int n) {int c[max]={0},i,j, JS, p=0,t;   
      for (i=1;i<=n;i++) {if (g.d[i]==0) {j=1;   
        while (1) {js=serch (i,j,n); if (js<=n) {C[p++]=js//Save teacher expertise returned from Serch if (k[js]<=0) {g.d[i]=js;k[js]=i;p=0;break; 
            else {j=js; 
          j + +;   
          } else {p =;   
          T=K[C[P]];   
          j=c[p]+1;   
            while (1) {js=serch (t,j,n); if (k[js]<=0 && js<=n) {k[c[p]]=0; G.d[t]=js; k[js]=t; G.D[I]=C[P]; K[c[p]]=i; p = =;   
            Break   
            else if (js<=n) j + +; 
              else {p++; 
                if (c[p]==0) {g.d[i]=0; 
                if (Serch_error (k,n)) Anpai (k,n);   
              Break   
            } t=c[p];j=c[p]+1;   
        }} break; "The teacher expertise course is set up successfully!" 
  /n "); Return 1; 
  } void display (int n) {int ch,i;  
  printf ("Teacher number Course Number/n");   
for (i=1;i<=n;i++) printf ("%5d%13d/n", i,g.d[i));   
  } void list (int n) {int i,j;  
    for (i=1;i<=n;i++) {printf ("%3d Teacher's professional strengths are:", I); 
    for (j=1;j<=n;j++) if (G.s[i][j]) printf ("%3d/n", j);   
  printf ("n"); 
  } void edit (int n) {int k,i=0,m=0,j=0; 
  printf ("Please enter the teacher to modify:"); while (i==0| | 
    I>n) {scanf ("%d", &i); 
    if (i>0 && i<=n) printf ("%d teacher's specialty subjects are:", I); else printf ("Not this teacher!") 
  Please re-enter:/n ");  
      for (k=1;k<=n;k++) {if (g.s[i][k]==1) {printf ("%3d/n", K);   
    j + +; 
  } if (j==0) printf ("No specialized account/n"); 
  printf ("/n Enter the account you want to modify (enter 0 end):/n");   
    do {scanf ("%d", &k); 
      if (k>n) {printf ("Out of range, reenter:"); 
    Continue   
    else if (g.s[i][k]==1) g.s[i][k]=0; else g.s[i][k]=1;   
  }while (k); 
  printf ("Revised%d teacher's specialty subjects are:", I); 
      for (k=1;k<=n;k++) {if (g.s[i][k]==1) {printf ("%3d/n", K);   
    m++; 
  } if (m==0) printf ("No specialized account/n"); 
printf ("n"); 
  the int main (void) {int k[max],ch,i=0, n=0,w=0,a=0;//n 0 is used to indicate that no I check whether the speciality course set W check whether the account number set a check whether the course is scheduled char CX; 
    while (1) {printf ("┏━━━━━━━━ Welcome into the teaching task scheduling system ━━━━━━━━┓/n"); 
    printf ("§§/n"); 
    printf ("§1-----Determine the number of subjects 2-----teacher Expertise Course set §/n"); 
    printf ("§3-----Course Arrangement 4-----teacher Expertise Browsing §/n"); 
    printf ("§5-----Teacher Specialty Curriculum Revision 6------View teaching task Arrangement §/n"); 
    printf ("§0-----exit System §/n"); 
    printf ("└────────────────────────────┘/n"); 
    printf ("Please select Features"); 
    scanf ("%d", &ch);   
    printf ("n"); 
          Switch (CH) {Case 1: {if (!w) {printf ("Please determine course number or number of teachers"); 
          scanf ("%d", &n); 
          W=creat (k, n); 
        Break }//Initialize else {printf("You have determined the number of courses, whether to confirm (is: y/y: the remaining key)"); 
          scanf ("%c", &AMP;CX); 
            if (cx== ' y ' | | | | cx== ' y ') {printf ("Re-enter Course Number:"); 
            scanf ("%d", &n); 
            W=creat (k, n); 
          Break   
        else break;   
        Case 2: {if (!w) printf ("Please first determine the number of accounts!/n/n"); 
          else if (i) {printf ("You have a teacher expertise course set, whether to reset (yes: y/y No: The remaining key)");  
          scanf ("%c", &AMP;CX); 
            if (cx== ' y ' | | | cx== ' y ') {i=techer_speciality (n);  
          Break   
        else break;   
        else i=techer_speciality (n); 
      Break   
        Case 3: {if (!w) printf ("Please first determine the number of accounts!/n/n");   
        else if (!i) printf ("Please first teacher specialty course set!/n"); 
        else Anpai (k,n);   
      Break Case 4: {if (!w) printf ("Please first determine the number of accounts and teacherSpecialty Course Setting!/n/n ");   
        else if (!i) printf ("Please first teacher specialty course set!/n"); 
      else list (n);//Teacher expertise browsing function break;   
        Case 5: {if (!w) printf ("No fixed number of subjects!/n");  else if (!i) printf ("Teacher expertise course is not set/n"); Teacher Expertise Course modification function else edit (n);   
      Modify function break;   
        Case 6: {if (!w) printf ("Please first determine the number of accounts!/n/n");  else if (!i) printf ("Please first teacher specialty course set!/n");  
        View teaching task scheduling function else if (!a) printf ("Please select course schedule!/n");   
        else;//view teaching task scheduling function; 
      Break 
        Case 0: {printf ("************** Thank you for using ************/n"); 
      return; 
    } default:printf ("New Select function:/n"); 
  } system ("Pause"); 
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.