程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> C語言項目--教師信息/學生成績管理系統

C語言項目--教師信息/學生成績管理系統

編輯:關於C語言

\
\

   \

   \

   \

  下面貼出部分代碼:
  void add_tea(Teacher tea[]) 
{ 
int i=0,j,num; 
char str[5]; 
if(numtea!=0) 
{ 
  printf("cover the current record?(y/n)\n"); 
  gets(str); 
  if(str[0]=='Y'||str[0]=='y') 
   i=0; 
  else i=numtea; 
} 

printf("Please input the number of you add the teachers:"); 
scanf("%d",&num); 
if(i==0) 
  numtea=num; 
else numtea+=num; 
if(numtea>lens) 
{ 
  lens+=10; 
  tea=(Teacher *)realloc(tea,lens*SIZE); 
} 
printf("Please input the teacher's info:\n"); 
for(;i<numtea;i++) 
{ 
  getchar(); 
  printf("please input the teacher's NO.:"); 
  gets(tea.number); 
  printf("please input the teacher's name:"); 
  gets(tea.name); 
  printf("please input the teacher's sex(man/woman 0/1):"); 
  gets(tea.sex); 
  if(tea.sex[0]=='0') strcpy(tea.sex,"man"); 
  else strcpy(tea.sex,"woman"); 
  printf("please input the teacher's address:"); 
  gets(tea.addr); 
  printf("the teacher is married(No/Yes 0/1):"); 
  gets(tea.married); 
  if(tea.sex[0]=='0') strcpy(tea.sex,"No"); 
  else strcpy(tea.sex,"Yes"); 
} 
display_tea(tea,0,numtea-1); 
getchar(); 
}
void display_tea(Teacher tea[],int n1,int n2) 
{ 
int i;
char str[2];
if(numtea==0){
        printf("There is Nothing!\n");
     printf("Do you want to open some file to find the record?(Y/N)\n");
     gets(str);
     if (str[0]=='Y'||str[0]=='y')
     {
      openfileTXT(tea);
     }
     else
     {
      return;
     }
}
else
{
  for(i=n1;i<=n2;i++) 
   printf("number:%s\tname:%s\t\tsex:%s\t\taddr:%s\t\tmarried:%s\t",tea.number,tea.name,tea.sex,tea.addr,tea.married);
}
} 
void adjust(Teacher tea[]) 
{ 
char str[5]; 
int i=-1,j; 

if(numtea==0) 
{
  printf("there is nothing !!!\n"); 
  return;
}
while(i<0) 
{ 
  i=find_tea(tea); 
  if(i>=0) 
  { 
   printf("Delete it?(y/n)"); 
   gets(str); 
   if(str[0]=='y'||str[0]=='Y') 
   { 
    delete_tea(tea,i); 
    /*count(stud); */
   } 
   else 
   { 
    printf("Adjust it?(y/n)"); 
    gets(str); 
    if(str[0]=='y'||str[0]=='Y') 
    { 

     printf("Please input something you want:\n"); 
     printf("please input the teacher's NO.:"); 
     gets(tea.number); 
     printf("please input the teacher's name:"); 
     gets(tea.name); 
     printf("please input the teacher's sex(man/woman 0/1):"); 
     gets(tea.sex); 
     if(tea.sex[0]=='0') strcpy(tea.sex,"man"); 
     else strcpy(tea.sex,"woman"); 
     printf("please input the teacher's address:"); 
     gets(tea.addr); 
     printf("the teacher is married(No/Yes 0/1):"); 
     gets(tea.married); 
     if(tea.sex[0]=='0') strcpy(tea.sex,"No"); 
     else strcpy(tea.sex,"Yes"); 
    } 
    /*count(stud); */
   } 
   display_tea(tea,0,numtea-1); 
  } 
  printf("Again to Adjust it ?(y/n)\n"); 
  gets(str); 
  if(str[0]=='y'||str[0]=='Y') 
   i=-1; 
  else i=1; 
} 
} 

int find_tea(Teacher tea[]) 
{ 
char str[10]; 
int i; 
if(numtea==0) 
{ 
  printf("There is nothing\n"); 
  return -1; 
} 
else 
{ 
  printf("what do you want your fashion ?\n1.number\t2.name\t3.addr\n"); 
  gets(str); 
  if(str[0]=='1') 
  { 
   printf("please input the teacher's number:"); 
   gets(str); 
   for(i=0;i<=numtea;i++) 
    if(strcmp(str,tea.number)==0) 
    { 
     display_tea(tea,i,i); 
     break; 
    } 
    else continue; 
  } 
  else if(str[0]=='2') 
  { 
   printf("please input the teacher's name:"); 
   gets(str); 
   for(i=0;i<=numtea;i++) 
    if(strcmp(str,tea.name)==0) 
    { 
     display_tea(tea,i,i); 
     break; 
    } 
    else continue; 
  } 
  else if(str[0]=='3') 
  { 
   printf("please input the teacher's address:"); 
   gets(str);
   for(i=0;i<=numtea;i++) 
    if(strcmp(str,tea.addr)==0) 
    { 
     display_tea(tea,i,i); 
     break; 
    } 
    else continue; 
  } 
  if(i>numtea) 
  { 
   printf("Nothing has find\n"); 
   return -1; 
  } 
  return i; 
} 
} 

void delete_tea(Teacher tea[],int i) 
{ 
int j; 
while(i>=0) 
{ 
  for(j=i;j<numtea;j++) 
   tea[j]=tea[j+1]; 
  numtea--; 
  printf("Delete Success!\n"); 
} 
} 

int writetoTXT(Teacher tea[]) 
{ 
int i=0,j; 
FILE *fp; 
char filename[20]; 
printf("Please input the file's name:"); 
gets(filename); 
fp=fopen(filename,"w"); 
fprintf(fp,"%d\n",numtea); 
while(i<numtea) 
{ 
  fprintf(fp,"%s %s %s %s %s",tea.number,tea.name,tea.sex,tea.addr,tea.married); 
  i++; 
} 
fclose(fp); 
printf("Save success!!!\n"); 
display_tea(tea,0,numtea-1); 
numtea=0; 
return 0; 
} 

int openfileTXT(Teacher tea[]) 
{ 
int i=0,j; 
FILE *fp; 
char filename[20],str[2]; 
if(numtea!=0) 
{ 
  printf("There has some records,Do you want to save them?(y/n)"); 
  gets(str); 
  if(str[0]=='y'||str[0]=='Y') 
   writetoTXT(tea); 
} 
printf("Please input the file name:"); 
gets(filename); 
numtea=0; 
if((fp=fopen(filename,"rb+"))==NULL) 
{ 
  printf("Sorry ,can't open the file\n"); 
  return(-1); 
} 
fscanf(fp,"%d",&numtea); 
fgetc(fp); 
while(i<numtea) 
{ 
  fscanf(fp,"%s",&tea.number); 
  fscanf(fp,"%s",&tea.name); 
  fscanf(fp,"%s",&tea.sex); 
  fscanf(fp,"%s",&tea.addr); 
  fscanf(fp,"%s",&tea.married); 
  i++; 
} 
fclose(fp); 
printf("Read the file success\n"); 
printf("Display the record ?(y/n)"); 
gets(str); 
if(str[0]=='y'||str[0]=='Y') 
  display_tea(tea,0,numtea-1); 
return(0); 
} 

void displayTheSystemInfo() 
{ 
printf("\t\t制作人員: \n\n"); 
printf("http://www.shengshiyouxi.com"); 
printf("\n\n"); 
} 

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved