C++实现简单的信息管理系统
本文为大家分享C++实现简单的信息管理系统,小编之前在学习的时候也要做一些管理系统,在网上查了许多资料,现在我把资料分享给大家,希望能够帮助到大家。
#include<stdio.h>
#include<stdlib.h>
#include"file.h"
voidsavaList(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);
}
voidduquLisr(Node*head)/**读取用户之前所录入的数据*/
{
FILE*fp=fopen("data\\data.txt","r");
studentse;
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类型的值*//**charname[M];
charphone[M];
charstreet[M];
charcity[M];
charyoub[M];*/
studentslurushuju()
{
studentse;
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);
returne;
}
voidshuchushuju(studentse)/**依次输出数据e*/
{
printf("%15s%15s%15s%15s%15s\n",e.name,e.phone,e.street,e.city,e.youb);
}
voidxiugaishuju(students*e)/**根据地址修改数据e里面的个别数据*//**通过选择序号选择想要修改的数据*/
{
intscore;
intcount=1;
printf("请输入想要修改的数据类型\n");
do
{
printf("1.姓名;2.电话;3.街道信息;4.城市信息;5.邮编;6.退出\n");
scanf("%d",&score);
switch(score)
{
case1:
scanf("%s",e->name);
break;
case2:
scanf("%s",e->phone);
break;
case3:
scanf("%s",e->street);
break;
case4:
scanf("%s",e->city);
break;
case5:
scanf("%s",e->youb);
break;
default:
count=0;
}
}while(count);
}
#include<stdio.h>
#include<string.h>
#include"list.h"
#include"goods.h"
voidcreatList(Node*head,intn)/**创建一个长度为n的链表*/
{
inti;
studentsp;
for(i=1;i<=n;i++)
{
p=lurushuju();
insertList(head,p);
}
}
voidinsertList(Node*head,studentse)/**把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;
}
intdelList(Node*head,chare[])/**把链表姓名为e的一项删除,先找找到删除成功就返回1,否者返回0*/
{
Node*p;
for(p=head;p->next&&strcmp(e,p->next->data.name);p=p->next);
if(p->next==0)
{
return0;
}
else
{
Node*t;
t=p->next;
p->next=t->next;
free(t);
return1;
}
}
Node*searchList(Node*head,chare[])/**在链表中查找名字这一项找到返回这个节点的地址否者返回null*/
{
Node*p;
for(p=head;p&&strcmp(e,p->data.name);p=p->next);
returnp;
}
voiddisputList(Node*head)/**依次顺序输出head链表*/
{
Node*p;
for(p=head->next;p;p=p->next)
shuchushuju(p->data);
}
voidchangeList(Node*head,chare[])/**修改链表中某一个节点的data值*//**该系统只能通过姓名查找后续在完善*/
{
Node*p;
p=searchList(head,e);
if(!p)
{
printf("error\n");
}
else
{
xiugaishuju(&(p->data));
}
}
voiddestroy(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"
voidmainmenu(Node*head)
{
intscored;
intcount=1;
chare[100];
intn;
studentsp;
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)
{
case1:
printf("请输入你大约想保存的学生\n");
scanf("%d",&n);
creatList(head,n);
break;
case2:
printf("请输入待改学生的姓名\n");
scanf("%s",e);
changeList(head,e);
break;
case3:
printf("姓名电话街道信息城市信息邮件信息\n");
disputList(head);
break;
case4:
printf("请输入待删学生的姓名\n");
scanf("%s",e);
n=delList(head,e);
if(n)
{
printf("删除成功\n");
}
else
{
printf("error\n");
}
break;
case5:
printf("请输入你想插入的信息\n");
p=lurushuju();
insertList(head,p);
break;
case6:
savaList(head);
count=0;
break;
case7:
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");
}
intmain()
{
Node*head=(Node*)malloc(sizeof(Node));
head->next=NULL;
mainmenu(head);
destroy(head);
return0;
}
#ifndefFILE_H_INCLUDED
#defineFILE_H_INCLUDED
#include"list.h"
voidsavaList(Node*head);/**把用户录入的数据存储到文件里面去方便下次读取*/
voidduquLisr(Node*head);/**读取用户之前所录入的数据*/
#endif//FILE_H_INCLUDED
#ifndefGOODS_H_INCLUDED
#defineGOODS_H_INCLUDED
typedefstructstudents/*定义学生信息*/
{
charname[100];
charphone[100];
charstreet[100];
charcity[100];
charyoub[100];
}students;
studentslurushuju();/**录入数据,函数目的返回一个goods类型的值*/
voidshuchushuju(studentse);/**依次输出数据e*/
voidxiugaishuju(students*e);/**根据地址修改数据e里面的个别数据*/
#endif//GOODS_H_INCLUDED
#ifndefLIST_H_INCLUDED
#defineLIST_H_INCLUDED
#include"goods.h"
typedefstructNode/**链表结构体*/
{
studentsdata;
structNode*next;
}Node;
voidcreatList(Node*head,intn);/**创建一个长度为n的链表*/
voidinsertList(Node*head,studentse);/**把e中的某一个值以一定的顺序插入到以head为头节点的链表上面去*/
intdelList(Node*head,chare[]);/**把链表姓名为e的一项删除,先找找到删除成功就返回1,否者返回0*/
Node*searchList(Node*head,chare[]);/**在链表中查找名字这一项*/
voiddisputList(Node*head);/**依次顺序输出head链表*/
voidchangeList(Node*head,chare[]);/**修改链表中某一个节点的data值*/
voiddestroy(Node*head);/**摧毁一起链表数据*/
#endif//LIST_H_INCLUDED
以上就是C++信息管理系统的关键代码,供大家参考,下面再为大家分享一些其他管理系统:
C++实现简单的图书管理系统
C++实现简单的职工信息管理系统
C++基础学生管理系统
更多学习资料请关注专题《管理系统开发》。
以上就是本文的全部内容,希望对大家的学习有所帮助。