⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class.cpp

📁 学籍管理小程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:

if(flag==0)
 { printf("	Num:%s didn't exist in the list.\n\n",ms);
   printf("	Press any key to go back!");
   getch();
   return;
 }
else
 { textprint("Old record:");
   printf("Num            |Name        |Sex|Birthday   |Ad          |Room    |Tel   \n") ;
   print(pm);
   textprint("Select a modify mode:");
   printf("    1.Delete         2.Modify one part   3.exit \n");

   s1=getch();
   while(!check_c(s1,"123dmeDME"))
    s1=getch();

   if(s1=='1')             /*In case of wrong operation*/
    { printf("\nDo you want to delete the record of %s(Y/N,y/n)",ms);
      s2=getch();
      if(s2!='y' && s2!='Y') return;
    }

  switch(s1)
   { case 'd':case 'D':
     case '1':  if(pm->next==NULL)
		 { pm->pre->next=NULL;
		   free(pm);
		 }
		else
		 { pm->pre->next=pm->next;
		   pm->next->pre=pm->pre;
		   free(pm);
		 }
		Record_len--;
		/*When a record is deleted ,the counter "Record_len" minus 1*/

		printf("\nRecord of num:%s has been deleted!\n",ms);
		printf("Press any key to continue!\n");
		getch();
		break;
    case 'm':case 'M':
    case '2':   modify_a_record(pm);
		textprint("New record:");
		print(pm);
		break;
    case 'e':case 'E':
    case '3': return;
   default:;
  }
 }
 printf("	Press any key to go back!");getch();
 }



void searchnum(struct stu*PS)              /*search num*/
 {
 char t[NUMLEN+1];
 int len=NUMLEN,i=0;
 struct stu *ps;
 ps=PS->next;

 textprint("Search num");
 printf("\tInput num(%d):",len);
 strcpy(t,inputnum(NUMLEN));
 while(ps!=NULL)
  { if(strcmp(ps->num,t)==0)
      {print(ps);
       i=1;
       break;
     }
    ps=ps->next;
  }
 if(i==0)
  printf("\n\tNum:%s doesn't exist in the list.",t);
}


 void searchtel(struct stu *PS)        /*search tel*/
 {
 char tel[TELLEN+1];
 struct stu *ptel;
 int n=0,tellen=TELLEN;
 ptel=PS->next;

 textprint("Search tel");
 printf("\tInput search tel(%d):",tellen);
 strcpy(tel,inputnum(TELLEN));
 while(ptel!=NULL)
  {
   if(!strcmp(ptel->tel,tel))
    { print(ptel);
      n++;
     }
   ptel=ptel->next;
  }
 printf("	 %d people use this tel.\n",n);
  }


 void searchdorm(struct stu *PS)           /*search dorm*/
 {
 char dorm[DORMLEN+1];
 struct stu *pr;
 int n=0,dormlen=DORMLEN;

 textprint("Search dorm");
 printf("   Input search dorm number(%d):",dormlen);
 strcpy(dorm,inputnum(DORMLEN));
 pr=PS->next;
 while(pr!=NULL)
  {if(!strcmp(pr->dorm,dorm))
   {
     print(pr);
     n++;
   }
   pr=pr->next;
  }
 printf("	There are %d numbers in DORM[%s].\n",n,dorm);
  }



 void searchname(struct stu *PS)          /*search name*/
 {
 int i,flag=0;
 char name[NAMELEN+1];
 struct stu *pn;
 pn=PS->next;

 textprint("Search name");
 printf(" Input search name(10):");
 strcpy(name,inputchar(NAMELEN));
 while(pn!=NULL)
  { if(!strcmp(pn->name,name))
     { print(pn);
       flag=1;
     }
     pn=pn->next;
  }
 if(flag==0)
  printf("\n%s didn't exist in the list!\n",name);
 }



 void searchad(struct stu *PS)         /*search address*/
 {
 int n=0,adlen=ADLEN;
 char ad[ADLEN+1];
 struct stu *pa;
 pa=PS->next;

 textprint("Search ad.");
 printf(" Input search ad.(%d):",adlen);
 strcpy(ad,inputchar(ADLEN));

 while(pa!=NULL)
  { if(!strcmp(pa->ad,ad))          /*if find the according records*/
     { print(pa);
       n++;
     }
    pa=pa->next;
  }
 printf("\n\n	There are %d numbers living in %s\n",n,ad);
 }


 void searchbirthday(struct stu *PB)
 {
 char c;
 struct stu *pb=PB->next;
 int n=0;
 int year=0,month=0,day=0;

 textprint("Search birthday:");
 printf("\t1. Search yy/mm/dd(1984 12 19):\n");
 printf("\t2. Search yy/mm   (1984 12   ):\n");
 printf("\t3. Search yy      (1984      ):\n");
 printf("\t4. Search mm      (     12   ):\n");
 printf("\t4. Exit\n\n");

 printf("Input your choice:\n");

 c=getch();
 while(c<'1'||c>'5') c=getch();

 switch(c)
  { case '1':printf("\tInput search yy/mm/dd:");
	     scanf("%d%d%d",&year,&month,&day);
	     getchar();
	     while(pb!=NULL)
	      { if( check(pb,year,1) && check(pb,month,2) &&check(pb,day,3))
		 { print(pb);
		   n++;
		 }
	      pb=pb->next;
	      }
	     break;
    case '2':printf("\tInput search yy/mm:");
	     scanf("%d%d",&year,&month);
	     getchar();
	     while(pb!=NULL)
	      { if( check(pb,year,1) && check(pb,month,2))
		 { print(pb);
		   n++;
		 }
		pb=pb->next;
	      }
	     break;
    case '3':printf("\tInput search yy:");
	     scanf("%d",&year);
	     getchar();
	     while(pb!=NULL)
	      { if( check(pb,year,1))
		 { print(pb);
		   n++;
		 }
		pb=pb->next;
	      }
	      break;
    case '4':printf("\tInput search month:");
	     scanf("%d",&month);
	     getchar();
	      while(pb!=NULL)
	       { if(check(pb,month,2))
		  { print(pb);
		    n++;
		  }
		 pb=pb->next;
	       }
	     break;
    case '5':return;
    default:;
  }
 printf("\n\tTotal: %3d students.",n);
 }


 int check(struct stu *pd,int test,int i)
 {
 switch(i)
  { case 1:if(pd->birthday.year==test) return (1);
	     else return (0);
    case 2:if(pd->birthday.month==test) return (1);
	       else return (0);
    case 3:if(pd->birthday.day==test) return (1);
	       else return (0);
    default:;
  }

 }


/*The inputnum fuction is set to correct num inputting,when the characters \
  in the string is not numbers or the length don't  match  the "len" this\
  fuction goes on exept right inputting!                                */
char *inputnum(int len)
 {
 int i;
 static char *a;
 gets(a);
 if(strlen(a)>len)
  { printf("	Your num input is too long!\nnum(%d):",len);
    strcpy(a,inputnum(len));
  }
 else if(strlen(a)<len)
  { printf("	Your num input is too short!\nnum(%d):",len);
    strcpy(a,inputnum(len));
  }

 for(i=0;i<len;i++)
  {
  if(a[i]<'0' ||a[i]>'9')
   { printf("	Your num input must be all numbers!\nnum(%d):",len);
     strcpy(a,inputnum(len));break;
   }
  }
 return (a);
 }


char *inputchar(int len)
{
static char *b;
gets(b);
while(strlen(b)>len)
 { printf("	Your string input is beyond  %d\nPlease input again:",len);
   gets(b);
 }
return (b);
}


void textprint(char *s)
{
char a[80];
int i,j,len;
len= strlen(s);
for (i=0;i<80;i++)
 a[i]='*';
for(i=(80-len)/2,j=0;j<len;i++,j++)
 a[i]=s[j];
for(i=0;i<80;i++)
 putch(a[i]);
}



void help(void)
{
FILE *P;
char ch;
clrscr();
gotoxy(1,1);
textprint("Help");
if((P=fopen("help.txt","r"))==NULL)
 { printf("Can not find help.txt");
   printf("\nPress any key to continue!");getch();
 }
else
 { ch=fgetc(P);
   while(!feof(P))
   {
   if(!(ch>'a'&&ch<'z'||ch>'A'&&ch<'Z')&&wherex()>73)
    printf("\n");
   if(wherey()>23)
    { printf("\tPress any key to view next page.");
      getch();
      clrscr();
      textprint("Help");
      printf("\n");
     }
   putchar(ch);
   ch=fgetc(P);
   }
 }
fclose(P);
printf("\n\tPress any key to go back!");getch();
}



void modify_a_record(struct stu *P)
{
char s,sex;

textprint("Modify one part");
printf("1.Name    2.Sex    3.Birthday  4.Address 5.Dorm   6.Telphone  7.Exit\n");
printf("\tInput your choice:\n");

s=getch();
while(!check_c(s,"1234567nsbadteNSBADTE")) s=getch();

switch(s)
 { case 'n':case 'N':
   case '1':printf("New name:",P->name);
	    strcpy(P->name,inputchar(NAMELEN));
	    return;
   case 's':case 'S':
   case '2':printf("New sex: ",P->sex);
	     sex=getch();
	    while(sex!='m' &&sex!='M'&&sex!='F'&&sex!='f')
	     sex=getch();
	    if(sex=='m'||sex=='M')
	      P->sex='M';
	    else P->sex='F';
	      putchar(P->sex);printf("\n");
	    return;
   case 'b':case 'B':
   case '3':printf("New birthday:",P->birthday);
	    scanf("%d%d%d",&P->birthday.year,&P->birthday.month,&P->birthday.day);
	    while(P->birthday.year>2003||P->birthday.month>12||P->birthday.day>31)
	     { printf("Input error!(The maximum of birthday is 2003 12 31)!\n");
	       printf("birthday:(2003 12 31)");
	       scanf("%d%d%d",&P->birthday.year,&P->birthday.month,&P->birthday.day);
	      }
	    getchar();
	    return;
   case 'a':case 'A':
   case '4':printf("New address:");
	    strcpy(P->ad,inputchar(ADLEN));
	    return;
   case 'd':case 'D':
   case '5':printf("New dorm:");
	    strcpy(P->dorm,inputchar(DORMLEN));
	    return;
   case 't':case 'T':
   case '6':printf("New telphone:");
	    strcpy(P->tel,inputchar(TELLEN));
	    return;
   case 'e':case 'E':
   case '7':return;
   default:;
 }
 }


void window_set(void)
{
char a;
static int i=1,c=1;
static int m,n;
m=TCOLOR;
n=TBCOLOR;

clrscr();
gotoxy(1,1);
textprint("Window");
printf("        Screen background  color\n");
printf("\tStatic text  color\n");
printf("\tStatic text background color\n");
printf("\tUse the original color\n");
printf("Input your choice:(Press Enter to confirm and exit)\n");
do
{
gotoxy(7,c+1);
printf("*");

a=getch();
if(a=='\0')
{ a=getch();
  switch(a)
  { case 'K':
	    switch(i)
	    {case 1:;break;
	     case 2:m--;
		    if(m<0)
		    m=15;
		    break;
	     case 3:
		   n--;
		   if(n<0)
		   n=15;
		   break;
	     case 4:
		   textattr(TCOLOR+(TBCOLOR<<4));
		   break;
	     case 5:;break;
	     case 6:;break;
	    }
	    break;
   case 'M':
	   switch(i)
	   {case 1:;break;
	    case 2:m++;
		   if(m>15)
		   m=0;
		   break;
	    case 3:n++;
		   if(n>15)
		   n=0;
		   break;
	    case 4:textattr(TCOLOR+(TBCOLOR<<4));
		   break;
	    case 5:;break;
	    case 6:;break;
	   }
	   break;
   case 'H': i--;
	     if(i==0) i=4;
	     break;
   case 'P': i++;
	     if(i==5) i=1;
	     break;
   default:;
  }
 }
if(i!=c)
 { gotoxy(7,c+1);
   printf(" ");
 }
c=i;
gotoxy(40,5);
textattr(m+(n<<4));
cprintf("Tc:%2dTbkc:%2d",m,n);
}while(a!=13);
gotoxy(5,8);
printf("\nPress any key to go back!");
getch();
}

int check_c(char a,char *p)          /*Used to inspect a char data's existence */
{
int i,flag=0;
for(i=0;i<strlen(p);i++)
 if(p[i]==a) flag=1;
return (flag);
}






⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -