学生管理系统

/***************************************************
学生管理系统
***************************************************/

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

#define YES   1
#define NO   0
#define DEBUG NO  //是否进行调试

int save_y_n  =  0;

typedef   struct stu_data_t
{
 char  name[20] ;
 int    num  ;
 char  sex    ;
 float   english   ;
 float   math   ;
 float   all_score  ;
 int     rank   ;
}stu_data_t;

typedef struct stu_node_t
{
 stu_data_t stu_data;
 struct  stu_node_t *next_stu_node;
}stu_node_t  ;

typedef struct stu_link_t
{
 stu_node_t *head_node;
 stu_node_t  *tail_node;
 int stu_number;
}stu_link_t   ;

/*

函数名  :init_link

功能  :初始化链表

参数  :
   输入参数  :          
       stu_link_t  *p_stu_link     :链表
   输出参数  :
       无
 
返回值  :
   0 :成功
   -1 :失败
   
其他  :
   无
   
*/
int  init_link(stu_link_t  *p_stu_link);

/*

函数名  :add_stu_node

功能  :将一个学生的信息添加到指点的结点

参数  :
   输入参数  :          
       stu_link_t *p_stu_link     :链表
       int pos         :要插入结点的位置
       stu_data_t *p_stu_data    :要加入的学生信息的指针
       
   输出参数  :
       无
 
返回值  :
   0 :成功
   -1 :失败
   
其他  :
   无
   
*/
int add_stu_node(stu_link_t * ,int pos ,stu_data_t *p_stu_data );

/*

函数名  :enter_add_stu_end_node

功能  :输入学生的信息,并将键盘输入的学生信息加入到链表结点(加入到了末尾)

参数  :
   输入参数  :          
       stu_link_t *p_stu_link     :链表
       
   输出参数  :
       无
 
返回值  :
   0 :成功
   -1 :失败
   
其他  :
   无
   
*/
int enter_add_stu_end_node(stu_link_t  *p_stu_link);

/*

函数名  :student_number

功能  :得出栈中学生的个数

参数  :
   输入参数  :          
       stu_link_t *p_stu_link     :链表
       
   输出参数  :
       无
 
返回值  :
   int
   学生的个数
   
其他  :
   无
   
*/
int student_number(stu_link_t  *p_stu_link);

/*

函数名  :write_stu_info_to_file

功能  :将栈中的学生信息写入文件

参数  :
   输入参数  :          
       stu_link_t *p_stu_link     :链表
       char *fm        :要写入的文件名
       
   输出参数  :
       无
 
返回值  :
   0 :成功
   -1 :失败
   
其他  :
   无
   
*/
int write_stu_info_to_file( stu_link_t  *p_stu_link ,char *fm);

/*

函数名  :read_stu_from_file_to_node

功能  :从文件中读取学生信息

参数  :
   输入参数  :          
       stu_link_t *p_stu_link     :链表
       char *fm        :文件名
       
   输出参数  :
       无
 
返回值  :
   0 :成功
   -1 :失败
   
其他  :
   无
   
*/
int read_stu_from_file_to_node(stu_link_t  *p_stu_link,char *fm);

/*

函数名  :clear_link

功能  :清链表

参数  :
   输入参数  :          
       stu_link_t *p_stu_link     :链表
       
   输出参数  :
       无
 
返回值  :
   0 :成功
   -1 :失败
   
其他  :
   无
   
*/
int clear_link(stu_link_t  *p_stu_link);//清除学生链表

/*

函数名  :delete_stu_node

功能  :删除链表结点()

参数  :
   输入参数  :          
       stu_link_t *p_stu_link     :链表
       int pos         :删除第几个结点
       
   输出参数  :
       无
 
返回值  :
   0 :成功
   -1 :失败
   
其他  :
   无
   
*/
int delete_stu_node(  stu_link_t  *p_stu_link, int pos  );

/*

函数名  :show_menu

功能  :显示功能菜单

参数  :
   输入参数  :          
       无
       
   输出参数  :
       无
 
返回值  :
   0 :成功
   -1 :失败
   
其他  :
   无
   
*/
int show_menu();

/*

函数名  :show_all_stu_info

功能  :显示学生的全部信息

参数  :
   输入参数  :          
       stu_link_t  *p_stu_link      :链表
       
   输出参数  :
       无
 
返回值  :
   0 :成功
   -1 :失败
   
其他  :
   无
   
*/
int show_all_stu_info(stu_link_t  *p_stu_link);

/*

函数名  :delete_stu_by_name

功能  :根据学生姓名删除结点

参数  :
   输入参数  :          
       stu_link_t  *p_stu_link      :链表
       
   输出参数  :
       无
 
返回值  :
   0 :成功
   -1 :失败
   
其他  :
   无
   
*/
int delete_stu_by_name(stu_link_t  *p_stu_link);

/*

函数名  :find_stu_info_by_name

功能  :根据学生姓名找到学生结点

参数  :
   输入参数  :          
       stu_link_t  *p_stu_link      :链表
       
   输出参数  :
       无
 
返回值  :
   0 :成功
   -1 :失败
   
其他  :
   无
   
*/
int find_stu_info_by_name(stu_link_t  *p_stu_link);

/*

函数名  :order

功能  :根据学生总分对学生进行排序

参数  :
   输入参数  :          
       stu_link_t  *p_stu_link      :链表
       
   输出参数  :
       无
 
返回值  :
   0 :成功
   -1 :失败
   
其他  :
   无
   
*/
int order(stu_link_t  *p_stu_link);

/*

函数名  :main_add_stu

功能  :菜单当中对添加学生信息的实现

参数  :
   输入参数  :          
       stu_link_t  *p_stu_link      :链表
       
   输出参数  :
       无
 
返回值  :
   0 :成功
   -1 :失败
   
其他  :
   在此函数中调用了int enter_add_stu_end_node(stu_link_t  *p_stu_link);
   对功能菜单功能的进一步改进
   
*/
int main_add_stu(stu_link_t  *p_stu_link);

/*

函数名  :main_exit_sys

功能  :菜单当中对添加学生信息的实现

参数  :
   输入参数  :          
       stu_link_t  *p_stu_link      :链表
       char *fm         :文件名
         在对学生信息改变后,可对学生信息进行保存,调用了
         保存学生信息的函数(int write_stu_info_to_file( stu_link_t \
         *p_stu_link ,char *fm);),所以要把文件名传递给形参。
       
       
   输出参数  :
       无
 
返回值  :
   0 :成功
   -1 :失败
   
其他  :
   对功能菜单功能的进一步改进
   
*/
int main_exit_sys(stu_link_t  *p_stu_link,  char *fm);

/*********************************************************************************************************************main*/
int main(int argc, char *argv[])
{
 //int fun_num = 0;
 
 char  *save_file ="student/student_info.dat";
 
 stu_link_t  stu_link ;
 init_link(&stu_link);
 
 while(1)
 {
  //show_menu();
  //printf("请选择功能序号\t");
  scanf("%d",&fun_num);
  getchar();
  
  while( (fun_num >= 9)||(fun_num <= 0))
  {
   scanf("%d",&fun_num);
   getchar();
  }
  
  switch(fun_num)
  {
   case 1:
     main_add_stu(&stu_link);
     break;
   case 2:
     save_y_n =  0  ;//标志学生数据是否改变
     show_all_stu_info(&stu_link);
     printf("学生成绩显示成功 -------------!\n");
     break;   
   case 3:
     save_y_n =  0  ;//标志学生数据是否改变
     order(&stu_link);
     printf("排序完成---------------------------\n");
     break;
   case 4:
     save_y_n =  0  ;//标志学生数据是否改变
     find_stu_info_by_name(&stu_link);
     break;
   case 5:
     save_y_n  =   0  ;//标志学生数据是否改变
     delete_stu_by_name(&stu_link);
     break;
   case 6:
     save_y_n =  0  ;//标志学生数据是否改变
     read_stu_from_file_to_node(&stu_link,save_file);
     printf("从文件中加载信息完成------------!\n");
     break;   
   case 7:
     save_y_n =  1  ;//标志学生数据是否改变
     write_stu_info_to_file( &stu_link,save_file);
     printf("保存信息成功完成------------------!\n");
     break;
   case 8:
     main_exit_sys(&stu_link,save_file);
     return 0;
     break;
  };
 printf("内存中的学生数:%d\n",stu_link.stu_number); 
 }
/*
 测试用代码
 read_stu_from_file_to_node(&stu_link,save_file );
 printf("学生数:%d\n",stu_link.stu_number);
 clear_link(&stu_link);
 printf("学生数:%d\n",stu_link.stu_number);
 printf("head_node:%d\n",stu_link.head_node);
 printf("tail_node:%d\n",stu_link.tail_node); */


 /*printf("the name of a student  is : %s\n",stu_link.head_node->stu_data.name);
 printf("the num of a student  is : %d\n",stu_link.head_node->stu_data.num);
 printf("the name of a student  is : %s\n",stu_link.head_node->next_stu_node->stu_data.name);
 printf("the num of a student  is : %d\n",stu_link.head_node->next_stu_node->stu_data.num);*/
/* enter_add_stu_end_node(&stu_link);
 printf("学生数为    :%d\n",student_number( &stu_link )  ); 
 printf("the name of a student  is : %s\n",stu_link.head_node->stu_data.name);
 printf("the num of a student  is : %d\n",stu_link.head_node->stu_data.num);
 
 enter_add_stu_end_node(&stu_link);
 printf("学生数为    :%d\n",student_number( &stu_link )  ); 
 printf("the name of a student  is : %s\n",stu_link.head_node->stu_data.name);
 printf("the num of a student  is : %d\n",stu_link.head_node->stu_data.num);
 write_stu_info_to_file( &stu_link ,save_file );
 delete_stu_node(&stu_link, 1 );
 printf("学生数为    :%d\n",student_number( &stu_link) ); 
 printf("the name of a student  is : %s\n",stu_link.head_node->stu_data.name);
 printf("the num of a student  is : %d\n",stu_link.head_node->stu_data.num);*/
 return 0;
}
/******************************************************************************************************************init_link***/
int  init_link(stu_link_t  *p_stu_link)
{
#if  DEBUG
 if(NULL == p_stu_link)
 {
  printf("warning (init_link):------------------------------无链表\n");
  return  -1;
 } 
#endif
 p_stu_link->head_node   = NULL ;
 p_stu_link->tail_node     = NULL ;
 p_stu_link->stu_number  = 0  ;
 
 return 0;
}

/********************************************************************************************************enter_stu_info***/
int enter_stu_info( stu_data_t *p_stu_data  )
{

#if  DEBUG//DEBUG开始

if(p_stu_data == NULL)
{
 printf("warning (enter_stu_info)   :传递的指针为空:\n");
}
#endif//DEBUG结束

 memset((unsigned char *)p_stu_data, 0 , sizeof(stu_data_t));
 
 printf("--------------------请输入学生的信息--------------------\n");
 printf("请键入学生姓名    :\n");
 scanf("%s",p_stu_data->name);
 
 printf("请键入学生学号    :\n");
 scanf("%d",&p_stu_data->num);
 
 getchar();
 printf("请键入学生性别    (男 :M   女 :F )\n");
 scanf("%c",&p_stu_data->sex);
 
 printf("请键入英语成绩    :\n");
 scanf("%f",&p_stu_data->english);
 getchar();
 
 printf("请键入数学成绩    :\n");
 scanf("%f",&p_stu_data->math);
 getchar();
 
 p_stu_data->all_score   = p_stu_data->english  +  p_stu_data->math;
 
 p_stu_data->rank  = 0 ;
 
 printf("已成功键入学生信息\n");
 
 return 0;
}

/********************************************************************************************************add_stu_node***/
int add_stu_node(stu_link_t *p_stu_link,   int pos,   stu_data_t *p_stu_data )
{
 int i = 0;
 stu_node_t  *lpv_stu_node;
 stu_node_t  *lpv_stu_node_temp;
#if  DEBUG
 if(NULL == p_stu_link)
 {
  printf("warning :------------------------------无链表\n");
  return  -1;
 }
 
 if(NULL == p_stu_data)
 {
  printf("warning :------------------------------无学生信息\n");
  return  -1;
 }
 if( ( pos >=  p_stu_link->stu_number + 2)||(pos <= 0))
 {
  printf("warning :------------------------------要插入的结点数无效\n");
  printf("please check  the argument ""pos"" of the function (add_stu_node)!\n");
  return  -1;
 }
 
#endif
 lpv_stu_node = (stu_node_t *)malloc(   sizeof(stu_node_t)  );
 
 memset((unsigned char *)(&(lpv_stu_node->stu_data)),0,sizeof(stu_data_t));
 memcpy((unsigned char *)&lpv_stu_node->stu_data, p_stu_data, sizeof(stu_data_t));
 
 if(1  ==  pos)
 {
   lpv_stu_node->next_stu_node = NULL;
   p_stu_link->head_node   =  lpv_stu_node ;  
   p_stu_link->tail_node    =  lpv_stu_node ; 
   p_stu_link->stu_number++;
 }
 else if( pos == p_stu_link->stu_number + 1)
 {
   lpv_stu_node->next_stu_node = NULL;
   p_stu_link->tail_node->next_stu_node  =  lpv_stu_node ;
   p_stu_link->tail_node   =  lpv_stu_node;
   p_stu_link->stu_number++;
 }
 else
 {
   //找到要插入位置的前一个结点  
   lpv_stu_node_temp =  p_stu_link->head_node;
   for(i = 1; i < pos - 1; i++)
   {
    lpv_stu_node_temp = lpv_stu_node_temp->next_stu_node;
   }//找到第  i - 1 个节点后退出循环
   lpv_stu_node->next_stu_node = lpv_stu_node_temp->next_stu_node;
   lpv_stu_node_temp->next_stu_node   =lpv_stu_node;
   p_stu_link->stu_number++;   
 }
 
 return 0;
}
/*********************************************************************************************enter_add_stu_end_node****/
int enter_add_stu_end_node(stu_link_t  *p_stu_link)
{
#if  DEBUG
 if(NULL == p_stu_link)
 {
  printf("warning (enter_add_stu_end_node):------------------------------无链表\n");
  return  -1;
 } 
#endif
 stu_data_t  stu_data_temp;
 stu_data_t  *p_stu_data_temp = &stu_data_temp;
 enter_stu_info( p_stu_data_temp );
 
 add_stu_node(p_stu_link,   p_stu_link->stu_number + 1,   p_stu_data_temp );
}

/********************************************************************************************************student_number***/
int student_number(stu_link_t  *p_stu_link)
{
#if  DEBUG
 if(NULL == p_stu_link)
 {
  printf("warning (student_number):------------------------------无链表\n");
  return  -1;
 } 
#endif
 return  p_stu_link->stu_number;
 
}
/********************************************************************************************************delete_stu_node***/
int delete_stu_node(stu_link_t  *p_stu_link, int pos )
{

 int i = 0;
 stu_node_t *stu_node_temp = NULL;
 stu_node_t *free_stu_node_temp = NULL;

#if  DEBUG
 if(NULL == p_stu_link)
 {
  printf("warning (delete_stu_node):------------------------------无链表\n");
  return  -1;
 }
 
 if( ( pos >=  p_stu_link->stu_number + 1)||(pos <= 0))
 {
  printf("warning (delete_stu_node):------------------------------要删除插入的结点数无效\n");
  printf("please check  the argument ""pos"" of the function (add_stu_node)!\n");
  return  -1;
 }
 if(p_stu_link->head_node == NULL)
 {
  printf("warning  (delete_stu_node):----------------------------链表已经为空删除结点无效\n");
  return -1;
 }
#endif
 if(1 == pos)
 {
   free_stu_node_temp =  p_stu_link->head_node;
   p_stu_link->head_node  =  p_stu_link->head_node->next_stu_node;
   if(p_stu_link->head_node == NULL)//只有一个数据项则应改变位指针
   {
    p_stu_link->tail_node = NULL;
   }
   free(free_stu_node_temp);
   p_stu_link->stu_number--;
 }
 else
 {
  stu_node_temp =  p_stu_link->head_node ;
  for(i = 1; i < pos - 1; i++)//寻找第pos - 1个节点
  {
   stu_node_temp = stu_node_temp->next_stu_node ;
  }//到pos - 1个结点停止循环
  if(  p_stu_link->stu_number == pos)//若为末尾的数据项执行此操作
  {
    p_stu_link->tail_node = stu_node_temp;
  }
  
  free_stu_node_temp = stu_node_temp->next_stu_node ;
  stu_node_temp->next_stu_node  =   free_stu_node_temp->next_stu_node;
  free(free_stu_node_temp);
  
  p_stu_link->stu_number--;
 }
 return 0;
}
/**************************************************************************************************write_stu_info_to_file***/
int write_stu_info_to_file( stu_link_t  *p_stu_link ,char *fm)
{

 int i = 0;
 int write_many_block;//写了多少块
 int  fclose_y_n;
 stu_data_t  *stu_data_tmp;
 stu_node_t  *stu_node_tmp;
 
 FILE  *fp = NULL;
#if DEBUG
 if(NULL == p_stu_link)
 {
  printf("warning (write_stu_info_to_file):------------------------------无链表\n");
  return  -1;
 }
 
 if(NULL == fm)
 {
  printf("warning (write_stu_info_to_file):------------------------------无文件\n");
  return  -1;
 }

#endif

 fp  = fopen(fm, "wb") ;
#if DEBUG
 if( fp == NULL )
 {
  printf("\n----------------------warning--------------------"); 
  printf("\nwarning(write_stu_info_to_file): 不能打开文件    !");
  return -1  ;
 }
 else
 {
  printf("\n已经打开文件\n");
 }
#endif
 stu_node_tmp =  p_stu_link->head_node;
 for( i = 1; i <= p_stu_link->stu_number; i++)
 {
  stu_data_tmp = &stu_node_tmp->stu_data;
  write_many_block = fwrite(stu_data_tmp, sizeof(stu_data_t), 1 , fp);
  
#if  DEBUG
  if(write_many_block <= 0)
  {
   printf("\n----------------------warning--------------------"); 
   printf("\nwarning(write_stu_info_to_file): 不能向文件写入数据 !");
   return -1  ;
  }
  else
  {
   printf("向文件写入成功");
   printf("\n向文件写入%d块\n",write_many_block );
  }
#endif

  stu_node_tmp = stu_node_tmp->next_stu_node;
 }

 fclose_y_n = fclose(fp) ;
 #if  DEBUG
  if(fclose_y_n == 0)
  {
   printf("成功关闭文件\n");
  }
  else
  {
   printf("----------------------warning--------------------\n"); 
   printf("warning (write_stu_info_to_file): 不能关闭文件 !\n");
   return -1  ;
  }
#endif
}

/*******************************************************************************************read_stu_from_file_to_node***/
int read_stu_from_file_to_node(stu_link_t  *p_stu_link,char *fm)
{
 int i = 0;
 int read_many_block = 0;
 int  fclose_y_n = 0;
 
 stu_data_t  stu_data_tmp;
 stu_data_t  *p_stu_data_tmp = &stu_data_tmp;
 
#if DEBUG
 if(NULL == p_stu_link)
 {
  printf("warning (read_stu_from_file_to_node):------------------------------无链表\n");
  return  -1;
 }
 
 if(NULL == fm)
 {
  printf("warning (read_stu_from_file_to_node):------------------------------无文件\n");
  return  -1;
 }

#endif
 clear_link(p_stu_link);//清除链表
 FILE  *fp = NULL;
#if  DEBUG
 if(NULL == p_stu_link)
 {
  printf("warning(read_stu_from_file_to_node) :------------------------------无链表\n");
  return  -1;
 } 
 if(NULL == fm)
 {
  printf("warning (read_stu_from_file_to_node):----------------------------无文件名\n");
  return  -1;
 } 
#endif 

 fp  = fopen(fm, "rb") ;
#if DEBUG
 if( fp == NULL )
 {
  printf("----------------------warning--------------------\n"); 
  printf("warning (read_stu_from_file_to_node): 不能打开文件    !\n");
  return -1  ;
 }
 else
 {
  printf("已经打开文件\n");
 }
#endif

//从文件中读取数据
 
 read_many_block = fread(p_stu_data_tmp, sizeof(stu_data_t), 1, fp);
 
 while(read_many_block == 1)
 {
 printf("从文件读出成功\n");
 printf("从文件读出%d块\n",read_many_block );
 //将stu_node加入到链表的末尾
 add_stu_node(p_stu_link ,p_stu_link->stu_number+1 ,p_stu_data_tmp );
 printf("the name of  a student :%s",p_stu_data_tmp->name);
 read_many_block = fread(p_stu_data_tmp, sizeof(stu_data_t), 1, fp);
 }
 printf("文件中数据读完!\n");

 
//关闭文件
 fclose_y_n = fclose(fp) ;
 #if  DEBUG
  if(fclose_y_n == 0)
  {
   printf("成功关闭文件\n");
  }
  else
  {
   printf("----------------------warning--------------------\n"); 
   printf("warning (read_stu_from_file_to_node): 不能关闭文件 !\n");
   return -1  ;
  }
#endif
 return 0;
}

/***************************************************************************************************************clear_link***/
int clear_link(stu_link_t  *p_stu_link)//清除学生链表

 stu_node_t  *p_stu_node_tmp = NULL;
 
 while(NULL != p_stu_link->head_node)
 {
 #if DEBUG
  printf("the name of a student:%s\n",p_stu_link->head_node->stu_data.name);
 #endif
  delete_stu_node(  p_stu_link, 1);
 }
  
 return 0;
}
/*************************************************************************************************************show_menu***/
int show_menu()
{
 printf("**************************英贝得培训项目**************************\n");
 printf("                         学生分数管理系       \n");
 printf("*********************************************************************\n");
 printf("请根据每行所描述功能选择序号: \n");
 printf("1 输入学生信息                     \n");
 printf("2   显示学生分数                     \n");
 printf("3 根据总分对排序                   \n");
 printf("4   寻找某一学生的信息    \n");
 printf("5   删除某一学生信息                 \n");
 printf("6 加载学生信息                      \n");
 printf("7 保存学生信息                      \n");
 printf("8 软件退出                           \n");
 
}
/******************************************************************************************************show_all_stu_info***/
int show_all_stu_info(stu_link_t  *p_stu_link)
{
#if  DEBUG
 if(NULL == p_stu_link)
 {
  printf("warning(show_all_stu_info) :------------------------------无链表\n");
  return  -1;
 } 

#endif 

 stu_node_t  *p_stu_node_tmp = p_stu_link->head_node;
 stu_data_t  *p_stu_data_tmp = &(p_stu_node_tmp->stu_data);
 printf("姓名 学号 性别 英语成绩   数学成绩  总成绩 排名\n");
 
 while(NULL != p_stu_node_tmp)
 {
  
  printf("%s %-8.2d %c %-8.2f   %-8.2f  %-8.2f   %d\n"
  ,  p_stu_data_tmp->name,       p_stu_data_tmp->num \
  ,  p_stu_data_tmp->sex,        p_stu_data_tmp->english,  p_stu_data_tmp->math  \
  ,  p_stu_data_tmp->all_score,  p_stu_data_tmp->rank);  
        
  p_stu_node_tmp = p_stu_node_tmp->next_stu_node;
  p_stu_data_tmp = &(p_stu_node_tmp->stu_data);
 }
 
 return 0;
}

/**************************************************************************************************delete_stu_by_name***/
int delete_stu_by_name(stu_link_t  *p_stu_link)
{
#if  DEBUG
 if(NULL == p_stu_link)
 {
  printf("warning(delete_stu_by_name) :------------------------------无链表\n");
  return  -1;
 } 

#endif 
 int i;
 stu_node_t  *p_stu_node_tmp = NULL;
 stu_data_t  *p_stu_data_tmp  = NULL;
 
 char delete_stu_name[20];
 char delet_stu_y_n = 0;
 
 
 printf("要删除学生信息吗?(Y  : 是  N  : 否) :");
 
while(1)
{
 scanf("%c",&delet_stu_y_n);
 getchar();
 if(delet_stu_y_n=='N')
 {
  return 0;
 }
 else if(delet_stu_y_n=='Y')
 {
   while(1)
  {
   printf("请输入要删除的学生的姓名:");
   scanf("%s",delete_stu_name);
   p_stu_node_tmp = p_stu_link->head_node;
   p_stu_data_tmp = &(p_stu_node_tmp->stu_data);
   for(i = 1; i <= p_stu_link->stu_number; i++)
   {
    if(strcmp(delete_stu_name,p_stu_data_tmp->name) == 0) 
    break; 
    p_stu_node_tmp = p_stu_node_tmp->next_stu_node;
    p_stu_data_tmp = &(p_stu_node_tmp->stu_data);
   }
   if(i > p_stu_link->stu_number)
   {
    printf("warning(delete_stu_by_name):输入的学生姓名不存在-------------------------\n");

   }
   else
   {
    delete_stu_node( p_stu_link, i );
    printf("成功删除信息\n");
    return 0;
   } 
  }
 }
 else
 {
  printf("warning(delete_stu_by_name):------------------------------------输入无效\n");
  printf("请再次输入信息\n");
  printf("要删除学生信息吗?(Y  : 是  N  : 否) :");
 }
}

 return 0;
}

/************************************************************************************************find_stu_info_by_name***/
int find_stu_info_by_name(stu_link_t  *p_stu_link)
{
 int i;
 stu_node_t  *p_stu_node_tmp = NULL;
 stu_data_t  *p_stu_data_tmp  = NULL;
 
 char find_stu_name[20];
 char find_stu_y_n = 0;
 
 
 printf("要寻找学生信息吗?(Y  : 是  N  : 否) :");
 
while(1)

 scanf("%c",&find_stu_y_n);
 getchar();
 if(find_stu_y_n == 'N' )
 {
  return 0; 
 }
 else if(find_stu_y_n == 'Y' )
 while(1)
 {
  printf("请输入要寻找的学生的姓名:");
  scanf("%s",find_stu_name);
  p_stu_node_tmp = p_stu_link->head_node;
  p_stu_data_tmp = &(p_stu_node_tmp->stu_data);///备注::::::
  for(i = 1; i <= p_stu_link->stu_number; i++)
  {
   if(strcmp(find_stu_name,p_stu_data_tmp->name) == 0) 
   break; 
   p_stu_node_tmp = p_stu_node_tmp->next_stu_node;
   p_stu_data_tmp = &(p_stu_node_tmp->stu_data);///备注::::::
  }
  if(i > p_stu_link->stu_number)
  {
   printf("warning(find_stu_info_by_name):输入的学生姓名不存在-------------------------\n");
   printf("请在次输入:\n");
  }
  else
  {
   printf("姓名 学号 性别 英语成绩   数学成绩  总成绩 排名\n");
   printf("%s %-8.2d %c %-8.2f   %-8.2f  %-8.2f   %d\n"
   ,  p_stu_data_tmp->name,       p_stu_data_tmp->num \
   ,  p_stu_data_tmp->sex,        p_stu_data_tmp->english,  p_stu_data_tmp->math  \
   ,  p_stu_data_tmp->all_score,  p_stu_data_tmp->rank); 
   printf("已找到指定的学生\n");
   return 0;
  }
 }
 else
 {
  printf("warning(find_stu_info_by_name):------------------------------------输入无效\n");
  printf("请再次输入信息\n");
  printf("要删除学生信息吗?(Y  : 是  N  : 否) :");
 }
}
 return 0;
}
/******************************************************************************************************************order****/
int order(stu_link_t  *p_stu_link)
{
 int i  = 0;
 int j  = 0;
 stu_data_t  p_stu_data_tmp;
 stu_node_t *p_pre_stu_node_tmp  =  NULL;
 stu_node_t *p_cur_stu_node_tmp  =  NULL;
 p_pre_stu_node_tmp  = p_stu_link->head_node;
 for( i = 1; i <= p_stu_link->stu_number; i++)
 {
  
  p_cur_stu_node_tmp = p_pre_stu_node_tmp->next_stu_node;
  
  for(j = i + 1; j <= p_stu_link->stu_number; j++ )
  {
   
   if(p_pre_stu_node_tmp->stu_data.all_score < p_cur_stu_node_tmp->stu_data.all_score )
   {
    memcpy(&p_stu_data_tmp,  &p_cur_stu_node_tmp->stu_data,  sizeof(stu_data_t));
    memcpy(&p_cur_stu_node_tmp->stu_data           \
    ,  &p_pre_stu_node_tmp->stu_data,  sizeof(stu_data_t)  );
    memcpy(&p_pre_stu_node_tmp->stu_data, &p_stu_data_tmp,  sizeof(stu_data_t));
   }
   p_cur_stu_node_tmp = p_cur_stu_node_tmp->next_stu_node;
  }
  p_pre_stu_node_tmp->stu_data.rank = i ;
  p_pre_stu_node_tmp = p_pre_stu_node_tmp->next_stu_node; 
 }
}

/****************************************************************************************************main_add_stuorder****/
int main_add_stu(stu_link_t  *p_stu_link)
{
char enter_stu_info_y_n = 0;
while(1)
    {
     printf("是否要继续输入学生信息(Y  : 是  N  : 否) :\n");
     scanf("%c",&enter_stu_info_y_n);
     getchar();
     while((enter_stu_info_y_n != 'Y')&&(enter_stu_info_y_n != 'N'))
     {
      printf("warning(find_stu_info_by_name):键入的字符不符合要求,请重新输入----------!\n");
      printf("是否要继续输入学生信息(Y  : 是  N  : 否) :------------\n");
      scanf("%c",&enter_stu_info_y_n);
      getchar();
     }
     if(enter_stu_info_y_n == 'Y')
     {
      save_y_n =  0  ;//标志学生数据是否改变
      enter_add_stu_end_node(p_stu_link); 
      printf("输入学生成绩成功-------------!\n");   
     }
     else
     {
      printf("停止输入学生成绩-------------!\n");
      break;
     }
    }
}

/********************************************************************************************************main_exit_sys****/
int main_exit_sys(stu_link_t  *p_stu_link,  char *fm)
{
char exit_sys_y_n = 0;
while(1)
 {
 printf("真的要退出系统吗?(Y  : 是  N  : 否) :\n");
 scanf("%c",&exit_sys_y_n);
 getchar();
 switch(exit_sys_y_n)
  {
  case 'Y' :
        if(save_y_n ==  0 )
          {
    printf("warning(main_exit_sys):学生数据还没有保存,是否要保存数据! (Y  : 是  N  : 否) :\n");
          while(1)
           {
            scanf("%c",&exit_sys_y_n);
            getchar();
            if(exit_sys_y_n == 'Y')
            {
             write_stu_info_to_file( p_stu_link,fm);
             printf("保存信息成功完成------------------!\n");
             printf("--------------------退出系统--------------------\n");
             return  0;
            }
            else if(exit_sys_y_n == 'N')
            {
             return  0;
            }
            printf("输入错误请重新输入  :\n");
           }
          }
          printf("--------------------退出系统--------------------\n");
          return  0;
          break;
       case 'N' :
          printf("--------------------不退出系统--------------------\n");
          break;  
       default :
          printf("输入错误请重新输入  :\n");
          break; 
      };
      if(exit_sys_y_n == 'N')
      break;
 }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值