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

2020-01-06 13:21:41王冬梅
  • {  cout << "Error opening file"<<endl;  
  • exit(0);  } 
  • while (!in.eof())  { 
  • Stu st;  in.read(reinterpret_cast<char *>(&st), sizeof(st)); 
  • if (in.fail())   { 
  • break;  } 
  • Student * pNew=new Student();  if(NULL==pNew) 
  • {  printf("分配失败,程序终止n"); 
  • exit(0);  } 
  • pNew->setst(st);  pTail->next=pNew; 
  • pNew->next=NULL;  pTail=pNew; 
  • }  in.close(); 
  • return pHead;  } 
  •    
  • void outFile()  { 
  • ofstream out;  out.open("c:kcsj.txt",ios_base::out|ios_base::app|ios::binary); 
  • if(!out)  { 
  • cout<<"文件不存在,退出时别忘记保存文件!"<<endl;  out.close(); 
  • out.open("stu.dat",ios_base::out|ios::binary);  } 
  • else  {  
  • out.close();  out.open("c:kcsj.txt",ios_base::out|ios_base::app|ios::binary); 
  • }  Student * temp=pHead->next; 
  • while(temp!=NULL)  { 
  • Stu st=temp->getst();  out.write(reinterpret_cast<char *>(&st), sizeof(st)); 
  • temp=temp->next;  }  
  • out.close();  } 
  •   Student * create_List() 
  • {  int len; 
  • Student * pHead=(Student *)malloc(sizeof(Student));  if(NULL==pHead) 
  • {  cout<<"分配失败,程序终止!"<<endl; 
  • exit(0);  } 
  • Student * pTail=pHead;  pTail->next=NULL; 
  • cout<<"请输入要存储的学生人数:";  cin>>len; 
  • for(int i=0;i<len;i++)  { 
  • Stu st;  cout<<"请输入第"<<i+1<<"个学生的学号:"; 
  • cin>>st.no;  cout<<"请输入第"<<i+1<<"个学生的姓名:";