实验室设备管理系统
题目要求
实验设备管理系统设计
实验设备信息包括:设备编号,设备种类(如:微机、打印机、扫描仪等等),设备名称,设备价格,设备购入日期,是否报废,报废日期等。
主要功能:
(1)能够完成对设备的录入和修改
(2)对设备进行分类统计
(3)设备的破损耗费和遗损处理
(4)设备的查询
要求:使用文件方式存储数据。
源代码
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<malloc.h>
#include<windows.h>
#include<conio.h>
/*定义存放仪器信息的结构体*/
typedef struct Information
{
char Name[20]; //仪器名称
char Sort[2]; //仪器种类
char ID[20]; //仪器编号
char Price[20]; //仪器价格
char Buydate[20]; //设备购买日期
char State[2]; //设备状态
char Donatedate[20]; //报废日期
struct Information* next;
} Information;
/*定义文件*/
FILE* fp;
/*读出文件信息*/
Information* Fscanf()
{
Information* head = (Information*)malloc(sizeof(Information));
head->next = NULL;
FILE* fp = fopen("Equipment.txt", "rt");
if (fp == NULL)
{
puts("文件打开失败");
exit(1); //程序异常退出
}
if (fscanf(fp, "%s %s %s %s %s %s %s", head->Name, head->Sort, head->ID, head->Buydate, head->Price, head->State, head->Donatedate) != EOF)
{
while (fgetc(fp) != EOF) //判断是否已经到文件尾部了
{
Information* cur = (Information*)malloc(sizeof(Information));
fscanf(fp, "%s %s %s %s %s %s %s", cur->Name, cur->Sort, cur->ID, cur->Buydate, cur->Price, cur->State, cur->Donatedate);
cur->next = head;
head = cur;
} //利用头插法将文件读入链表中
}
else
return NULL;
fclose(fp);
return head->next;
}
/*存入文件*/
void Fprintf(Information* head)
{
if ((fp = fopen("Equipment.txt", "w")) == NULL)
{
printf("\n\n文件打开失败!\n");
exit(1);
}
Information* cur = head;
while (cur)
{
fprintf(fp, "%s %s %s %s %s %s %s\n", cur->Name, cur->Sort, cur->ID, cur->Buydate, cur->Price, cur->State, cur->Donatedate);
cur = cur->next;
}
fclose(fp);
}
/*目录*/
Information* Addition(Information* head);//添加设备信息
Information* Query(Information* head);//查找设备信息
Information* Modify(Information* head);//修改仪器信息
Information* Delect(Information* head);//删除仪器信息
void Over();//结束系统
void Menu();//系统目录
/*添加设备信息*/
Information* Addition(Information* head)
{
int n, count = 0;
printf("\n请输入要添加的设备数量:"); //请输入要添加的设备数量
scanf("%d", &n);
system("cls"); //清屏操作
while (n--)
{
Information* cur