C++实现简单的学生管理系统

2020-01-06 13:21:41王冬梅
  • cin>>st.name;  cout<<"请输入第"<<i+1<<"个学生的数学成绩:"; 
  • cin>>st.math;  cout<<"请输入第"<<i+1<<"个学生的语文成绩:"; 
  • cin>>st.chi;  Student * pNew=new Student(); 
  • if(NULL==pNew)  { 
  • printf("分配失败,程序终止n");  exit(0); 
  • }  pNew->setst(st); 
  • pTail->next=pNew;  pNew->next=NULL; 
  • pTail=pNew;  } 
  • return pHead;  } 
  •   void traverse_List(Student * pHead) 
  • {  int i=1; 
  • Student * temp=pHead->next;  while(temp!=NULL) 
  • {  cout<<endl<<"序号:"<<i<<endl; 
  • temp->show();  temp=temp->next; 
  • i++;  } 
  • }    
  • bool is_empty(Student * pHead)  { 
  • if(NULL==pHead->next)  { 
  • return true;  } 
  • else  { 
  • return false;  } 
  • }   
  • int length_List(Student * pHead)  { 
  • int len=0;  Student * temp=pHead->next; 
  • while(temp)  { 
  • len++;  temp=temp->next; 
  • }  return len; 
  • }   
  • bool insert_List(Student * pHead,int position,Stu st)  { 
  • int i=0;  Student * p=pHead; 
  •   while(NULL!=p&&i<position-1) 
  • {  p=p->next; 
  • i++;  } 
  • if(i>position-i||NULL==p)  { 
  • return false;  } 
  • Student * pNew=(Student *)malloc(sizeof(Student));  if(NULL==pNew) 
  • {  cout<<"分配失败,程序终止"<<endl; 
  • exit(0);  } 
  • pNew->setst(st);  pNew->next=p->next; 
  • p->next=pNew;  return true;