C language realizes the curriculum design of class file management system

  • 2020-06-23 01:37:43
  • OfStack

This article shares the specific code of C language class file management system for your reference. The specific content is as follows

I did a very long course design, as a reference


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 20
struct student
{
 long num;
 char name[20];
 char sex[10];
 int age;
 char bz[40];
 struct student *next;
};
int i,j,n,num2,num3,age3,k,m;
char name3[20],sex3[20],bz3[20],ch;
FILE *fp;
int login() // Log in function 
{
 char key[20];
 printf("\t  ******************** Please enter the system password ********************\n");
 do
 {
 scanf("%s",key);
 if((strcmp("a",key))==0)
 {
 printf("\t        password correct ,welcome !\n");
 return 1; // When the password is correct, return 1 , enter the system 
 }
 printf("\t        password incorrect,please input again!\n");
 }while(key!=1);// When the return value is not 1 Enter the password again until it is entered correctly 
 system("cls");
}
int menu() // The menu 
{
 int c;
 printf("\t\t********** Welcome to the communication client! ************\n\n");
 printf("\t\t| -- -- - 1. Input basic information of students -- |\n");
 printf("\t\t|----------2. Displays basic information about students ----------|\n");
 printf("\t\t|----------3. Save basic information about students ----------|\n");
 printf("\t\t|----------4. Delete basic information about students ----------|\n");
 printf("\t\t|----------5. Modify the student's basic information ----------|\n");
 printf("\t\t|----------6. Check the basic information of students ----------|\n");
 printf("\t\t| -- -- - 7. Quit the system -- |\n");
 printf("\t\t Please select the function you want to work on (0~7) ");
 scanf("%d",&c);
 return c;
}
struct student *creat() // Input information function 
{
 struct student *head,*p1,*p2;
 n=0;
 p1=p2=(struct student *)malloc(sizeof(struct student));
 head=NULL;
 printf(" Please enter your student number, name, gender, age, and remarks 0 When the end) \n");
 while(1) // for 1 Table I, p2->next Don't for 0 ; 
 {
 scanf("%d",&p1->num);
 if(p1->num==0) // Determine if the student's student number is 0 If for 0 Then stop input data; 
 {
  break;
 }
 scanf("%s%s%d%s",p1->name,p1->sex,&p1->age,p1->bz);
 n=n+1;
 if(n==1)
 {
  head=p1;
 }
 else
 {
  p2->next=p1;
 }
 p2=p1;
 p1=(struct student *)malloc(sizeof(struct student));
 }
 p2->next=NULL;
 system("cls");
 return(head);
}
void print(struct student *head) // Output information function 
{
 struct student *p;
 printf("\t\t There's a  %d  Student data information \n",n);
 p=head;
 if(head!=NULL)
 {
 do
 {
 printf("\t\t Student id :%d\t The name :%s\t gender :%s\t age :%d\t note :%s\n",p->num,p->name,p->sex,p->age,p->bz);
 p=p->next;
 }while(p!=NULL);
 }
 else
 {
 return 0;
 }
 printf("\n");
}
int save(struct student *p) // Save information function 
{
 FILE *fp;
 if((fp=fopen("keshe.txt","wb"))==NULL)
 {
 printf("open file fail\n");
 }
 fp=fopen("stud","wb");
 do
 {
 fwrite(p,sizeof(struct student),1,fp);
 p=p->next;
 }while(p!=NULL);
 printf("\t\t\t Save success !\n");
 fclose(fp);
 return 0;
}
struct student *del(struct student *head)
{
 struct student *p1,*p2;
 printf("\t\t Please enter the student id you want to delete \n");
 scanf("%d",&num2);
 p1=head;
 if(head->num==num2)
 {
 head=head->next;
 free(p1);
 n--;
 }
 else
 {
 
 p2=head;
 while(p2->num!=num2&&p2->next!=NULL)
 {
  p1=p2;
  p2=p2->next;
 }
 if(p2->num==num2)
 {
  p1->next=p2->next;
  n--;
 }
 printf("delete:%ld\n",num2);
 }
 return (head);
}
int mod(struct student *head); // Modify information function 
struct student *modify(struct student *head)
{
 if(login()==0)
 {
 return 0;
 }
 else
 {
 struct student *p1;
 j=0;
 p1=(struct student *)malloc(sizeof(struct student));
 printf("\t\t\t Please enter the student number you want to change \n");
 scanf("%d",&num2);
 printf("\t\t\t Student id \n");
 scanf("%d",&num3);
 printf("\t\t\t The name \n");
 scanf("%s",name3);
 printf("\t\t\t gender \n");
 scanf("%s",sex3);
 printf("\t\t\t age \n");
 scanf("%d",&age3);
 printf("\t\t\t note \n");
 scanf("%s",bz3);
 p1=head;
 if(head->num==num2)
 {
  head->num=num3;
  strcpy(head->name,name3);
  strcpy(head->sex,sex3);
  head->age=age3;
  strcpy(head->bz,bz3);
  j=1;
 }
 else
 {
  p1=head->next;
  if(p1!=NULL)
  {
  while(p1->num!=num2)
  {
   p1=p1->next;
  }
  p1->num=num2;
  strcpy(p1->name,name3);
  strcpy(p1->sex,sex3);
  p1->age=age3;
  strcpy(p1->bz,bz3);
  j=1;
  }
 }
 if(j==0)
 {
  printf("\t\t\t Change the failure \n");
 }
 else
 {
  printf("\t\t\t Change the success \n");
 }
 }
 system("cls");
 mod(head);
}
int mod(struct student *head)
{
 printf("\t\t\t Please select a \n");
 printf("\t\t\t1: Revise student information by student number \n");
 printf("\t\t\t2: Output the revised student information \n");
 printf("\t\t\t3: Go back to the main menu \n");
 scanf("%d",&m);
 switch(m)
 {
 case 1:head=modify(head);break;
 case 2:print(head);break;
 case 3:menu();break;
 default:printf("\t\t\tinput error!\n");
 mod(head);
 }
}
int find(struct student *head);
int find1(struct student *head) // Search by student id 
{
 struct student *p1;
 p1=(struct student *)malloc(sizeof(struct student));
 printf("\t\t\t Please enter the student number you are looking for \n");
 scanf("%d",&num2);
 p1=head;
 while(p1!=NULL)
 {
 if(p1->num==num2)
 {
  k=1;
  printf("\t\t\t Student id :%d\t The name :%s\t gender :%s\t age :%d\t note :%s\n\n",p1->num,p1->name,p1->sex,p1->age,p1->bz);
  break;
 }
 p1=p1->next;
 }
 if(k==0)
 {
 printf("\t\t\t The student information you are looking for is not found \n\n");
 }
 else
 {
 printf("\t\t\t This is the student information you are looking for \n\n");
 }
 find(head);
}
int find2(struct student *head) // Find by name 
{
 struct student *p1;
 p1=(struct student *)malloc(sizeof(struct student));
 printf("\t\t\t Please enter the name of the student you want to check \n");
 scanf("%s",name3);
 p1=head;
 while(p1!=NULL)
 {
 if((strcmp(p1->name,name3))==0)
 {
  k=1;
  printf("\t\t\t Student id :%d\t The name :%s\t gender :%s\t age :%d\t note :%s\n\n",p1->num,p1->name,p1->sex,p1->age,p1->bz);
  break;
 }
 p1=p1->next;
 }
 if(k==0)
 {
 printf("\t\t\t The student information was not found \n\n");
 }
 else
 {
 printf("\t\t\t This is the student information you are looking for \n\n");
 }
 find(head);
}
int find3(struct student *head) // Search by gender 
{ 
 struct student *p1;
 p1=(struct student *)malloc(sizeof(struct student));
 printf("\t\t\t Please enter the gender of the student you are looking for \n");
 scanf("%s",sex3);
 p1=head;
 while(p1!=NULL)
 {
 if((strcmp(p1->sex,sex3))==0)
 {
  k=1;
  printf("\t\t\t Student id :%d\t The name :%s\t gender :%s\t age :%d\t note :%s\n\n",p1->num,p1->name,p1->sex,p1->age,p1->bz);
  break;
 }
 p1=p1->next;
 }
 if(k==0)
 {
 printf("\t\t\t The student information was not found \n\n");
 }
 else
 {
 printf("\t\t\t This is the information for the student you are looking up \n\n");
 }
 find(head);
}
int find4(struct student *head) // Search by age 
{
 struct student *p1;
 p1=(struct student *)malloc(sizeof(struct student));
 printf("\t\t\t Please enter the age of the student you are looking for \n");
 scanf("%d",&age3);
 p1=head;
 while(p1!=NULL)
 {
 if(p1->age==age3)
 {
  k=1;
  printf("\t\t\t Student id :%d\t The name :%s\t gender :%s\t age :%d\t note :%s\n\n",p1->num,p1->name,p1->sex,p1->age,p1->bz);
  break;
 }
 p1=p1->next;
 }
 if(k==0)
 {
 printf("\t\t\t No information was found about the student \n\n");
 }
 else
 {
 printf("\t\t\t This is the information of the student you are looking for \n\n");
 }
 find(head);
}
int find(struct student *head)
{
 printf("\t\t\t Please choose how you want to query student information \n");
 printf("\t\t\t1: Query by student id \n");
 printf("\t\t\t2: Search by student name \n");
 printf("\t\t\t3: Search by student sex \n");
 printf("\t\t\t4: Search by student age \n");
 printf("\t\t\t5: Go back to the main menu \n");
 scanf("%d",&m);
 switch(m)
 {
 case 1:find1(head);break;
 case 2:find2(head);break;
 case 3:find3(head);break;
 case 4:find4(head);break;
 case 5:system("cls");menu();break;
 default:printf("\t\t\tinput error,please input again\n");
 }
}
int main() // The main function 
{
 struct student *phead;
 if(login()==0)
 {
 return 0;
 }
 
 printf("\n");
 while(1)
 {
 switch(menu())
 {
 case 1:system("cls");phead=creat();break;
 case 2:system("cls");print(phead);break;
 case 3:system("cls");save(phead);break;
 case 4:system("cls");phead=del(phead);break;
 case 5:system("cls");mod(phead);break;
 case 6:system("cls");find(phead);break;
 case 7:system("cls");printf("\t\t\t Welcome to use, bye! \n");return 0;
 default:printf("\t\t\t There is an error in the input. Please reenter it \n");
 }
 }
}

For more information, please pay attention to the topic management System Development.


Related articles: