C++实现简单的信息管理系统

  • Post author:
  • Post category:其他


640?wx_fmt=gif

本文为大家分享C++实现简单的信息管理系统,小编之前在学习的时候也要做一些管理系统,在网上查了许多资料,现在我把资料分享给大家,希望能够帮助到大家。

640?wx_fmt=jpeg

#include <stdio.h>	
#include <stdlib.h>	
#include "file.h"	
  	
  	
  	
void savaList(Node *head)/**把用户录入的数据存储到文件里面去方便下次读取*/	
{	
 FILE *fp=fopen("data\\data.txt" ,"w") ;	
 Node *p ;	
 for(p=head->next;p;p=p->next)	
 {	
   fwrite(&(p->data),sizeof(students),1,fp) ;	
 }	
 fclose(fp) ;	
  	
}	
  	
  	
  	
void duquLisr(Node *head)/**读取用户之前所录入的数据 */	
{	
 FILE *fp=fopen("data\\data.txt" ,"r") ;	
 students e ;	
  while( fread(&e,sizeof(students) ,1,fp ) )	
  {	
   insertList(head,e) ;	
  }	
  fclose(fp) ;	
  	
}	
  	
  	
  	
  	
#include <stdio.h>	
#include <stdlib.h>	
#include <string.h>	
#include "goods.h"	
  	
/**录入数据,函数目的返回一个goods类型的值*/  /**      char name[M] ;	
                   char phone[M] ;	
                   char street[M] ;	
                   char city[M] ;	
                   char youb[M] ; */	
students lurushuju()	
{	
 students e ;	
  	
  	
 printf("请输入学生的姓名 ") ;	
 scanf("%s",e.name);	
  	
 printf("请输入学生的电话 ") ;	
 scanf("%s",e.phone) ;	
  	
 printf("请输入学生的街道 ") ;	
 scanf("%s",e.street) ;	
  	
 printf("请输入学生的城市信息 ") ;	
 scanf("%s",e.city) ;	
  	
 printf("请输入学生的邮编 ") ;	
 scanf("%s",e.youb) ;	
  	
  	
 return e ;	
  	
}	
void shuchushuju(students e)/**依次输出数据e*/	
{	
 printf("%15s%15s%15s%15s%15s\n" , e.name ,e.phone,e.street,e.city,e.youb) ;	
  	
}	
void xiugaishuju(students *e)/**根据地址修改数据e里面的个别数据*/ /**通过选择序号选择想要修改的数据*/	
{	
 int score ;	
 int count=1 ;	
 printf("请输入想要修改的数据类型\n") ;	
 do	
 {	
 printf("1.姓名;2.电话;3.街道信息;4.城市信息;5.邮编;6.退出\n");	
 scanf("%d",&score) ;	
 switch(score)	
 {	
 case 1:	
  scanf("%s",e->name);	
  break ;	
 case 2:	
  scanf("%s",e->phone) ;	
  break;	
 case 3:	
  scanf("%s",e->street) ;	
  break ;	
 case 4:	
  scanf("%s",e->city) ;	
  break ;	
 case 5:	
  scanf("%s",e->youb) ;	
  break ;	
 default:	
  count=0;	
 }	
 }while(count);	
  	
}	
  	
  	
  	
  	
#include <stdio.h>	
#include <string.h>	
#include "list.h"	
#include "goods.h"	
  	
void creatList(Node *head,int n)/**创建一个长度为n的链表*/	
{	
 int i ;	
 students p ;	
 for(i=1; i<=n ; i++)	
 {	
  p=lurushuju() ;	
  insertList(head,p) ;	
 }	
  	
}	
void insertList(Node *head,students e) /**把e中的某一个值以一定的顺序插入到以head为头节点的链表上面去*/	
{	
 Node *p;	
 Node *q;	
 q=(Node*)malloc(sizeof(Node));	
 q->data=e;	
 for(p=head; p->next && strcmp( (p->next)->data.name,e.name)<0 ;p=p->next ) ;	
 q->next=p->next;	
 p->next=q;	
}	
  	
int delList(Node *head,char e[])/**把链表姓名为e的一项删除,先找找到删除成功就返回1,否者返回0*/	
{	
 Node *p;	
 for(p=head; p->next && strcmp(e,p->next->data.name) ;p=p->next) ;	
 if(p->next ==0)	
 {	
  return 0 ;	
 }	
 else	
 {	
  Node *t;	
  t=p->next;	
  p->next=t->next;	
  free(t);	
  return 1 ;	
 }	
  	
}	
  	
  	
Node *searchList(Node *head,char e[])/**在链表中查找名字这一项找到返回这个节点的地址 否者返回null*/	
{	
 Node *p;	
 for(p=head; p && strcmp(e,p->data.name) ; p=p->next ) ;	
 return p ;	
}	
  	
  	
void disputList(Node *head)/**依次顺序输出head链表*/	
{	
 Node *p;	
 for(p=head->next;p;p=p->next)	
 shuchushuju(p->data);	
  	
  	
}	
  	
void changeList(Node *head ,char e[]) /**修改链表中某一个节点的data值*/ /**该系统只能通过姓名查找 后续在完善*/	
{	
 Node *p ;	
 p=searchList(head,e) ;	
 if(!p)	
 {	
  printf("error\n");	
 }	
 else	
 {	
  xiugaishuju(&(p->data)) ;	
  	
 }	
  	
}	
void destroy(Node *head)	
{	
 Node *p;	
 for(p=head;p;p=p->next)	
  free(p);	
}	
  	
  	
#include <stdio.h>	
#include <stdlib.h>	
#include <string.h>	
#include "list.h"	
#include "goods.h"	
  	
void mainmenu(Node *head)	
{	
 int scored ;	
 int count=1 ;	
 char e[100] ;	
 int n;	
 students p;	
 do	
 {	
 printf("================****学生信息管理系统(公测版by李远航)****=====\n") ;	
 printf("==========================开始===============================\n");	
 printf("==1.录入数据 2.修改数据 3.显示数据 4.删除数据 5.插入数据=\n") ;	
 printf("=======7.读取数据========6.存盘退出=======8.退出=============\n") ;	
 printf("=======================**********============================\n") ;	
  printf("请输入你想要做的事\n") ;	
  scanf("%d",&scored);	
 switch(scored)	
 {	
 case 1:	
  printf("请输入你大约想保存的学生\n");	
  scanf("%d",&n);	
  creatList(head,n);	
  break ;	
 case 2:	
  printf("请输入待改学生的姓名\n") ;	
  scanf("%s",e);	
  changeList(head , e) ;	
  break ;	
 case 3:	
  printf("   姓名   电话  街道信息   城市信息  邮件信息 \n") ;	
  disputList(head) ;	
  break ;	
 case 4:	
  printf("请输入待删学生的姓名\n");	
  scanf("%s",e);	
  n=delList(head, e) ;	
  if(n)	
  {	
   printf("删除成功\n");	
  }	
  else	
  {	
   printf("error\n") ;	
  }	
  break ;	
 case 5:	
  printf("请输入你想插入的信息\n");	
  p=lurushuju();	
  insertList(head, p);	
  break ;	
 case 6:	
  savaList(head);	
  count=0;	
  break ;	
 case 7:	
  duquLisr(head);	
  break ;	
 default :	
  count=0;	
 }	
 system("pause") ;	
 system("cls") ;	
  	
 }while(count);	
 printf("\n\n\n\n感谢您对本系统的支持,如果您在使用过程中遇到bug,请发送邮件到1277171561@qq.com\n\n\n\n\n\n\n") ;	
  	
  	
}	
  	
  	
  	
int main()	
{	
 Node *head=(Node*)malloc(sizeof(Node));	
 head->next=NULL ;	
 mainmenu(head) ;	
 destroy(head) ;	
 return 0;	
}	
  	
  	
#ifndef FILE_H_INCLUDED	
#define FILE_H_INCLUDED	
#include "list.h"	
  	
void savaList(Node *head);/**把用户录入的数据存储到文件里面去方便下次读取*/	
void duquLisr(Node *head);/**读取用户之前所录入的数据 */	
  	
  	
  	
#endif // FILE_H_INCLUDED	
  	
  	
  	
#ifndef GOODS_H_INCLUDED	
#define GOODS_H_INCLUDED	
  	
typedef struct students /*定义学生信息*/	
{	
 char name[100] ;	
 char phone[100] ;	
 char street[100] ;	
 char city[100] ;	
 char youb[100] ;	
  	
}students;	
  	
students lurushuju();/**录入数据,函数目的返回一个goods类型的值*/	
void shuchushuju(students e);/**依次输出数据e*/	
void xiugaishuju(students *e);/**根据地址修改数据e里面的个别数据*/	
  	
  	
  	
  	
  	
#endif // GOODS_H_INCLUDED	
  	
  	
  	
  	
#ifndef LIST_H_INCLUDED	
#define LIST_H_INCLUDED	
#include "goods.h"	
  	
typedef struct Node /**链表结构体*/	
{	
 students data ;	
 struct Node *next ;	
}Node ;	
  	
void creatList(Node *head,int n);/**创建一个长度为n的链表*/	
void insertList(Node *head,students e) ;/**把e中的某一个值以一定的顺序插入到以head为头节点的链表上面去*/	
int delList(Node *head,char e[]) ;/**把链表姓名为e的一项删除,先找找到删除成功就返回1,否者返回0*/	
Node *searchList(Node *head,char e[]) ; /**在链表中查找名字这一项*/	
void disputList(Node *head);/**依次顺序输出head链表*/	
void changeList(Node *head ,char e[]) ;/**修改链表中某一个节点的data值 */	
void destroy(Node *head) ;/**摧毁一起链表数据*/	
  	
  	
  	
  	
  	
#endif // LIST_H_INCLUDED

640?wx_fmt=png

640?wx_fmt=png

它,

不仅仅是一个码

扫码关注

C++资源免费送